vagrant-node 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,29 +2,71 @@
2
2
  require 'vagrant'
3
3
  require 'vagrant-node/actions/snapshot'
4
4
  require 'vagrant-node/dbmanager'
5
- #require 'sambal'
5
+ require 'vagrant-node/pwmanager'
6
+ require 'vagrant-node/exceptions.rb'
7
+ require 'vagrant-node/configmanager'
8
+
6
9
 
7
10
  module Vagrant
8
11
  module Node
9
- class ClientController
12
+
13
+
14
+
15
+ class ClientController
16
+
17
+
18
+ def self.execute_queued
19
+ ensure_environment
20
+ #Generating a random identifier for process
21
+ rpid=rand(1000000)
22
+
23
+ pid = fork do
24
+ begin
25
+ @db.create_queued_process(rpid)
26
+ res = yield
27
+ @db.set_queued_process_result(rpid,res.to_json)
28
+
29
+ rescue Exception => e
30
+ @db.set_queued_process_error(rpid,e)
31
+ end
32
+ end
33
+ rpid
34
+ end
35
+
36
+ def self.send_challenge
37
+ challenge = SecureRandom.urlsafe_base64(nil, false)
38
+ cookie = SecureRandom.urlsafe_base64(nil, false)
39
+
40
+
41
+ {:cookie => cookie, :challenge => challenge}
42
+ end
43
+
44
+ def self.authorized?(token,challenge)
45
+ ensure_environment
46
+
47
+ @pw.authorized?(token,challenge)
48
+ end
10
49
 
11
50
  ################################################################
12
51
  ####################### BOX LIST METHOD #######################
13
52
  ################################################################
14
53
  def self.listboxes
54
+
55
+
56
+ ensure_environment
57
+
58
+ boxes = @env.boxes.all.sort
59
+
60
+ fboxes = Array.new
61
+ boxes.each do |name, provider|
62
+ fboxes << {"name" => name,"provider" => provider}
63
+ end
64
+
65
+
66
+ fboxes
15
67
 
16
- ensure_environment
17
-
18
- boxes = @env.boxes.all.sort
19
-
20
- fboxes = Array.new
21
- boxes.each do |name, provider|
22
- fboxes << {"name" => name,"provider" => provider}
23
- end
24
-
25
- fboxes
26
68
 
27
- end
69
+ end
28
70
 
29
71
  ################################################################
30
72
  ####################### BOX DELETE METHOD #####################
@@ -39,7 +81,7 @@ module Vagrant
39
81
 
40
82
  if (box)
41
83
  boxes << box.name
42
- box.destroy!
84
+ box.destroy!
43
85
  end
44
86
 
45
87
  boxes
@@ -50,234 +92,318 @@ module Vagrant
50
92
  ######################## BOX ADD METHOD #######################
51
93
  ################################################################
52
94
  def self.box_add(box,url,user="guest",pass="--no-pass")
