This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRakefile
92 lines (77 loc) · 2.32 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'rake'
require 'net/ssh'
require 'net/scp'
USER = PASSWORD = 'vagrant'
HOSTS = {
'gold' => '172.16.0.2',
}
DISTROS = {
'microkernel' => {
:type => :mk,
:url => 'https://github.com/downloads/puppetlabs/Razor/rz_mk_dev-image.0.9.0.4.iso',
},
'ubuntu' => {
:release => 'ubuntu_precise',
:version => '12.04',
:url => 'http://releases.ubuntu.com/precise/ubuntu-12.04-server-amd64.iso',
},
'scientific' => {
:release => 'scientific',
:version => '6.2',
:url => 'http://ftp.scientificlinux.org/linux/scientific/6.2/x86_64/iso/SL-62-x86_64-2012-02-06-Install-DVD.iso',
},
'centos' => {
:release => 'centos',
:version => '6.2',
:url => 'http://mirror.metrocast.net/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-minimal.iso',
},
}
def ssh(host, user = USER, password = PASSWORD)
(@ssh_connections ||= {})[host.to_s] ||= net_ssh(HOSTS[host.to_s], user, password)
end
def net_ssh(address, user, password)
Net::SSH.start(address, user, :password => password)
end
def scp(host, local_path, remote_path, user = USER, password = PASSWORD)
ssh(host, user, password).scp.upload!(local_path, remote_path)
end
def razor(*a)
puts ssh(:gold).exec!(['sudo /opt/razor/bin/razor', *a].join(' '))
end
def download(url, options = {})
file_name = options[:as] || File.basename(url)
folder = options[:to] || "."
file_path = folder + "/" + file_name
command = "curl -L #{url} -o #{file_path}"
if File.exists?(file_path)
puts "File #{file_path} already exists. skipping download!"
else
system(command) or raise "Download command failed: #{command}"
end
end
desc "Start here. Provision & configure the Razor server."
task :start do
sh('librarian-puppet install')
sh('vagrant up')
end
DISTROS.each do |name, options|
namespace name do
url = options[:url]
file_name = File.basename(url)
remote_file_name = "/tmp/#{file_name}"
file file_name do
download(url)
end
task :upload => file_name do
scp(:gold, file_name, remote_file_name)
end
task :setup => :upload do
if options[:type] == :mk
razor('image', 'add', 'mk', remote_file_name)
else
razor('image', 'add', 'os', remote_file_name, options[:release], options[:version])
end
end
end
task name => "#{name}:setup"
end