This repository has been archived by the owner on Sep 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathVagrantfile
238 lines (179 loc) · 5.91 KB
/
Vagrantfile
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'optparse'
require 'pp'
require 'ipaddr'
require './boxes'
require './actions'
require './types'
ours = []
while ARGV.include? '--'
ours << ARGV.pop
end
ours -= ['--']
ours.reverse!
puts "Command-line options are " + ours.to_s
options= {
:type => nil,
:list => nil,
:installer => :core,
:install_version => nil,
:provider => "virtualbox",
:setup => [],
:dctest => [],
:ec2_options => {},
:box => 'ubuntu-13.04',
:count => 1,
:ip => "10.1.1.12",
:bootstrap_ip => nil,
:dcurl => 'https://github.com/cfengine/design-center.git',
:dcbranch => 'master',
:vmname => 'cftester',
:vmsize => "1024",
:fport => "80",
:baseport => "8080",
}
OptionParser.new do |op|
op.banner = <<EOHIPPUS
Syntax: vagrant [vagrant options] -- OPTIONS
Note that options can be abbreviated.
Example: use the single_centos_hub type:
vagrant up -- --type single_centos_hub
Example: use the single_ubuntu_ec2 type:
vagrant up -- --type single_ubuntu_ec2
Example: list all the available types
vagrant ssh -- --list
Example: install on Ubuntu 13.04 from a CFEngine Core master checkout and bootstrap against A.B.C.D
vagrant up -- --bootstrap_ip A.B.C.D bootstrap
Example: install on Ubuntu 13.04 from the CFEngine APT repo and install Design Center in /var/tmp/dc
vagrant up -- -ipackages dc
EOHIPPUS
op.on("--type=[TYPE]",
"Instance type to control") do |v|
options = options.merge(Types.type(v))
end
op.on("--list",
"List instance types") do |v|
pp Types.types
exit
end
op.on("--dcurl=[URL]",
"Design Center URL to check out with Git") do |v|
options[:dcurl] = v
end
op.on("--vmname=[VMNAME]",
"VM Base name") do |v|
options[:vmname] = v
end
op.on("--vmsize=[VMSIZE]",
"VM memory size") do |v|
options[:vmsize] = v
end
op.on("--baseport=[BASEPORT]",
"Base forwarding port") do |v|
options[:baseport] = v
end
op.on("--fport=[FPORT]",
"Forwarded port") do |v|
options[:baseport] = v
end
op.on("--dcbranch=[BRANCH]",
"Design Center branch to check out with Git") do |v|
options[:dcbranch] = v
end
op.on("-i[INSTALLER]", "--installer=[INSTALLER]",
[:none, :core, :packages],
"Installation method for CFEngine (none, core, packages)") do |v|
options[:installer] = v
end
op.on("--install_version=[VERSION]",
"Installation version for CFEngine, where applicable") do |v|
options[:install_version] = v
end
op.on("--setup bootstrap,dc",
Array,
"Setup steps: (bootstrap, dc, etc.). Only bootstrap and dc have special treatment.") do |v|
options[:setup] = v
end
op.on("--dctest x,y,z",
Array,
"Test sketches: (Sketch1, Sketch2, etc.)") do |v|
options[:dctest] = v
end
op.on("-b[BOX]", "--box=[BOX]",
"Box to use (precise32, lucid32, ubuntu-VERSION, etc.)") do |v|
options[:box] = v
end
op.on("-I[IP]", "--ip=[IP]",
"Starting IP to assign to the hosts") do |v|
ip = IPAddr.new(v)
abort unless ip
options[:ip] = v
end
op.on("-b[IP]", "--bootstrap=[IP]",
"Bootstrap IP. Skipped by default. With count > 1, if not specified, uses the first element of the --ip range") do |v|
options[:bootstrap_ip] = v
end
op.on("-c[COUNT]", "--count=[COUNT]",
"Count of boxes to bring up") do |v|
options[:count] = v.to_i
if options[:count] > 254
abort "We can't handle count over 254, sorry"
end
end
end.parse!(ours)
# any leftover things are setup steps
options[:setup] += ours
puts "Parsed options from the command line + defaults:"
pp options
unless options[:bootstrap_ip]
options[:bootstrap_ip] = options[:ip]
end
box = Boxes.find(options[:box])
unless box
abort "Sorry, the box spec #{options[:box]} did not match a single box we can use. Bye."
end
puts "Found and using box [#{box}]"
options[:vmname].gsub!("BOX", options[:box] )
options[:vmname].gsub!(/[^-A-Za-z0-9]/, "-" )
box_type = Boxes.type(box)
unless box_type
abort "Sorry, the box #{options[:box]} did not have a valid type. Bye."
end
puts "Found and using box type [#{box_type}]"
puts "Requested instance count [#{options[:count]}]"
puts "Requested instance IP or IP prefix [#{options[:ip]}]"
puts "Requested bootstrap IP [#{options[:bootstrap_ip]}]"
actions = Actions.assemble(Boxes.type(box), options[:installer], options[:install_version], options[:setup], options[:dctest])
printable_version = options[:install_version] || 'latest'
unless actions
abort "Sorry, the box #{options[:box]} with type #{box_type} and setup steps #{options[:installer]} (version #{printable_version}), #{options[:setup].join(' ')}, #{options[:dctest].join(' ')} did not give us valid steps to follow. Bye."
end
puts "From setup steps #{options[:installer]} (version #{printable_version}), setup #{options[:setup].join(' ')}, dctest #{options[:dctest].join(' ')}, steps to follow: " + actions.to_s
puts "CFEngine test environment ready!"
puts "Engaging Vagrant's attention..."
Vagrant.configure("2") do |config|
config.vm.box = File.basename(box)
config.vm.box_url = box
config.vm.provider options[:provider] do |v|
v.customize ["modifyvm", :id, "--memory", 1024]
end
#### Define VMs ####
options[:count].times do |i|
iprint = i.to_s.rjust(3, '0')
config.vm.define "#{options[:vmname]}#{iprint}" do |vm_config|
# Host config
vm_config.vm.hostname = "#{options[:vmname]}#{iprint}"
ip = options[:ip]
# shaddap, it works
i.times { |c| ip = ip.succ() }
vm_config.vm.network :private_network, ip: ip
vm_config.vm.network :forwarded_port, guest: options[:fport], host: options[:baseport].to_i+i
options[:i] = i
actions.each do |a|
args = Actions.process_args(a[:args], options)
vm_config.vm.provision :shell, :path => "resources/shell_provisioners/#{a[:path]}", :args => args
end
end
end
end