53
-
54
- ensure_environment
55
-
56
- boxes = []
57
-
58
- #TODO
59
-
60
- # Get the provider if one was set
61
- provider = nil
62
- # provider = options[:provider].to_sym if options[:provider]
63
-
64
- begin
65
-
66
- uri = "\\\\155.54.190.227\\boxtmp\\boxes\\debian_squeeze_32.box"
67
- #
68
- # if uri=~ /^\\\\(.*?)\\(.*?)\\(.*?)$/
69
- # puts "EL HOST ES #{$1}"
70
- # puts "EL Share ES #{$2}"
71
- # puts "EL PATH ES #{$3}"
72
- # host = $1
73
- # share = $2
74
- # path = $3
75
- #
76
- # Getting and checking box file
77
- # boxname=File.basename(path.gsub('\\',File::SEPARATOR))
78
- #
79
- # raise 'Box file format not supported' if File.extname(boxname)!=".box"
80
- #
81
- # samba = nil
82
- # begin
83
- # samba = Sambal::Client.new( :host => host,
84
- # :share => share,
85
- # :user => user,
86
- # :password => pass)
87
- #
88
- #
89
- #
90
- # Get the tmp file name
91
- # temp_path = @env.tmp_path.join("box" + Time.now.to_i.to_s)
92
- #
93
- #
94
- # response = nil
95
- #
96
- # smbclient //155.54.190.227/boxtmp --no-pass -W WORKGROUP -U guest -p 445
97
- # smbclient //155.54.190.227/boxtmp -D boxes -c "get debian_squeeze_321.box" -N
98
- #
99
- # command="smbclient //#{host}/#{share} -D #{dirlocation} -c \"get #{boxname}\" -U #{user} --no-pass"
100
- #
101
- #
102
- # FIXME encontrar si existe algún tipo de notificación por
103
- # interrupciónde la descarga
104
- # FIXME a little hack beacuse in version 0.1.2 of sambal there is
105
- # a timeout that close the download after 10 seconds
106
- # def samba.ask(cmd)
107
- # @i.printf("#{cmd}\n")
108
- # response = @o.expect(/^smb:.*\\>/)[0]
109
- # end
110
- #
111
- # response = samba.get(path, temp_path.to_s)
112
- # FIXME DELETE
113
- # pp response.inspect
114
- #
115
- # raise response.message if !response.success?
116
- #
117
- # if response.success?
118
- # File download succesfully
119
- # added_box = nil
120
- # begin
121
- # provider=nil
122
- # force = true
123
- # added_box = @env.boxes.add(temp_path,box,nil,force)
124
- # boxes << {:name=>box,:provider=>added_box.provider.to_s}
125
- # rescue Vagrant::Errors::BoxUpgradeRequired
126
- # Upgrade the box
127
- # env.boxes.upgrade(box)
128
- #
129
- # Try adding it again
130
- # retry
131
- # rescue Exception => e
132
- # boxes = nil
133
- # end
134
- #
135
- # end
136
- #
137
- # rescue Exception => e
138
- # puts "EXCEPCION de descarga" if response
139
- # puts "EXCEPCION de conexion" if !response
140
- # puts e.message
141
- # boxes=nil
142
- # end
143
- #
144
- #
145
- # Closing connection
146
- # samba.close if samba
147
- #
148
- #
149
- # Cleaning
150
- # if temp_path && File.exist?(temp_path)
151
- # File.unlink(temp_path)
152
- # end
153
- #
154
- #
155
- # else
156
- # FIXME Ver qué poner en los parámetros de la llamada
157
- provider=nil
158
- force = true # Always overwrite box if exists
159
- insecure = true #Don't validate SSL certs
160
- #Calling original box add action
161
- @env.action_runner.run(Vagrant::Action.action_box_add, {
162
- :box_name => box,
163
- :box_provider => provider,
164
- :box_url => url,
165
- :box_force => force,
166
- :box_download_insecure => insecure,
167
- })
95
+ command_block = Proc.new {
96
+ #ensure_environment
97
+
98
+ boxes = []
99
+
100
+ #TODO
101
+
102
+ # Get the provider if one was set
103
+ provider = nil
104
+ # provider = options[:provider].to_sym if options[:provider]
105
+
106
+ begin
107
+
108
+ #uri = "\\\\155.54.190.227\\boxtmp\\boxes\\debian_squeeze_32.box"
109
+ #
110
+ # if uri=~ /^\\\\(.*?)\\(.*?)\\(.*?)$/
111
+ # puts "EL HOST ES #{$1}"
112
+ # puts "EL Share ES #{$2}"
113
+ # puts "EL PATH ES #{$3}"
114
+ # host = $1
115
+ # share = $2
116
+ # path = $3
117
+ #
118
+ # Getting and checking box file
119
+ # boxname=File.basename(path.gsub('\\',File::SEPARATOR))
120
+ #
121
+ # raise 'Box file format not supported' if File.extname(boxname)!=".box"
122
+ #
123
+ # samba = nil
124
+ # begin
125
+ # samba = Sambal::Client.new( :host => host,
126
+ # :share => share,
127
+ # :user => user,
128
+ # :password => pass)
129
+ #
130
+ #
131
+ #
132
+ # Get the tmp file name
133
+ # temp_path = @env.tmp_path.join("box" + Time.now.to_i.to_s)
134
+ #
135
+ #
136
+ # response = nil
137
+ #
138
+ # smbclient //155.54.190.227/boxtmp --no-pass -W WORKGROUP -U guest -p 445
139
+ # smbclient //155.54.190.227/boxtmp -D boxes -c "get debian_squeeze_321.box" -N
140
+ #
141
+ # command="smbclient //#{host}/#{share} -D #{dirlocation} -c \"get #{boxname}\" -U #{user} --no-pass"
142
+ #
143
+ #
144
+ # FIXME encontrar si existe algún tipo de notificación por
145
+ # interrupciónde la descarga
146
+ # FIXME a little hack beacuse in version 0.1.2 of sambal there is
147
+ # a timeout that close the download after 10 seconds
148
+ # def samba.ask(cmd)
149
+ # @i.printf("#{cmd}\n")
150
+ # response = @o.expect(/^smb:.*\\>/)[0]
151
+ # end
152
+ #
153
+ # response = samba.get(path, temp_path.to_s)
154
+ # FIXME DELETE
155
+ # pp response.inspect
156
+ #
157
+ # raise response.message if !response.success?
158
+ #
159
+ # if response.success?
160
+ # File download succesfully
161
+ # added_box = nil
162
+ # begin
163
+ # provider=nil
164
+ # force = true
165
+ # added_box = @env.boxes.add(temp_path,box,nil,force)
166
+ # boxes << {:name=>box,:provider=>added_box.provider.to_s}
167
+ # rescue Vagrant::Errors::BoxUpgradeRequired
168
+ # Upgrade the box
169
+ # env.boxes.upgrade(box)
170
+ #
171
+ # Try adding it again
172
+ # retry
173
+ # rescue Exception => e
174
+ # boxes = nil
175
+ # end
176
+ #
177
+ # end
178
+ #
179
+ # rescue Exception => e
180
+ # puts "EXCEPCION de descarga" if response
181
+ # puts "EXCEPCION de conexion" if !response
182
+ # puts e.message
183
+ # boxes=nil
184
+ # end
185
+ #
186
+ #
187
+ # Closing connection
188
+ # samba.close if samba
189
+ #
190
+ #
191
+ # Cleaning
192
+ # if temp_path && File.exist?(temp_path)
193
+ # File.unlink(temp_path)
194
+ # end
195
+ #
196
+ #
197
+ # else
198
+
199
+
200
+
201
+ boxes <<{:name=>box}
202
+ # FIXME Ver qué poner en los parámetros de la llamada
203
+ provider=nil
204
+ force = true # Always overwrite box if exists
205
+ insecure = true #Don't validate SSL certs
206
+ #Calling original box add action
207
+ @env.action_runner.run(Vagrant::Action.action_box_add, {
208
+ :box_name => box,
209
+ :box_provider => provider,
210
+ :box_url => url,
211
+ :box_force => force,
212
+ :box_download_insecure => insecure,
213
+ })
214
+
215
+ # end
216
+
217
+
218
+
219
+
168
220
 
169
- # end
170
-
221
+
222
+ boxes
223
+
171
224
  rescue =>e
172
225
  puts e.message
173
226
  end
174
227
 
175
-
176
- boxes
228
+ }
229
+ method("execute_queued").call(&command_block);
177
230
 
