inprovise-vbox 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/inprovise/vbox/vbox.rb +135 -44
- data/lib/inprovise/vbox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTc2NzIyNTlkODRmYjBjNzJiYjYyOTA2MTczYWM1ZmMxYzM0YzI0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTJmZmQ1YTY3ZWVhZDE5NDliNTVhYzlmNWZkNTIxMGFkMDA3ZTcwNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjFkMWM1ZmM3NDE4YTU4N2ExZWRiYjM5YjNjOTc4OWI2Yzc4NWJmNzgxYmE1
|
10
|
+
NjFmYjdmZmJiMjc3ZjFmZjMwNjE0MWFmNDZlODZmMGVhNTI3YzZlZmEyZTJm
|
11
|
+
OTM1ZjdlZDQ2NTA3NTQ2N2I0OTE0Y2Q3MGRiYzBmODc3ZDU3MWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDcyN2VkMmI2N2I1NzI5ZjhhNzM2OWNmYzBhZWFhZWMxOGQzMTVhYTVlMGRk
|
14
|
+
ZWZmMzE3MTI3NDk1ZTI1Njc5ZDFkY2JjNjBmMGQ0ZmE1MmIwNjVlNDdkNGFm
|
15
|
+
NGNjM2EyYzI4ZGVkYmQ1NzA1NDA4Njc3YzM5MGE4MTlmZTUwZjY=
|
data/lib/inprovise/vbox/vbox.rb
CHANGED
@@ -67,71 +67,71 @@ module Inprovise::VBox
|
|
67
67
|
# generate name if none set
|
68
68
|
configuration[:name] ||= "#{name}_#{self.hash}_#{Time.now.to_f}"
|
69
69
|
|
70
|
-
|
71
|
-
vbox_scrname = self.name
|
70
|
+
vbs = self
|
72
71
|
# define the scripts that do the actual work as dependencies
|
73
72
|
# 1. install the virtual machine
|
74
73
|
@vm_script = Inprovise::DSL.script "#{name}#vbox_vm" do
|
75
74
|
|
76
75
|
# verify VM
|
77
76
|
validate do
|
78
|
-
|
77
|
+
vmname = vbs.vbox_name(self)
|
79
78
|
# look for existing target with VM name on :apply unless node creation is suppressed
|
80
|
-
if command == :apply && !
|
81
|
-
if tgt = Inprovise::Infrastructure.find(
|
79
|
+
if command == :apply && !vbs.vbox_no_node(self)
|
80
|
+
if tgt = Inprovise::Infrastructure.find(vmname)
|
82
81
|
type = Inprovise::Infrastructure::Group === tgt ? 'group' : 'node'
|
83
|
-
raise ArgumentError, "VBox #{
|
82
|
+
raise ArgumentError, "VBox #{vmname} clashes with existing #{type}"
|
84
83
|
end
|
85
84
|
end
|
86
|
-
trigger 'vbox:vbox-verify',
|
85
|
+
trigger 'vbox:vbox-verify', vmname, (command == :apply && vbs.vbox_autostart(self))
|
87
86
|
end
|
88
87
|
|
89
88
|
# apply : installation
|
90
89
|
apply do
|
91
|
-
|
90
|
+
vmname = vbs.vbox_name(self)
|
91
|
+
vmimg = vbs.vbox_image(self)
|
92
92
|
# 1. verify config
|
93
|
-
raise ArgumentError, "Cannot access VBox image #{
|
93
|
+
raise ArgumentError, "Cannot access VBox image #{vmimg}" unless remote(vmimg).file?
|
94
94
|
# 2. execute virt-install
|
95
|
-
log("Installing VBox #{
|
95
|
+
log("Installing VBox #{vmname}".bold)
|
96
96
|
cmdline = 'virt-install --connect qemu:///system --hvm --virt-type kvm --import --wait 0 '
|
97
|
-
cmdline << '--autostart ' if
|
98
|
-
cmdline << "--name #{
|
99
|
-
cmdline << "--os-variant #{
|
100
|
-
cmdline << case
|
97
|
+
cmdline << '--autostart ' if vbs.vbox_autostart(self)
|
98
|
+
cmdline << "--name #{vmname} --memory #{vbs.vbox_memory(self)} --vcpus #{vbs.vbox_cpus(self)} "
|
99
|
+
cmdline << "--os-variant #{vbs.vbox_os(self)} " if vbs.vbox_os(self)
|
100
|
+
cmdline << case vbs.vbox_network(self)
|
101
101
|
when :hostnet
|
102
|
-
"--network network=#{
|
102
|
+
"--network network=#{vbs.vbox_netname(self) || 'default'} "
|
103
103
|
when :bridge
|
104
|
-
"--network bridge=#{
|
104
|
+
"--network bridge=#{vbs.vbox_netname(self) || 'virbr0' } "
|
105
105
|
end
|
106
106
|
cmdline << '--graphics spice '
|
107
|
-
cmdline << "--disk path=#{
|
108
|
-
cmdline << ",bus=#{
|
109
|
-
cmdline << ",format=#{
|
107
|
+
cmdline << "--disk path=#{vbs.vbox_image(self)},device=disk,boot_order=1"
|
108
|
+
cmdline << ",bus=#{vbs.vbox_diskbus(self)}" if vbs.vbox_diskbus(self)
|
109
|
+
cmdline << ",format=#{vbs.vbox_format(self)}" if vbs.vbox_format(self)
|
110
110
|
cmdline << ' --disk device=cdrom,boot_order=2,bus=ide'
|
111
|
-
cmdline << " #{
|
111
|
+
cmdline << " #{vbs.vbox_install_opts(self)}" if vbs.vbox_install_opts(self)
|
112
112
|
sudo(cmdline)
|
113
113
|
10.times do
|
114
114
|
sleep(1)
|
115
|
-
break if trigger 'vbox:vbox-verify',
|
115
|
+
break if trigger 'vbox:vbox-verify', vmname, vbs.vbox_autostart(self)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
# revert : uninstall
|
120
120
|
revert do
|
121
|
-
|
122
|
-
trigger 'vbox:vbox-shutdown',
|
123
|
-
log.print("Waiting for shutdown of VBox #{
|
121
|
+
vmname = vbs.vbox_name(self)
|
122
|
+
trigger 'vbox:vbox-shutdown', vmname
|
123
|
+
log.print("Waiting for shutdown of VBox #{vmname}. Please wait ...|".bold)
|
124
124
|
30.times do |n|
|
125
125
|
sleep(1)
|
126
126
|
log.print("\b" + %w{| / - \\}[(n+1) % 4].bold)
|
127
|
-
break unless trigger 'vbox:vbox-verify',
|
127
|
+
break unless trigger 'vbox:vbox-verify', vmname
|
128
128
|
end
|
129
|
-
if trigger('vbox:vbox-verify',
|
130
|
-
trigger('vbox:vbox-kill',
|
129
|
+
if trigger('vbox:vbox-verify', vmname)
|
130
|
+
trigger('vbox:vbox-kill', vmname)
|
131
131
|
sleep(1)
|
132
132
|
end
|
133
133
|
log.println("\bdone".bold)
|
134
|
-
trigger('vbox:vbox-delete',
|
134
|
+
trigger('vbox:vbox-delete', vmname) unless trigger('vbox:vbox-verify', vmname)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -140,47 +140,52 @@ module Inprovise::VBox
|
|
140
140
|
|
141
141
|
# add a node object for the new VM unless suppressed
|
142
142
|
apply do
|
143
|
-
|
144
|
-
unless
|
143
|
+
vmname = vbs.vbox_name(self)
|
144
|
+
unless vbs.vbox_no_node(self)
|
145
145
|
# get MAC and IP for VM
|
146
|
-
log.print("Determining IP address for VBox #{
|
146
|
+
log.print("Determining IP address for VBox #{vmname}. Please wait ...|".bold)
|
147
147
|
mac = addr = nil
|
148
148
|
150.times do |n|
|
149
149
|
sleep(2)
|
150
150
|
log.print("\b" + %w{| / - \\}[(n+1) % 4].bold)
|
151
|
-
mac, addr = trigger 'vbox:vbox-ifaddr',
|
151
|
+
mac, addr = trigger 'vbox:vbox-ifaddr', vmname
|
152
152
|
if addr
|
153
153
|
break
|
154
154
|
end
|
155
155
|
end
|
156
156
|
log.println("\bdone".bold)
|
157
|
-
raise RuntimeError, "Failed to determin IP address for VBox #{
|
158
|
-
log("VBox #{
|
159
|
-
vbox_opts =
|
157
|
+
raise RuntimeError, "Failed to determin IP address for VBox #{vmname}" unless addr
|
158
|
+
log("VBox #{vmname} : mac=#{mac}, addr=#{addr}") if Inprovise.verbosity > 0
|
159
|
+
vbox_opts = vbs.vbox_config_hash(self)
|
160
160
|
vbox_opts.delete(:no_node)
|
161
161
|
vbox_opts.delete(:no_sniff)
|
162
|
-
|
162
|
+
node_opts = vbox_opts.delete(:node) || {}
|
163
|
+
node_name = node_opts.delete(:name) || vmname
|
164
|
+
node_opts[:host] ||= addr
|
165
|
+
node_opts[:user] ||= vbs.vbox_user(self)
|
166
|
+
node_opts[:vbox] = vbox_opts
|
167
|
+
node = Inprovise::Infrastructure::Node.new(node_name, node_opts)
|
163
168
|
Inprovise::Infrastructure.save
|
164
|
-
unless
|
169
|
+
unless vbs.vbox_no_sniff(self)
|
165
170
|
# retry on (comm) failure
|
166
171
|
Inprovise::Sniffer.run_sniffers_for(node) rescue Inprovise::Sniffer.run_sniffers_for(node)
|
167
172
|
Inprovise::Infrastructure.save
|
168
173
|
end
|
169
|
-
log("Added new node #{node
|
174
|
+
log("Added new node #{node}".bold)
|
170
175
|
end
|
171
176
|
end
|
172
177
|
|
173
178
|
# remove the node object for the VM unless node creation suppressed
|
174
179
|
revert do
|
175
|
-
|
176
|
-
unless
|
177
|
-
tgt = Inprovise::Infrastructure.find(
|
180
|
+
vmname = vbs.vbox_name(self)
|
181
|
+
unless vbs.vbox_no_node(self)
|
182
|
+
tgt = Inprovise::Infrastructure.find(vmname)
|
178
183
|
if tgt && Inprovise::Infrastructure::Node === tgt
|
179
|
-
Inprovise::Infrastructure.deregister(
|
184
|
+
Inprovise::Infrastructure.deregister(vmname)
|
180
185
|
Inprovise::Infrastructure.save
|
181
|
-
log("Removed node #{tgt
|
186
|
+
log("Removed node #{tgt}".bold)
|
182
187
|
else
|
183
|
-
log("No existing node #{
|
188
|
+
log("No existing node #{vmname} found!".yellow)
|
184
189
|
end
|
185
190
|
end
|
186
191
|
end
|
@@ -194,6 +199,92 @@ module Inprovise::VBox
|
|
194
199
|
self
|
195
200
|
end
|
196
201
|
|
202
|
+
def vbox_name(context)
|
203
|
+
value_for context, context.config[name.to_sym][:name]
|
204
|
+
end
|
205
|
+
|
206
|
+
def vbox_autostart(context)
|
207
|
+
value_for context, context.config[name.to_sym][:autostart]
|
208
|
+
end
|
209
|
+
|
210
|
+
def vbox_no_node(context)
|
211
|
+
value_for context, context.config[name.to_sym][:no_node]
|
212
|
+
end
|
213
|
+
|
214
|
+
def vbox_no_sniff(context)
|
215
|
+
value_for context, context.config[name.to_sym][:no_sniff]
|
216
|
+
end
|
217
|
+
|
218
|
+
def vbox_image(context)
|
219
|
+
value_for context, context.config[name.to_sym][:image]
|
220
|
+
end
|
221
|
+
|
222
|
+
def vbox_memory(context)
|
223
|
+
value_for context, context.config[name.to_sym][:memory]
|
224
|
+
end
|
225
|
+
|
226
|
+
def vbox_cpus(context)
|
227
|
+
value_for context, context.config[name.to_sym][:cpus]
|
228
|
+
end
|
229
|
+
|
230
|
+
def vbox_network(context)
|
231
|
+
value_for context, context.config[name.to_sym][:network]
|
232
|
+
end
|
233
|
+
|
234
|
+
def vbox_netname(context)
|
235
|
+
value_for context, context.config[name.to_sym][:netname]
|
236
|
+
end
|
237
|
+
|
238
|
+
def vbox_os(context)
|
239
|
+
value_for context, context.config[name.to_sym][:os]
|
240
|
+
end
|
241
|
+
|
242
|
+
def vbox_user(context)
|
243
|
+
value_for context, context.config[name.to_sym][:user]
|
244
|
+
end
|
245
|
+
|
246
|
+
def vbox_diskbus(context)
|
247
|
+
value_for context, context.config[name.to_sym][:diskbus]
|
248
|
+
end
|
249
|
+
|
250
|
+
def vbox_format(context)
|
251
|
+
value_for context, context.config[name.to_sym][:format]
|
252
|
+
end
|
253
|
+
|
254
|
+
def vbox_install_opts(context)
|
255
|
+
value_for context, context.config[name.to_sym][:install_opts]
|
256
|
+
end
|
257
|
+
|
258
|
+
def vbox_config_hash(context)
|
259
|
+
context.config[name.to_sym].to_h.reduce({}) do |h, (k,v)|
|
260
|
+
case h[k] = value_for(context, v)
|
261
|
+
when OpenStruct
|
262
|
+
h[k] = config_to_hash(h[k])
|
263
|
+
end
|
264
|
+
h
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def config_to_hash(cfg)
|
269
|
+
cfg.to_h.reduce({}) do |h, (k,v)|
|
270
|
+
h[k] = case v
|
271
|
+
when OpenStruct
|
272
|
+
config_to_hash(v)
|
273
|
+
else
|
274
|
+
v
|
275
|
+
end
|
276
|
+
h
|
277
|
+
end
|
278
|
+
end
|
279
|
+
private :config_to_hash
|
280
|
+
|
281
|
+
def value_for(context, option)
|
282
|
+
return nil if option.nil?
|
283
|
+
return context.instance_exec(&option) if option.respond_to?(:call)
|
284
|
+
option
|
285
|
+
end
|
286
|
+
private :value_for
|
287
|
+
|
197
288
|
end
|
198
289
|
|
199
290
|
end
|