vagrant-node 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/vagrant-node/actions/boxadd.rb +110 -0
- data/lib/vagrant-node/actions/snapshot.rb +1 -1
- data/lib/vagrant-node/api.rb +303 -270
- data/lib/vagrant-node/apidesc.rb +47 -21
- data/lib/vagrant-node/clientcontroller.rb +658 -415
- data/lib/vagrant-node/configmanager.rb +266 -85
- data/lib/vagrant-node/dbmanager.rb +300 -123
- data/lib/vagrant-node/exceptions.rb +15 -0
- data/lib/vagrant-node/nodeserverpasswd.rb +109 -34
- data/lib/vagrant-node/nodeserverstart.rb +4 -3
- data/lib/vagrant-node/nodeserverstop.rb +2 -1
- data/lib/vagrant-node/obmanager.rb +123 -0
- data/lib/vagrant-node/server.rb +27 -21
- data/lib/vagrant-node/util/downloader.rb +182 -0
- data/lib/vagrant-node/version.rb +1 -1
- data/vagrant-node.gemspec +17 -3
- metadata +65 -22
- data/lib/vagrant-node/actions/.svn/entries +0 -62
- data/lib/vagrant-node/actions/.svn/text-base/snapshot.rb.svn-base +0 -310
@@ -24,70 +24,107 @@ module Vagrant
|
|
24
24
|
|
25
25
|
|
26
26
|
def extract_vms_sexp
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
|
28
|
+
|
29
|
+
index=VM_INDEX_START
|
30
|
+
|
31
|
+
if (@config_sexp[0]==:iter)
|
32
|
+
block=@config_sexp
|
33
|
+
else
|
34
|
+
|
35
|
+
gindex=0
|
36
|
+
block=nil
|
37
|
+
@config_sexp.each_sexp do |conf|
|
38
|
+
gindex=gindex+1
|
39
|
+
if (conf.node_type == :iter)
|
40
|
+
block = @config_sexp[gindex]
|
41
|
+
end
|
42
|
+
end
|
33
43
|
|
34
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
raise RestException.new(406,
|
50
|
+
"Config File has no virtual machine configured") if (block.nil? ||
|
51
|
+
block.empty? ||
|
52
|
+
block[index].nil?)
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
if block[index].node_type==:block
|
58
|
+
|
59
|
+
if (block[index].find_nodes(:iter).empty?)
|
35
60
|
#One machine with default style
|
36
61
|
return default_to_block
|
37
62
|
|
38
63
|
else
|
39
64
|
#Several machines configured
|
40
|
-
return
|
65
|
+
return block[index].find_nodes(:iter)
|
41
66
|
end
|
42
67
|
|
43
|
-
else
|
44
|
-
|
45
|
-
return [
|
68
|
+
else
|
69
|
+
|
70
|
+
return [block[index]]
|
46
71
|
end
|
47
72
|
|
48
73
|
end
|
49
74
|
|
50
|
-
def delete_vm (vm_name)
|
75
|
+
def delete_vm (vm_name)
|
76
|
+
index=get_start_index
|
77
|
+
|
51
78
|
|
52
79
|
|
53
|
-
|
54
|
-
#Este caso se presenta cuando existe más de una máquina virtual
|
55
|
-
#O bien cuando la máquina es de tipo default
|
56
|
-
if @config_sexp[VM_INDEX_START].node_type==:block
|
80
|
+
|
57
81
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
vm.find_nodes(:call).first.find_nodes(:lit).each do |node|
|
67
|
-
if node.value === vm_name.to_sym
|
68
|
-
@config_sexp[VM_INDEX_START].delete(vm)
|
69
|
-
save
|
70
|
-
return true
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
82
|
+
if (@config_sexp[0]==:iter)
|
83
|
+
nodo=@config_sexp
|
84
|
+
else
|
85
|
+
nodo=@config_sexp.find_nodes(:iter).first
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
if (!nodo[VM_INDEX_START].nil?)
|
75
90
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
if (nodo[VM_INDEX_START].node_type == :iter)
|
92
|
+
vm = nodo[VM_INDEX_START].find_nodes(:call)
|
93
|
+
|
94
|
+
if (!vm.empty?)
|
95
|
+
leaf= vm.first.find_nodes(:lit)
|
96
|
+
|
97
|
+
if (!leaf.empty? && leaf.first.value === vm_name.to_sym)
|
98
|
+
nodo.delete_at(VM_INDEX_START)
|
99
|
+
|
100
|
+
save
|
101
|
+
return true
|
102
|
+
end
|
86
103
|
end
|
104
|
+
elsif (nodo[VM_INDEX_START].node_type == :block)
|
105
|
+
nodo[VM_INDEX_START].each_sexp do |vm|
|
87
106
|
|
107
|
+
|
108
|
+
subnode=vm.find_nodes(:call)
|
109
|
+
if (!subnode.empty?)
|
110
|
+
leaf=subnode.first.find_nodes(:lit)
|
111
|
+
if (!leaf.empty? && leaf.first.value === vm_name.to_sym)
|
112
|
+
|
113
|
+
nodo[VM_INDEX_START].delete(vm)
|
114
|
+
save
|
115
|
+
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
88
121
|
end
|
122
|
+
|
123
|
+
|
89
124
|
end
|
90
125
|
|
126
|
+
|
127
|
+
|
91
128
|
raise RestException.new(404,"Virtual Machine #{vm_name} not found")
|
92
129
|
|
93
130
|
|
@@ -95,17 +132,18 @@ module Vagrant
|
|
95
132
|
|
96
133
|
|
97
134
|
def get_vm_names
|
98
|
-
|
99
|
-
|
135
|
+
|
136
|
+
index=get_start_index
|
137
|
+
raise RestException.new(406,"No virtual machine configured") if @config_sexp[index].nil?
|
100
138
|
|
101
139
|
names = []
|
102
|
-
if @config_sexp[
|
140
|
+
if @config_sexp[index].node_type==:block
|
103
141
|
#Entorno con una maquina configurada fuera de bloque
|
104
|
-
if (@config_sexp[
|
142
|
+
if (@config_sexp[index].find_nodes(:iter).empty?)
|
105
143
|
names.push(:default)
|
106
144
|
else
|
107
145
|
#Entorno multi vm
|
108
|
-
@config_sexp[
|
146
|
+
@config_sexp[index].each_sexp do |vm|
|
109
147
|
vm.find_nodes(:call).first.find_nodes(:lit).each do |node|
|
110
148
|
names.push(node.value)
|
111
149
|
end
|
@@ -117,7 +155,7 @@ module Vagrant
|
|
117
155
|
#una maquina virtual configurada. En este caso
|
118
156
|
#@config_sexp[VM_INDEX_START] contiene la definicion
|
119
157
|
#de la maquina directamente
|
120
|
-
node=@config_sexp[
|
158
|
+
node=@config_sexp[index].find_nodes(:call).first.find_node(:lit)
|
121
159
|
names.push(node.value)
|
122
160
|
|
123
161
|
end
|
@@ -129,6 +167,7 @@ module Vagrant
|
|
129
167
|
#FIXME REVISAR PORQUE CUANDO QUEDA UNA ÚNICA máquina en un entorno
|
130
168
|
#multi vm el fichero cambia
|
131
169
|
def rename_vm(old_name,new_name)
|
170
|
+
|
132
171
|
machines = extract_vms_sexp
|
133
172
|
|
134
173
|
machines.each do |machine|
|
@@ -139,18 +178,40 @@ module Vagrant
|
|
139
178
|
|
140
179
|
end
|
141
180
|
|
142
|
-
def insert_vms_sexp(vms_sexp)
|
181
|
+
def insert_vms_sexp(vms_sexp)
|
182
|
+
|
143
183
|
raise RestException.new(406,"Invalid configuration file supplied") if vms_sexp.nil? || vms_sexp.empty?
|
184
|
+
index=VM_INDEX_START
|
144
185
|
|
145
|
-
|
186
|
+
|
187
|
+
|
188
|
+
if @config_sexp[0]==:iter
|
189
|
+
block=@config_sexp
|
190
|
+
else
|
191
|
+
gindex=0
|
192
|
+
block=nil
|
193
|
+
@config_sexp.each_sexp do |conf|
|
194
|
+
gindex=gindex+1
|
195
|
+
if (!conf.nil? && conf.node_type == :iter)
|
196
|
+
block = @config_sexp[gindex]
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
if !block[VM_INDEX_START].nil?
|
146
207
|
# If @config_sexp[VM_INDEX_START] isn't nil could mean three things:
|
147
|
-
# -- There is machine
|
208
|
+
# -- There is a machine configured with a default style
|
148
209
|
# -- There are some machines inserted inside a block
|
149
|
-
# -- There is only one machine and it is stored at
|
150
|
-
if
|
151
|
-
# If node is a block
|
152
|
-
if (
|
153
|
-
# This case match the first option, so the steps to
|
210
|
+
# -- There is only one machine and it is stored at block[VM_INDEX_START]
|
211
|
+
if block[VM_INDEX_START].node_type==:block
|
212
|
+
# If node is a block it could be the first two options
|
213
|
+
if (block[VM_INDEX_START].find_nodes(:iter).empty?)
|
214
|
+
# This case match the first option, so the steps to perform are the following:
|
154
215
|
# -- Create a block node
|
155
216
|
new_block = s(:block)
|
156
217
|
# -- Convert the current machine to a block style and insert into the block
|
@@ -159,26 +220,50 @@ module Vagrant
|
|
159
220
|
new_block.add(vms_sexp)
|
160
221
|
|
161
222
|
|
162
|
-
@config_sexp.delete_at(
|
223
|
+
@config_sexp.delete_at(index)
|
163
224
|
|
164
|
-
@config_sexp[
|
225
|
+
@config_sexp[index] = new_block
|
165
226
|
|
166
227
|
|
167
|
-
else
|
228
|
+
else
|
168
229
|
# This case means that there are some machines inserted inside a block
|
169
230
|
# we only have to add thems
|
170
231
|
#FIXME FALTA COMPREOBAR SI HACE FALTA RENOMBRAR
|
171
|
-
@config_sexp[
|
232
|
+
if @config_sexp[0]==:iter
|
233
|
+
@config_sexp[VM_INDEX_START].add(vms_sexp)
|
234
|
+
elsif @config_sexp[0]==:block
|
235
|
+
@config_sexp[gindex][VM_INDEX_START].add(vms_sexp)
|
236
|
+
end
|
237
|
+
|
172
238
|
end
|
173
239
|
|
174
|
-
else
|
175
|
-
|
240
|
+
else
|
241
|
+
|
242
|
+
|
243
|
+
#There is only one machine stored, we can store it at @config_sexp[index]
|
176
244
|
new_block = s(:block)
|
177
|
-
|
178
|
-
|
179
|
-
@config_sexp.delete_at(VM_INDEX_START)
|
180
|
-
@config_sexp[VM_INDEX_START] = new_block
|
245
|
+
|
246
|
+
result = extract_vms_sexp
|
181
247
|
|
248
|
+
|
249
|
+
if (@config_sexp[0]==:block)
|
250
|
+
#SI el elemento 0 es un bloque
|
251
|
+
|
252
|
+
new_block.add(result)
|
253
|
+
new_block.add(vms_sexp)
|
254
|
+
|
255
|
+
|
256
|
+
block.delete_at(VM_INDEX_START)
|
257
|
+
@config_sexp[gindex][VM_INDEX_START]=new_block
|
258
|
+
|
259
|
+
else
|
260
|
+
new_block.add(extract_vms_sexp)
|
261
|
+
new_block.add(vms_sexp)
|
262
|
+
@config_sexp.delete_at(index)
|
263
|
+
|
264
|
+
|
265
|
+
@config_sexp[index] = new_block
|
266
|
+
end
|
182
267
|
|
183
268
|
end
|
184
269
|
else
|
@@ -195,9 +280,9 @@ module Vagrant
|
|
195
280
|
if (vms_sexp.length>1)
|
196
281
|
new_block = s(:block)
|
197
282
|
new_block.add(vms_sexp)
|
198
|
-
@config_sexp[
|
283
|
+
@config_sexp[index] = new_block
|
199
284
|
else
|
200
|
-
@config_sexp[
|
285
|
+
@config_sexp[index] = vms_sexp.first
|
201
286
|
end
|
202
287
|
|
203
288
|
end
|
@@ -210,7 +295,7 @@ module Vagrant
|
|
210
295
|
end
|
211
296
|
|
212
297
|
#Ruby2Ruby modify the parameter, so a deep cloned copy is passed
|
213
|
-
def config_content
|
298
|
+
def config_content
|
214
299
|
begin
|
215
300
|
Ruby2Ruby.new.process(@config_sexp.dclone)
|
216
301
|
rescue => e
|
@@ -218,7 +303,7 @@ module Vagrant
|
|
218
303
|
end
|
219
304
|
end
|
220
305
|
|
221
|
-
def save
|
306
|
+
def save
|
222
307
|
#Processing the content first. If there is any error
|
223
308
|
#the file wont'be modified
|
224
309
|
content= config_content
|
@@ -231,24 +316,31 @@ module Vagrant
|
|
231
316
|
private
|
232
317
|
VM_INDEX_START = 3
|
233
318
|
DEFAULT_BLOCK_NAME = :default_config
|
319
|
+
DEFAULT_MACHINE = "default"
|
234
320
|
|
235
321
|
|
236
322
|
|
237
|
-
def rename_block_to_default(exp)
|
323
|
+
def rename_block_to_default(exp)
|
238
324
|
exp.each_sexp do |node|
|
239
|
-
rename_block_to_default(node)
|
240
|
-
# pp node.node_type
|
325
|
+
rename_block_to_default(node)
|
241
326
|
if (node.node_type == :lvar)
|
242
327
|
node[1]=DEFAULT_BLOCK_NAME
|
243
328
|
end
|
244
329
|
end
|
245
330
|
end
|
246
331
|
|
332
|
+
def get_start_index
|
333
|
+
|
334
|
+
if (@config_sexp[0]==:iter)
|
335
|
+
return VM_INDEX_START
|
336
|
+
else
|
337
|
+
return VM_INDEX_START-1
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
247
341
|
#Process a default virtual machine and produces
|
248
342
|
#a block with the vm configuration
|
249
|
-
def default_to_block
|
250
|
-
|
251
|
-
|
343
|
+
def default_to_block
|
252
344
|
#Getting the main block name
|
253
345
|
mblock_name = @config_sexp[2].value.to_s
|
254
346
|
|
@@ -256,7 +348,7 @@ module Vagrant
|
|
256
348
|
|
257
349
|
result= RubyParser.new.parse(
|
258
350
|
"Vagrant.configure('2') do |#{mblock_name}|"+
|
259
|
-
"#{mblock_name}.vm.define(
|
351
|
+
"#{mblock_name}.vm.define(:#{DEFAULT_MACHINE}) do |#{DEFAULT_BLOCK_NAME.to_s}|\n"+
|
260
352
|
Ruby2Ruby.new.process(@config_sexp[VM_INDEX_START].dclone)+
|
261
353
|
"end\nend"
|
262
354
|
)
|
@@ -266,15 +358,104 @@ module Vagrant
|
|
266
358
|
return [result[VM_INDEX_START]]
|
267
359
|
end
|
268
360
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
361
|
+
|
362
|
+
def convert_default_to_block
|
363
|
+
|
364
|
+
if (@config_sexp[0]==:iter)
|
365
|
+
|
366
|
+
|
367
|
+
#Caso en el que el fichero no tiene ningún contenido, tan solo el config
|
368
|
+
if (!@config_sexp[VM_INDEX_START].nil?)
|
369
|
+
if (@config_sexp[VM_INDEX_START].node_type==:attrasgn)
|
370
|
+
#Caso en el que el fichero es por defecto y los atributos están fuera
|
371
|
+
#de un bloque
|
372
|
+
new_block = s(:block)
|
373
|
+
new_block.add(default_to_block)
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
@config_sexp.delete_at(VM_INDEX_START)
|
378
|
+
@config_sexp[VM_INDEX_START] = new_block
|
379
|
+
|
380
|
+
elsif (@config_sexp[VM_INDEX_START].node_type==:block &&
|
381
|
+
@config_sexp[VM_INDEX_START].find_nodes(:iter).empty?)
|
382
|
+
|
383
|
+
new_block = s(:block)
|
384
|
+
new_block.add(default_to_block)
|
385
|
+
|
386
|
+
@config_sexp.delete_at(VM_INDEX_START)
|
387
|
+
@config_sexp[VM_INDEX_START] = new_block
|
388
|
+
|
389
|
+
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
else
|
394
|
+
#Busco donde comienza la declaración del bloque principal
|
395
|
+
|
396
|
+
gindex=0
|
397
|
+
block=nil
|
398
|
+
@config_sexp.each_sexp do |conf|
|
399
|
+
gindex=gindex+1
|
400
|
+
if (conf.node_type == :iter)
|
401
|
+
block = @config_sexp[gindex]
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
if (!block.nil?)
|
409
|
+
|
410
|
+
if (block[VM_INDEX_START].nil?)
|
411
|
+
mblock_name = block[2][1].to_s
|
412
|
+
block= RubyParser.new.parse(
|
413
|
+
"Vagrant.configure('2') do |#{mblock_name}|"+
|
414
|
+
"#{mblock_name}.vm.define(:#{DEFAULT_MACHINE}) do |#{DEFAULT_BLOCK_NAME.to_s}|\n"+
|
415
|
+
"end\nend"
|
416
|
+
)
|
417
|
+
|
418
|
+
@config_sexp[gindex] = block
|
419
|
+
|
420
|
+
elsif (!block[VM_INDEX_START].nil? && block[VM_INDEX_START].node_type==:attrasgn)
|
421
|
+
|
422
|
+
|
423
|
+
mblock_name = block[2][1].to_s
|
274
424
|
|
275
|
-
|
276
|
-
|
425
|
+
|
426
|
+
rename_block_to_default(block[VM_INDEX_START])
|
427
|
+
|
428
|
+
block= RubyParser.new.parse(
|
429
|
+
"Vagrant.configure('2') do |#{mblock_name}|"+
|
430
|
+
"#{mblock_name}.vm.define(:#{DEFAULT_MACHINE}) do |#{DEFAULT_BLOCK_NAME.to_s}|\n"+
|
431
|
+
Ruby2Ruby.new.process(block[VM_INDEX_START].dclone)+
|
432
|
+
"end\nend"
|
433
|
+
)
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
@config_sexp[gindex]=block
|
440
|
+
|
441
|
+
|
442
|
+
elsif (block[VM_INDEX_START].node_type==:block &&
|
443
|
+
block[VM_INDEX_START].find_nodes(:iter).empty?)
|
444
|
+
|
445
|
+
|
446
|
+
new_block = s(:block)
|
447
|
+
new_block.add(default_to_block)
|
448
|
+
|
449
|
+
block.delete_at(VM_INDEX_START)
|
450
|
+
block[VM_INDEX_START] = new_block
|
451
|
+
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|
456
|
+
|
277
457
|
end
|
458
|
+
|
278
459
|
end
|
279
460
|
|
280
461
|
end
|