178
231
  end
179
232
 
233
+
234
+
180
235
  ################################################################
181
236
  ################## VIRTUAL MACHINE UP METHOD ##################
182
237
  ################################################################
183
238
  def self.vm_up(vmname)
184
- ensure_environment
185
-
239
+ command_block = Proc.new {
240
+ #ensure_environment
241
+
186
242
  machine_names = []
187
243
 
188
- begin
189
-
244
+ #begin
245
+
190
246
  options = {}
191
247
  options[:parallel] = true
192
248
 
193
249
  #Launching machines
194
250
  @env.batch(options[:parallel]) do |batch|
195
- get_vms(vmname).each do |machine|
196
- machine_names << machine.name
197
- batch.action(machine, :up, options)
251
+ get_vms(vmname).each do |machine|
252
+ batch.action(machine, :up, options)
253
+ machine_names << {"vmname" => machine.name.to_s,
254
+ "status" => "running"}
198
255
  end
199
256
  end
200
257
 
201
-
258
+
202
259
  machine_names
260
+ }
203
261
 
204
- rescue => e
205
- # return nil
206
- end
262
+ method("execute_queued").call(&command_block);
263
+
264
+ # rescue Vagrant::Errors::BoxNotFound => e
265
+ # puts "BOX NOT FOUND"
266
+ # rescue => e
267
+ # pp e
268
+ # puts e.message
269
+ # raise RestException.new(404,e.message)
270
+ # end
207
271
 
208
272
  end
209
273
 
210
- ################################################################
211
- ################ VIRTUAL MACHINE DESTROY METHOD ###############
274
+
275
+
276
+
212
277
  ################################################################
213
-
214
- def self.vm_confirmed_destroy(vmname)
215
- ensure_environment
278
+ ################ VIRTUAL MACHINE ADD METHOD ###############
279
+ ################################################################
280
+
281
+ def self.vm_add(config,rename)
282
+ ensure_environment
283
+ begin
284
+ path="/tmp/conf."+Time.now.to_i.to_s
285
+ f = File.new(path, "w")
286
+ f.write(config)
287
+ f.close
288
+
289
+
290
+ cm = ConfigManager.new(@env.root_path+"Vagrantfile")
291
+ cmtmp = ConfigManager.new(path)
292
+
293
+
294
+ current_vms = @env.machine_names
295
+
296
+ cmtmp.get_vm_names.each do |key|
297
+
298
+ if current_vms.include?(key)
299
+ raise RestException.new(406,"There is a remote VM with the same name: \"#{key}\"") if rename=="false"
300
+ cmtmp.rename_vm(key,"#{key}_1")
301
+ end
302
+ end
303
+
304
+ cm.insert_vms_sexp(cmtmp.extract_vms_sexp)
305
+
306
+ rescue => e
307
+ raise e
308
+ ensure
309
+ File.delete(path)
310
+ end
311
+
312
+
313
+ end
314
+
315
+
316
+ ################################################################
317
+ ################ VIRTUAL MACHINE DELETE METHOD ###############
318
+ ################################################################
319
+
320
+ def self.vm_delete(vmname,remove=false)
321
+ ensure_environment
322
+
323
+ cm = ConfigManager.new(@env.root_path+"Vagrantfile")
324
+
325
+ self.vm_confirmed_destroy(vmname) if remove!=false
326
+
327
+ cm.delete_vm(vmname)
328
+
329
+ true
330
+
331
+ end
216
332
 
217
- machine_names = []
218
-
219
- begin
220
-
221
- get_vms(vmname).each do |machine|
222
- machine_names << machine.name
223
- machine.action(:destroy, :force_confirm_destroy => true)
224
- end
225
-
226
- machine_names
227
-
228
- rescue => e
229
- # return nil
230
- end
231
-
232
- end
333
+ ################################################################
334
+ ################ VIRTUAL MACHINE DESTROY METHOD ###############
335
+ ################################################################
336
+
337
+ def self.vm_confirmed_destroy(vmname)
338
+ ensure_environment
339
+
340
+ machine_names = []
341
+
342
+
343
+ #begin
344
+
345
+ get_vms(vmname.to_sym).each do |machine|
346
+ machine_names << machine.name
347
+ machine.action(:destroy, :force_confirm_destroy => true)
348
+ end
349
+
350
+ machine_names
351
+
352
+ #rescue => e
353
+ # return nil
354
+ #end
355
+
356
+ end
233
357
 
234
358
  ################################################################
235
359
  ################# VIRTUAL MACHINE HALT METHOD #################
236
360
  ################################################################
237
361
  def self.vm_halt(vmname,force)
238
- ensure_environment
239
-
240
- machine_names = []
241
-
242
- begin
243
-
244
- get_vms(vmname).each do |machine|
245
- machine_names << machine.name
246
- machine.action(:halt, :force_halt => force)
247
- end
248
-
249
- machine_names
362
+ command_block = Proc.new {
363
+ #ensure_environment
364
+
365
+ machine_names = []
366
+
367
+ #begin
368
+
369
+ get_vms(vmname).each do |machine|
370
+ machine.action(:halt, :force_halt => force)
371
+ machine_names << {"vmname" => machine.name.to_s,
372
+ "status" => machine.state.short_description}
373
+ end
374
+
375
+ machine_names
376
+ }
377
+
378
+ method("execute_queued").call(&command_block);
250
379
 
251
- rescue => e
380
+ #rescue => e
252
381
  # return nil
253
- end
382
+ #end
254
383
 
255
384
  end
256
385
 
257
386
  ################################################################
258
387
  ################# VIRTUAL MACHINE STATUS METHOD ###############
259
388
  ################################################################
260
- def self.vm_status(vmname)
389
+ def self.vm_status(vmname=nil)
261
390
  ensure_environment
262
391
 
263
- begin
392
+
264
393
 
265
- status = Array.new
266
-
267
- get_vms(vmname).each do |machine|
394
+ status = Array.new
395
+
396
+ get_vms(vmname).each do |machine|
397
+
398
+ status << {"name" => machine.name.to_s,
399
+ "status" => machine.state.short_description,
400
+ "provider" => machine.provider_name}
401
+ end
402
+
403
+
404
+ status
268
405
 
269
- status << {"name" => machine.name.to_s,
270
- "status" => machine.state.short_description,
271
- "provider" => machine.provider_name}
272
- end
273
-
274
406
 
275
- status
276
-
277
- rescue => e
278
- puts e.message
279
- # return nil
280
- end
281
407
 
282
408
  end
283
409
 
@@ -285,26 +411,27 @@ module Vagrant
285
411
  ################## VIRTUAL MACHINE SUSPEND METHOD ##################
286
412
  ################################################################
287
413
  def self.vm_suspend(vmname)
288
- ensure_environment
414
+ command_block = Proc.new {
415
+ #ensure_environment
289
416
 
290
- machine_names = []
417
+ machine_names = []
291
418
 
292
- begin
419
+
293
420
 
294
421
 
295
422
  #Suspendiing machines
296
- get_vms(vmname).each do |machine|
297
- machine_names << machine.name
423
+ get_vms(vmname).each do |machine|
298
424
  machine.action(:suspend)
425
+ machine_names << {"vmname" => machine.name.to_s,
426
+ "status" => machine.state.short_description}
299
427
  end
300
428
 
301
429
 
302
- machine_names
430
+ machine_names
431
+
432
+ }
303
433
 
304
- rescue => e
305
- puts e.message
306
- # return nil
307
- end
434
+ method("execute_queued").call(&command_block);
308
435
 
309
436
  end
310
437
 
@@ -312,38 +439,35 @@ module Vagrant
312
439
  ################## VIRTUAL MACHINE RESUME METHOD ##################
313
440
  ################################################################
314
441
  def self.vm_resume(vmname)
315
- ensure_environment
442
+ command_block = Proc.new {
443
+ #ensure_environment
316
444
 
317
- machine_names = []
318
-
319
-
320
- begin
321
-
445
+ machine_names = []
322
446
  #Launching machines
323
447
 
324
- get_vms(vmname).each do |machine|
325
- machine_names << machine.name
326
- machine.action(:resume)
448
+ get_vms(vmname).each do |machine|
449
+ machine.action(:resume)
450
+ machine_names << {"vmname" => machine.name.to_s,
451
+ "status" => machine.state.short_description}
327
452
  end
328
453
 
329
454
 
330
455
 
331
456
  machine_names
332
-
333
- rescue => e
334
- puts e.message
335
- # return nil
336
- end
457
+ }
458
+
459
+ method("execute_queued").call(&command_block);
460
+
337
461
 
338
462
  end
339
463
 
340
464
  ################################################################
341
465
  ############ VIRTUAL MACHINE SNAPSHOT LIST METHOD #############
342
466
  ################################################################
343
- def self.vm_snapshots(vmname)
467
+ def self.vm_snapshots(vmname=nil)
344
468
  ensure_environment
345
469
 
346
- begin
470
+ #begin
347
471
 
348
472
  snapshots = {}
349
473
 
@@ -362,13 +486,13 @@ module Vagrant
362
486
 
363
487
  end
364
488
 
365
-
489
+
366
490
  snapshots
367
491
 
368
- rescue => e
369
- puts e.message
370
- # return nil
371
- end
492
+ # rescue => e
493
+ # puts e.message
494
+ # # return nil
495
+ # end
372
496
 
373
497
  end
374
498
 
@@ -376,42 +500,103 @@ module Vagrant
376
500
  ############ VIRTUAL MACHINE SNAPSHOT TAKE METHOD #############
377
501
  ################################################################
378
502
  def self.vm_snapshot_take(vmname,name,desc=" ")
379
- ensure_environment
503
+ command_block = Proc.new {
504
+ #ensure_environment
380
505
 
381
- begin
382
-
383
- get_vms(vmname).each do |machine|
384
- env =
385
- {
386
- :machine => machine,
387
- :machine_action => SnapshotAction::TAKE,
388
- :snapshot_name => name,
389
- :snapshot_desc => desc
390
- }
391
-
392
-
393
- res = @env.action_runner.run(SnapshotAction,env)
394
-
395
- return res[:last_snapshot]
396
-
397
- end
398
-
399
- rescue => e
400
- puts e.message
401
- # return nil
402
- end
506
+
507
+ raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
508
+
509
+
510
+ machine = get_vms(vmname)
511
+ raise RestException.new(404,"Virtual Machine not found") if (machine.empty?)
512
+
513
+ env =
514
+ {
515
+ :machine => machine.first,
516
+ :machine_action => SnapshotAction::TAKE,
517
+ :snapshot_name => name,
518
+ :snapshot_desc => desc
519
+ }
520
+
521
+ res = @env.action_runner.run(SnapshotAction,env)
522
+
523
+ res[:last_snapshot]
524
+
525
+
526
+ # get_vms(vmname).each do |machine|
527
+ # env =
528
+ # {
529
+ # :machine => machine,
530
+ # :machine_action => SnapshotAction::TAKE,
531
+ # :snapshot_name => name,
532
+ # :snapshot_desc => desc
533
+ # }
534
+ #
535
+ # res = @env.action_runner.run(SnapshotAction,env)
536
+ #
537
+ # return res[:last_snapshot]
538
+ #
539
+ # end
540
+
541
+
542
+ }
543
+
544
+ method("execute_queued").call(&command_block);
403
545
 
404
546
  end
405
547
 
548
+ ################################################################
549
+ ############ VIRTUAL MACHINE SNAPSHOT DELETE METHOD #############
550
+ ################################################################
551
+ def self.vm_snapshot_delete(vmname,snapshot_id)
552
+ ensure_environment
553
+
554
+ #begin
555
+
556
+
557
+ raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
558
+
559
+
560
+
561
+ get_vms(vmname).each do |machine|
562
+ env =
563
+ {
564
+ :machine => machine,
565
+ :machine_action => SnapshotAction::DELETE,
566
+ :snapshot_id => snapshot_id,
567
+ }
568
+ #
569
+ #
570
+ res = @env.action_runner.run(SnapshotAction,env)
571
+ #
572
+ return res[:delete_snapshot]
573
+ #
574
+ end
575
+ #
576
+ # rescue => e
577
+ # puts e.message
578
+ # # return nil
579
+ # end
580
+
581
+ end
582
+
583
+
584
+
406
585
  ################################################################
407
586
  ############ VIRTUAL MACHINE SNAPSHOT RESTORE METHOD #############
408
587
  ################################################################
409
588
  def self.vm_snapshot_restore(vmname,snapshot_id)
410
- ensure_environment
589
+ command_block = Proc.new {
590
+ #ensure_environment
411
591
 
412
- begin
413
-
414
- get_vms(vmname).each do |machine|
592
+ raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
593
+
594
+ restore_results = {}
595
+
596
+
597
+ get_vms(vmname).each do |machine|
598
+
599
+
415
600
  prev_state=machine.state.id
416
601
  #First, ensure that the machine is in a proper state
417
602
  #to restore the snapshot (save, poweroff)
@@ -431,14 +616,14 @@ module Vagrant
431
616
  #Now restore the vm to the previous state if running
432
617
  machine.action(:up) if prev_state==:running
433
618
 
434
- return res[:restore_result]
435
-
619
+ restore_results[machine.name.to_sym]=res[:restore_result]
436
620
  end
437
-
438
- rescue => e
439
- puts e.message
440
- # return nil
441
- end
621
+
622
+ restore_results
623
+
624
+
625
+ }
626
+ method("execute_queued").call(&command_block);
442
627
 
443
628
  end
444
629
 
@@ -448,29 +633,32 @@ module Vagrant
448
633
  ################## VIRTUAL MACHINE PROVISION METHOD ##################
449
634
  ################################################################
450
635
  def self.vm_provision(vmname)
451
- ensure_environment
452
-
453
- machine_names = []
454
-
455
-
456
- begin
636
+ #ensure_environment
637
+ command_block = Proc.new {
638
+ machine_names = []
639
+
640
+ # Por ahora no dejo que el vmname esté vacío para realizar la operación sobre todas las vm
641
+ raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
642
+ #begin
643
+
644
+ #Provisioning
645
+ get_vms(vmname).each do |machine|
646
+ machine_names << machine.name
647
+ machine.action(:provision)
648
+ end
649
+
650
+
651
+
652
+ machine_names
653
+ }
654
+
655
+ method("execute_queued").call(&command_block);
656
+
457
657
 
458
- #Provisioning
459
- get_vms(vmname).each do |machine|
460
- machine_names << machine.name
461
- machine.action(:provision)
462
- end
463
-
658
+ end
659
+
464
660
 
465
-
466
- machine_names
467
661
 
468
- rescue => e
469
- puts e.message
470
- # return nil
471
- end
472
-
473
- end
474
662
 
475
663
 
476
664
  ################################################################
@@ -484,7 +672,7 @@ module Vagrant
484
672
  return nil if vmname.empty?
485
673
 
486
674
 
487
- begin
675
+ #begin
488
676
  info = Array.new
489
677
  get_vms(vmname).each do |machine|
490
678
  info << machine.ssh_info
@@ -492,10 +680,10 @@ module Vagrant
492
680
 
493
681
  info[0]
494
682
 
495
- rescue => e
496
- puts e.message
683
+ # rescue => e
684
+ # puts e.message
497
685
  # return nil
498
- end
686
+ #end
499
687
 
500
688
  end
501
689
 
@@ -545,25 +733,76 @@ module Vagrant
545
733
 
546
734
  end
547
735
 
548
-
736
+ ################################################################
737
+ ################### NODE PASSWORD CHANGE ###################
738
+ ################################################################
739
+ def self.password_change(new_password)
740
+ ensure_environment
741
+
742
+ @db.node_password_set(new_password,true)
743
+ true
744
+ end
549
745
 
550
746
  ################################################################
551
747
  ################# BACKUP LOG METHOD ###############
552
748
  ################################################################
553
- def self.backup_log(vmname)
749
+ #FIXME No está controlado el que el parámetro sea nil
750
+ def self.backup_log(vmname=nil)
554
751
  ensure_environment
555
752
 
556
- begin
753
+ #begin
557
754
 
558
755
  @db.get_backup_log_entries(vmname)
559
756
 
560
- rescue => e
561
- puts e.message
562
- end
757
+ # rescue => e
758
+ # puts e.message
759
+ # end
563
760
 
564
761
  end
565
762
 
566
763
 
764
+ ################################################################
765
+ ###################### CONFIG SHOW METHOD #####################
766
+ ################################################################
767
+ def self.config_show
768
+ ensure_environment
769
+
770
+ file = @env.root_path+"Vagrantfile"
771
+ end
772
+
773
+ ################################################################
774
+ ###################### CONFIG UPLOAD METHOD #####################
775
+ ################################################################
776
+ def self.config_upload(cfile)
777
+ ensure_environment
778
+
779
+ f = File.new(@env.root_path+"Vagrantfile", "w")
780
+ f.write(cfile)
781
+ f.close
782
+
783
+ true
784
+ end
785
+
786
+
787
+ def self.operation_queued(id)
788
+ ensure_environment
789
+ result = @db.get_queued_process_result(id)
790
+
791
+ raise RestException.new(404,"The operation ID: #{id} not found") if result.empty?
792
+
793
+ result.first
794
+ end
795
+
796
+ def self.operation_queued_last
797
+ ensure_environment
798
+
799
+ @db.get_queued_last
800
+
801
+ end
802
+
803
+
804
+
805
+
567
806
  ################################################################
568
807
  ####################### PRIVATE METHODS #######################
569
808
  ################################################################
@@ -585,7 +824,7 @@ module Vagrant
585
824
  opts = {}
586
825
  @env = Vagrant::Environment.new(opts)
587
826
  @db = DB::DBManager.new(@env.data_dir) if (!@db)
588
-
827
+ @pw = PwManager.new(@db) if (!@pw)
589
828
  end
590
829
 
591
830
  #FIXME REVISAR Y MEJORAR, LO HE HECHO DEPRISA PERO SE