vagrant-node 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/vagrant-node/apidesc.rb
CHANGED
@@ -4,9 +4,17 @@ module RestRoutes
|
|
4
4
|
|
5
5
|
class RouteManager
|
6
6
|
|
7
|
+
def self.node_info_route
|
8
|
+
NODE_INFO
|
9
|
+
end
|
10
|
+
|
7
11
|
def self.box_list_route
|
8
12
|
BOX_LIST_ROUTE
|
9
13
|
end
|
14
|
+
|
15
|
+
def self.box_download_route
|
16
|
+
BOX_DOWNLOAD_ROUTE
|
17
|
+
end
|
10
18
|
|
11
19
|
def self.box_delete_route
|
12
20
|
BOX_DELETE_ROUTE
|
@@ -37,8 +45,8 @@ module RestRoutes
|
|
37
45
|
end
|
38
46
|
|
39
47
|
def self.vm_add_route
|
40
|
-
|
41
|
-
|
48
|
+
VM_ADD_ROUTE
|
49
|
+
end
|
42
50
|
|
43
51
|
def self.vm_status_route
|
44
52
|
VM_STATUS_ROUTE
|
@@ -69,12 +77,12 @@ module RestRoutes
|
|
69
77
|
end
|
70
78
|
|
71
79
|
def self.vm_snapshot_delete_route
|
72
|
-
|
73
|
-
|
80
|
+
VM_SNAPSHOT_DELETE_ROUTE
|
81
|
+
end
|
74
82
|
|
75
83
|
def self.vm_delete_route
|
76
|
-
|
77
|
-
|
84
|
+
VM_DELETE_ROUTE
|
85
|
+
end
|
78
86
|
|
79
87
|
def self.vm_snapshot_restore_route
|
80
88
|
VM_SNAPSHOT_RESTORE_ROUTE
|
@@ -85,10 +93,12 @@ module RestRoutes
|
|
85
93
|
end
|
86
94
|
|
87
95
|
def self.node_password_change_route
|
88
|
-
|
89
|
-
|
90
|
-
|
96
|
+
NODE_PASSWORD_CHANGE
|
97
|
+
end
|
91
98
|
|
99
|
+
def self.vm_info_route
|
100
|
+
VM_INFO_ROUTE
|
101
|
+
end
|
92
102
|
|
93
103
|
def self.vm_backup_log_route
|
94
104
|
VM_BACKUP_LOG_ROUTE
|
@@ -96,12 +106,12 @@ module RestRoutes
|
|
96
106
|
|
97
107
|
|
98
108
|
def self.config_show_route
|
99
|
-
|
100
|
-
|
109
|
+
NODE_CONFIG_SHOW_ROUTE
|
110
|
+
end
|
101
111
|
|
102
|
-
|
103
|
-
|
104
|
-
|
112
|
+
def self.config_upload_route
|
113
|
+
NODE_CONFIG_UPLOAD_ROUTE
|
114
|
+
end
|
105
115
|
|
106
116
|
|
107
117
|
def self.login_route
|
@@ -113,12 +123,18 @@ module RestRoutes
|
|
113
123
|
end
|
114
124
|
|
115
125
|
def self.node_queue_last_route
|
116
|
-
|
117
|
-
|
118
|
-
|
126
|
+
NODE_QUEUE_LAST_ROUTE
|
127
|
+
end
|
119
128
|
|
120
129
|
|
130
|
+
|
131
|
+
def self.node_info_url(host,port)
|
132
|
+
"http://#{host}:#{port}#{node_info_route}"
|
133
|
+
end
|
121
134
|
|
135
|
+
def self.box_download_url(host,port)
|
136
|
+
"http://#{host}:#{port}#{box_download_route}"
|
137
|
+
end
|
122
138
|
|
123
139
|
def self.box_list_url(host,port)
|
124
140
|
"http://#{host}:#{port}#{box_list_route}"
|
@@ -145,11 +161,12 @@ module RestRoutes
|
|
145
161
|
url="http://#{host}:#{port}#{url}"
|
146
162
|
end
|
147
163
|
|
148
|
-
|
149
|
-
|
150
|
-
|
164
|
+
def self.node_queue_last_url(host,port)
|
165
|
+
"http://#{host}:#{port}#{node_queue_last_route}"
|
166
|
+
end
|
151
167
|
|
152
168
|
def self.login_url(host,port)
|
169
|
+
|
153
170
|
"http://#{host}:#{port}#{login_route}"
|
154
171
|
end
|
155
172
|
|
@@ -182,7 +199,12 @@ module RestRoutes
|
|
182
199
|
end
|
183
200
|
|
184
201
|
|
185
|
-
|
202
|
+
def self.vm_info_url(host,port,vmname)
|
203
|
+
url="http://#{host}:#{port}#{vm_info_route}"
|
204
|
+
url=String.new(vm_info_route)
|
205
|
+
url[":vm"]=vmname
|
206
|
+
url="http://#{host}:#{port}#{url}"
|
207
|
+
end
|
186
208
|
|
187
209
|
def self.vm_status_url(host,port,vmname=nil)
|
188
210
|
url="http://#{host}:#{port}#{vm_status_all_route}"
|
@@ -285,8 +307,11 @@ module RestRoutes
|
|
285
307
|
|
286
308
|
private
|
287
309
|
BOX_LIST_ROUTE = "/api/box/list"
|
310
|
+
BOX_DOWNLOAD_ROUTE = "/api/box/download"
|
288
311
|
BOX_DELETE_ROUTE = "/api/box/:box/:provider/delete"
|
289
312
|
BOX_ADD_ROUTE = "/api/box/add"
|
313
|
+
|
314
|
+
NODE_INFO = "/api/info"
|
290
315
|
|
291
316
|
VM_UP_ROUTE = "/api/vm/up"
|
292
317
|
VM_HALT_ROUTE = "/api/vm/halt"
|
@@ -298,6 +323,7 @@ module RestRoutes
|
|
298
323
|
VM_PROVISION_ROUTE = "/api/vm/provision"
|
299
324
|
VM_STATUS_ALL_ROUTE = "/api/vm/status"
|
300
325
|
VM_STATUS_ROUTE = "/api/vm/:vm/status"
|
326
|
+
VM_INFO_ROUTE = "/api/vm/:vm/info"
|
301
327
|
SSH_CONFIG_ROUTE = "/api/vm/:vm/sshconfig"
|
302
328
|
|
303
329
|
SNAPSHOTS_ALL_ROUTE = "/api/vm/snapshots"
|
@@ -1,13 +1,25 @@
|
|
1
1
|
|
2
2
|
require 'vagrant'
|
3
3
|
require 'vagrant-node/actions/snapshot'
|
4
|
+
require 'vagrant-node/actions/boxadd'
|
4
5
|
require 'vagrant-node/dbmanager'
|
5
6
|
require 'vagrant-node/pwmanager'
|
6
7
|
require 'vagrant-node/exceptions.rb'
|
7
8
|
require 'vagrant-node/configmanager'
|
9
|
+
require 'vagrant-node/obmanager'
|
10
|
+
require 'usagewatch'
|
11
|
+
require "sys/cpu"
|
12
|
+
require 'facter'
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
8
17
|
|
9
18
|
|
10
19
|
module Vagrant
|
20
|
+
|
21
|
+
|
22
|
+
|
11
23
|
module Node
|
12
24
|
|
13
25
|
|
@@ -15,8 +27,9 @@ module Vagrant
|
|
15
27
|
class ClientController
|
16
28
|
|
17
29
|
|
18
|
-
def self.execute_queued
|
30
|
+
def self.execute_queued
|
19
31
|
ensure_environment
|
32
|
+
|
20
33
|
#Generating a random identifier for process
|
21
34
|
rpid=rand(1000000)
|
22
35
|
|
@@ -26,17 +39,18 @@ module Vagrant
|
|
26
39
|
res = yield
|
27
40
|
@db.set_queued_process_result(rpid,res.to_json)
|
28
41
|
|
29
|
-
rescue Exception => e
|
42
|
+
rescue Exception => e
|
30
43
|
@db.set_queued_process_error(rpid,e)
|
31
44
|
end
|
32
45
|
end
|
46
|
+
|
33
47
|
rpid
|
34
48
|
end
|
35
49
|
|
36
50
|
def self.send_challenge
|
37
51
|
challenge = SecureRandom.urlsafe_base64(nil, false)
|
38
52
|
cookie = SecureRandom.urlsafe_base64(nil, false)
|
39
|
-
|
53
|
+
|
40
54
|
|
41
55
|
{:cookie => cookie, :challenge => challenge}
|
42
56
|
end
|
@@ -46,7 +60,69 @@ module Vagrant
|
|
46
60
|
|
47
61
|
@pw.authorized?(token,challenge)
|
48
62
|
end
|
63
|
+
|
64
|
+
################################################################
|
65
|
+
####################### NODE INFO (CPU,MEMORY) ################
|
66
|
+
################################################################
|
67
|
+
def self.nodeinfo
|
68
|
+
|
69
|
+
|
70
|
+
usw = Usagewatch
|
71
|
+
|
72
|
+
|
73
|
+
Facter.loadfacts
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
result=Hash[Facter.to_hash.map{|(k,v)| [k.to_sym,v]}]
|
78
|
+
|
79
|
+
result[:cpuaverage] = Sys::CPU.load_avg;
|
80
|
+
result[:diskusage] = usw.uw_diskused
|
81
|
+
|
82
|
+
result
|
83
|
+
|
84
|
+
|
85
|
+
end
|
49
86
|
|
87
|
+
################################################################
|
88
|
+
####################### BOX DOWNLOADS METHOD ##################
|
89
|
+
################################################################
|
90
|
+
def self.listdownloadboxes
|
91
|
+
|
92
|
+
|
93
|
+
ensure_environment
|
94
|
+
|
95
|
+
downloads = @db.get_box_download
|
96
|
+
|
97
|
+
|
98
|
+
fdownloads = Array.new
|
99
|
+
downloads.each do |row|
|
100
|
+
fdownloads << {"box_name" => row["box_name"],"box_url" => row["box_url"],"box_progress" => row["download_progress"],"box_remaining" => row["download_remaining"],"download_status" => row["download_status"]}
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
fdownloads
|
106
|
+
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
################################################################
|
111
|
+
################# CLEAR BOX DOWNLOADS METHOD ##################
|
112
|
+
################################################################
|
113
|
+
def self.cleardownloadboxes
|
114
|
+
|
115
|
+
|
116
|
+
ensure_environment
|
117
|
+
|
118
|
+
@db.clear_box_downloads
|
119
|
+
|
120
|
+
|
121
|
+
true
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
50
126
|
################################################################
|
51
127
|
####################### BOX LIST METHOD #######################
|
52
128
|
################################################################
|
@@ -74,15 +150,28 @@ module Vagrant
|
|
74
150
|
def self.box_delete(box,provider)
|
75
151
|
|
76
152
|
ensure_environment
|
153
|
+
|
154
|
+
boxes = []
|
155
|
+
|
77
156
|
|
78
|
-
boxes = []
|
79
157
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
158
|
+
bbox = @env.boxes.find(box,provider.to_sym)
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
if (bbox)
|
163
|
+
get_vms("").each do |machine|
|
164
|
+
if (!machine.box.nil? && machine.box.name==box)
|
165
|
+
raise RestException.new(500,"The box can't be deleted because the virtual machine '#{machine.name.to_s}' is using it")
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
boxes << bbox.name
|
171
|
+
bbox.destroy!
|
172
|
+
else
|
173
|
+
raise RestException.new(404,"The box '#{box}' does not exist")
|
174
|
+
end
|
86
175
|
|
87
176
|
boxes
|
88
177
|
|
@@ -92,6 +181,16 @@ module Vagrant
|
|
92
181
|
######################## BOX ADD METHOD #######################
|
93
182
|
################################################################
|
94
183
|
def self.box_add(box,url,user="guest",pass="--no-pass")
|
184
|
+
|
185
|
+
@env.boxes.all.each do |box_name,provider|
|
186
|
+
|
187
|
+
if box_name==box
|
188
|
+
raise RestException.new(500,"There is a box with the same name")
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
|
95
194
|
command_block = Proc.new {
|
96
195
|
#ensure_environment
|
97
196
|
|
@@ -196,21 +295,35 @@ module Vagrant
|
|
196
295
|
#
|
197
296
|
# else
|
198
297
|
|
298
|
+
|
299
|
+
copy_db = @db.clone
|
199
300
|
|
200
|
-
|
301
|
+
|
302
|
+
|
201
303
|
boxes <<{:name=>box}
|
202
304
|
# FIXME Ver qué poner en los parámetros de la llamada
|
203
305
|
provider=nil
|
204
306
|
force = true # Always overwrite box if exists
|
205
307
|
insecure = true #Don't validate SSL certs
|
206
308
|
#Calling original box add action
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
309
|
+
|
310
|
+
|
311
|
+
@env.action_runner.run(BoxAddAction, {
|
312
|
+
:box_name => box,
|
313
|
+
:box_provider => provider,
|
314
|
+
:box_url => url,
|
315
|
+
:box_force => force,
|
316
|
+
:box_download_insecure => insecure,
|
317
|
+
:db => copy_db,
|
318
|
+
})
|
319
|
+
|
320
|
+
# @env.action_runner.run(Vagrant::Action.action_box_add, {
|
321
|
+
# :box_name => box,
|
322
|
+
# :box_provider => provider,
|
323
|
+
# :box_url => url,
|
324
|
+
# :box_force => force,
|
325
|
+
# :box_download_insecure => insecure,
|
326
|
+
# })
|
214
327
|
|
215
328
|
# end
|
216
329
|
|
@@ -219,14 +332,15 @@ module Vagrant
|
|
219
332
|
|
220
333
|
|
221
334
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
335
|
+
boxes
|
336
|
+
|
337
|
+
rescue =>e
|
338
|
+
puts e.message
|
339
|
+
end
|
227
340
|
|
228
341
|
}
|
229
|
-
|
342
|
+
|
343
|
+
method("execute_queued").call(&command_block);
|
230
344
|
|
231
345
|
end
|
232
346
|
|
@@ -235,42 +349,61 @@ module Vagrant
|
|
235
349
|
################################################################
|
236
350
|
################## VIRTUAL MACHINE UP METHOD ##################
|
237
351
|
################################################################
|
238
|
-
def self.vm_up(vmname)
|
239
|
-
|
240
|
-
#ensure_environment
|
241
|
-
|
242
|
-
machine_names = []
|
243
|
-
|
244
|
-
#begin
|
245
|
-
|
246
|
-
options = {}
|
247
|
-
options[:parallel] = true
|
352
|
+
def self.vm_up(vmname)
|
353
|
+
|
248
354
|
|
249
|
-
|
250
|
-
|
251
|
-
get_vms(vmname).each do |machine|
|
252
|
-
batch.action(machine, :up, options)
|
253
|
-
machine_names << {"vmname" => machine.name.to_s,
|
254
|
-
"status" => "running"}
|
255
|
-
end
|
256
|
-
end
|
355
|
+
|
356
|
+
command_block = Proc.new {
|
257
357
|
|
358
|
+
machine_names = []
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
begin
|
258
363
|
|
259
|
-
|
260
|
-
|
364
|
+
|
365
|
+
options = {}
|
366
|
+
options[:parallel] = true
|
367
|
+
|
368
|
+
#Launching machines
|
369
|
+
@env.batch(options[:parallel]) do |batch|
|
370
|
+
|
371
|
+
get_vms(vmname).each do |machine|
|
372
|
+
|
373
|
+
batch.action(machine, :up, options)
|
374
|
+
|
375
|
+
machine_names << {"vmname" => machine.name.to_s,
|
376
|
+
"provider" => machine.provider_name.to_s,
|
377
|
+
"status" => "running"}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
|
385
|
+
|
386
|
+
machine_names
|
387
|
+
|
388
|
+
rescue Exception => e
|
389
|
+
|
390
|
+
aux=get_vms(vmname)
|
391
|
+
machine=aux[0]
|
392
|
+
|
393
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?)
|
394
|
+
raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.message) if (!machine.nil?)
|
395
|
+
end
|
396
|
+
|
261
397
|
|
262
|
-
|
398
|
+
}
|
399
|
+
|
400
|
+
method("execute_queued").call(&command_block)
|
263
401
|
|
264
|
-
|
265
|
-
# puts "BOX NOT FOUND"
|
266
|
-
# rescue => e
|
267
|
-
# pp e
|
268
|
-
# puts e.message
|
269
|
-
# raise RestException.new(404,e.message)
|
270
|
-
# end
|
402
|
+
|
271
403
|
|
272
404
|
end
|
273
405
|
|
406
|
+
|
274
407
|
|
275
408
|
|
276
409
|
|
@@ -286,15 +419,19 @@ module Vagrant
|
|
286
419
|
f.write(config)
|
287
420
|
f.close
|
288
421
|
|
289
|
-
|
422
|
+
|
290
423
|
cm = ConfigManager.new(@env.root_path+"Vagrantfile")
|
424
|
+
|
425
|
+
|
291
426
|
cmtmp = ConfigManager.new(path)
|
292
427
|
|
428
|
+
|
293
429
|
|
294
430
|
current_vms = @env.machine_names
|
295
431
|
|
296
|
-
|
297
|
-
|
432
|
+
|
433
|
+
|
434
|
+
cmtmp.get_vm_names.each do |key|
|
298
435
|
if current_vms.include?(key)
|
299
436
|
raise RestException.new(406,"There is a remote VM with the same name: \"#{key}\"") if rename=="false"
|
300
437
|
cmtmp.rename_vm(key,"#{key}_1")
|
@@ -355,195 +492,276 @@ module Vagrant
|
|
355
492
|
|
356
493
|
end
|
357
494
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
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);
|
379
|
-
|
380
|
-
#rescue => e
|
381
|
-
# return nil
|
382
|
-
#end
|
383
|
-
|
384
|
-
end
|
495
|
+
################################################################
|
496
|
+
################# VIRTUAL MACHINE HALT METHOD #################
|
497
|
+
################################################################
|
498
|
+
def self.vm_halt(vmname,force)
|
385
499
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
500
|
+
force=(force=="true")?true:false;
|
501
|
+
|
502
|
+
command_block = Proc.new {
|
503
|
+
|
504
|
+
begin
|
505
|
+
machine_names = []
|
506
|
+
get_vms(vmname).each do |machine|
|
507
|
+
machine.action(:halt, :force_halt => force)
|
508
|
+
machine_names << {"vmname" => machine.name.to_s,
|
509
|
+
"provider" => machine.provider_name.to_s,
|
510
|
+
"status" => machine.state.short_description}
|
511
|
+
end
|
512
|
+
|
513
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
|
514
|
+
|
515
|
+
machine_names
|
516
|
+
|
517
|
+
rescue Exception => e
|
518
|
+
aux=get_vms(vmname)
|
519
|
+
machine=aux[0]
|
520
|
+
|
521
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?)
|
522
|
+
raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.message) if (!machine.nil?)
|
523
|
+
end
|
524
|
+
|
391
525
|
|
526
|
+
}
|
392
527
|
|
393
|
-
|
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
|
528
|
+
method("execute_queued").call(&command_block);
|
402
529
|
|
530
|
+
#rescue => e
|
531
|
+
# return nil
|
532
|
+
#end
|
403
533
|
|
404
|
-
|
405
|
-
|
406
|
-
|
534
|
+
end
|
535
|
+
|
536
|
+
################################################################
|
537
|
+
################# VIRTUAL MACHINE INFO METHOD ###############
|
538
|
+
################################################################
|
539
|
+
def self.vm_info(vmname)
|
540
|
+
raise RestException.new(500,"The VM Name can't be emtpy") if vmname.empty?
|
541
|
+
|
542
|
+
ensure_environment
|
543
|
+
|
544
|
+
#execute("snapshot",self.uuid,"showvminfo",name)
|
545
|
+
|
546
|
+
machines=get_vms(vmname)
|
407
547
|
|
548
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machines.empty?)
|
549
|
+
|
550
|
+
info = Hash.new
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
if (machines[0].id!=nil)
|
555
|
+
machines[0].provider.driver.execute("showvminfo",machines[0].id,"--machinereadable").split("\n").each do |line|
|
556
|
+
if (line =~ /^(.*?)=\"(.*?)\"$/) || (line =~ /^(.*?)=(.*?)$/)
|
557
|
+
info[$1]=$2
|
558
|
+
end
|
559
|
+
end
|
408
560
|
end
|
409
561
|
|
410
|
-
################################################################
|
411
|
-
################## VIRTUAL MACHINE SUSPEND METHOD ##################
|
412
|
-
################################################################
|
413
|
-
def self.vm_suspend(vmname)
|
414
|
-
command_block = Proc.new {
|
415
|
-
#ensure_environment
|
416
562
|
|
417
|
-
|
563
|
+
info
|
564
|
+
|
565
|
+
end
|
566
|
+
|
567
|
+
|
568
|
+
################################################################
|
569
|
+
################# VIRTUAL MACHINE STATUS METHOD ###############
|
570
|
+
################################################################
|
571
|
+
def self.vm_status(vmname=nil,verbose=true)
|
572
|
+
ensure_environment
|
418
573
|
|
419
|
-
|
420
|
-
|
574
|
+
|
575
|
+
begin
|
576
|
+
status = Array.new
|
577
|
+
if (verbose==true || verbose=="true")
|
421
578
|
|
422
|
-
#Suspendiing machines
|
423
579
|
get_vms(vmname).each do |machine|
|
424
|
-
machine.action(:suspend)
|
425
|
-
machine_names << {"vmname" => machine.name.to_s,
|
426
|
-
"status" => machine.state.short_description}
|
427
|
-
end
|
428
580
|
|
581
|
+
status << {"name" => machine.name.to_s,
|
582
|
+
"status" => machine.state.short_description,
|
583
|
+
"provider" => machine.provider_name}
|
584
|
+
end
|
585
|
+
else
|
586
|
+
@env.machine_names.each do |machine|
|
587
|
+
status << {"name" => machine.to_s}
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
429
591
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
method("execute_queued").call(&command_block);
|
435
|
-
|
592
|
+
status
|
593
|
+
rescue Exception => e
|
594
|
+
raise e
|
436
595
|
end
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
end
|
600
|
+
|
601
|
+
################################################################
|
602
|
+
################## VIRTUAL MACHINE SUSPEND METHOD ##################
|
603
|
+
################################################################
|
604
|
+
def self.vm_suspend(vmname)
|
605
|
+
command_block = Proc.new {
|
606
|
+
#ensure_environment
|
437
607
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
608
|
+
begin
|
609
|
+
|
610
|
+
machine_names = []
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
#Suspendiing machines
|
616
|
+
get_vms(vmname).each do |machine|
|
617
|
+
machine.action(:suspend)
|
618
|
+
machine_names << {"vmname" => machine.name.to_s,
|
619
|
+
"provider" => machine.provider_name.to_s,
|
620
|
+
"status" => machine.state.short_description}
|
621
|
+
end
|
622
|
+
|
623
|
+
|
624
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
|
625
|
+
|
626
|
+
machine_names
|
627
|
+
|
628
|
+
rescue Exception => e
|
629
|
+
aux=get_vms(vmname)
|
630
|
+
machine=aux[0]
|
631
|
+
|
632
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?)
|
633
|
+
raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.message) if (!machine.nil?)
|
634
|
+
end
|
635
|
+
|
636
|
+
|
637
|
+
}
|
638
|
+
|
639
|
+
method("execute_queued").call(&command_block);
|
444
640
|
|
445
|
-
|
641
|
+
end
|
642
|
+
|
643
|
+
################################################################
|
644
|
+
################## VIRTUAL MACHINE RESUME METHOD ##################
|
645
|
+
################################################################
|
646
|
+
def self.vm_resume(vmname)
|
647
|
+
command_block = Proc.new {
|
648
|
+
#ensure_environment
|
649
|
+
begin
|
650
|
+
|
651
|
+
machine_names = []
|
446
652
|
#Launching machines
|
447
653
|
|
448
654
|
get_vms(vmname).each do |machine|
|
449
655
|
machine.action(:resume)
|
450
656
|
machine_names << {"vmname" => machine.name.to_s,
|
451
|
-
|
657
|
+
"provider" => machine.provider_name.to_s,
|
658
|
+
"status" => machine.state.short_description}
|
452
659
|
end
|
453
660
|
|
454
|
-
|
661
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
|
455
662
|
|
456
663
|
machine_names
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
664
|
+
|
665
|
+
rescue Exception => e
|
666
|
+
aux=get_vms(vmname)
|
667
|
+
machine=aux[0]
|
668
|
+
|
669
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?)
|
670
|
+
raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.message) if (!machine.nil?)
|
671
|
+
end
|
672
|
+
}
|
461
673
|
|
462
|
-
|
674
|
+
method("execute_queued").call(&command_block);
|
463
675
|
|
464
|
-
################################################################
|
465
|
-
############ VIRTUAL MACHINE SNAPSHOT LIST METHOD #############
|
466
|
-
################################################################
|
467
|
-
def self.vm_snapshots(vmname=nil)
|
468
|
-
ensure_environment
|
469
|
-
|
470
|
-
#begin
|
471
|
-
|
472
|
-
snapshots = {}
|
473
|
-
|
474
|
-
get_vms(vmname).each do |machine|
|
475
|
-
|
476
|
-
env =
|
477
|
-
{
|
478
|
-
:machine => machine,
|
479
|
-
:machine_action => SnapshotAction::LIST
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
res = @env.action_runner.run(SnapshotAction,env)
|
484
|
-
|
485
|
-
snapshots[machine.name.to_sym]=res[:snapshots_list]
|
486
|
-
|
487
|
-
end
|
488
|
-
|
489
|
-
|
490
|
-
snapshots
|
491
|
-
|
492
|
-
# rescue => e
|
493
|
-
# puts e.message
|
494
|
-
# # return nil
|
495
|
-
# end
|
496
|
-
|
497
|
-
end
|
498
676
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
677
|
+
end
|
678
|
+
|
679
|
+
################################################################
|
680
|
+
############ VIRTUAL MACHINE SNAPSHOT LIST METHOD #############
|
681
|
+
################################################################
|
682
|
+
def self.vm_snapshots(vmname=nil)
|
683
|
+
ensure_environment
|
684
|
+
|
685
|
+
#begin
|
686
|
+
|
687
|
+
snapshots = {}
|
688
|
+
|
689
|
+
get_vms(vmname).each do |machine|
|
506
690
|
|
507
|
-
|
691
|
+
env =
|
692
|
+
{
|
693
|
+
:machine => machine,
|
694
|
+
:machine_action => SnapshotAction::LIST
|
695
|
+
}
|
508
696
|
|
509
697
|
|
510
|
-
|
511
|
-
raise RestException.new(404,"Virtual Machine not found") if (machine.empty?)
|
698
|
+
res = @env.action_runner.run(SnapshotAction,env)
|
512
699
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
700
|
+
snapshots[machine.name.to_sym]=res[:snapshots_list]
|
701
|
+
|
702
|
+
end
|
703
|
+
|
704
|
+
|
705
|
+
snapshots
|
706
|
+
|
707
|
+
# rescue => e
|
708
|
+
# puts e.message
|
709
|
+
# # return nil
|
710
|
+
# end
|
711
|
+
|
712
|
+
end
|
713
|
+
|
714
|
+
################################################################
|
715
|
+
############ VIRTUAL MACHINE SNAPSHOT TAKE METHOD #############
|
716
|
+
################################################################
|
717
|
+
def self.vm_snapshot_take(vmname,name,desc=" ")
|
718
|
+
command_block = Proc.new {
|
719
|
+
#ensure_environment
|
720
|
+
|
721
|
+
|
722
|
+
raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
|
723
|
+
|
724
|
+
|
725
|
+
machine = get_vms(vmname)
|
726
|
+
raise RestException.new(404,"Virtual Machine not found") if (machine.empty?)
|
727
|
+
|
728
|
+
env =
|
729
|
+
{
|
730
|
+
:machine => machine.first,
|
731
|
+
:machine_action => SnapshotAction::TAKE,
|
732
|
+
:snapshot_name => name,
|
733
|
+
:snapshot_desc => desc
|
734
|
+
}
|
735
|
+
|
736
|
+
res = @env.action_runner.run(SnapshotAction,env)
|
737
|
+
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
res[:last_snapshot]
|
742
|
+
|
743
|
+
|
744
|
+
# get_vms(vmname).each do |machine|
|
745
|
+
# env =
|
746
|
+
# {
|
747
|
+
# :machine => machine,
|
748
|
+
# :machine_action => SnapshotAction::TAKE,
|
749
|
+
# :snapshot_name => name,
|
750
|
+
# :snapshot_desc => desc
|
751
|
+
# }
|
534
752
|
#
|
535
|
-
|
753
|
+
# res = @env.action_runner.run(SnapshotAction,env)
|
536
754
|
#
|
537
|
-
|
755
|
+
# return res[:last_snapshot]
|
538
756
|
#
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
}
|
543
|
-
|
544
|
-
method("execute_queued").call(&command_block);
|
757
|
+
# end
|
545
758
|
|
546
|
-
|
759
|
+
|
760
|
+
}
|
761
|
+
|
762
|
+
method("execute_queued").call(&command_block);
|
763
|
+
|
764
|
+
end
|
547
765
|
|
548
766
|
################################################################
|
549
767
|
############ VIRTUAL MACHINE SNAPSHOT DELETE METHOD #############
|
@@ -581,196 +799,198 @@ module Vagrant
|
|
581
799
|
end
|
582
800
|
|
583
801
|
|
802
|
+
|
803
|
+
################################################################
|
804
|
+
############ VIRTUAL MACHINE SNAPSHOT RESTORE METHOD #############
|
805
|
+
################################################################
|
806
|
+
def self.vm_snapshot_restore(vmname,snapshot_id)
|
807
|
+
command_block = Proc.new {
|
808
|
+
#ensure_environment
|
584
809
|
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
810
|
+
raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
|
811
|
+
|
812
|
+
restore_results = {}
|
813
|
+
|
814
|
+
|
815
|
+
get_vms(vmname).each do |machine|
|
591
816
|
|
592
|
-
raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
|
593
817
|
|
594
|
-
|
818
|
+
prev_state=machine.state.id
|
819
|
+
#First, ensure that the machine is in a proper state
|
820
|
+
#to restore the snapshot (save, poweroff)
|
821
|
+
machine.action(:suspend) if prev_state==:running
|
595
822
|
|
596
|
-
|
597
|
-
|
823
|
+
#Now the machine is ready for restoration
|
824
|
+
env =
|
825
|
+
{
|
826
|
+
:machine => machine,
|
827
|
+
:machine_action => SnapshotAction::RESTORE,
|
828
|
+
:snapshot_id => snapshot_id
|
829
|
+
}
|
598
830
|
|
599
|
-
|
600
|
-
prev_state=machine.state.id
|
601
|
-
#First, ensure that the machine is in a proper state
|
602
|
-
#to restore the snapshot (save, poweroff)
|
603
|
-
machine.action(:suspend) if prev_state==:running
|
604
|
-
|
605
|
-
#Now the machine is ready for restoration
|
606
|
-
env =
|
607
|
-
{
|
608
|
-
:machine => machine,
|
609
|
-
:machine_action => SnapshotAction::RESTORE,
|
610
|
-
:snapshot_id => snapshot_id
|
611
|
-
}
|
612
|
-
|
613
|
-
|
614
|
-
res = @env.action_runner.run(SnapshotAction,env)
|
615
|
-
|
616
|
-
#Now restore the vm to the previous state if running
|
617
|
-
machine.action(:up) if prev_state==:running
|
618
|
-
|
619
|
-
restore_results[machine.name.to_sym]=res[:restore_result]
|
620
|
-
end
|
621
831
|
|
622
|
-
|
832
|
+
res = @env.action_runner.run(SnapshotAction,env)
|
623
833
|
|
834
|
+
#Now restore the vm to the previous state if running
|
835
|
+
machine.action(:up) if prev_state==:running
|
624
836
|
|
625
|
-
|
626
|
-
|
837
|
+
restore_results[machine.name.to_sym]=res[:restore_result]
|
838
|
+
end
|
627
839
|
|
628
|
-
|
840
|
+
|
841
|
+
|
842
|
+
restore_results
|
843
|
+
|
844
|
+
|
845
|
+
}
|
846
|
+
method("execute_queued").call(&command_block);
|
847
|
+
|
848
|
+
end
|
629
849
|
|
630
850
|
|
631
851
|
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
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
|
-
}
|
852
|
+
################################################################
|
853
|
+
################## VIRTUAL MACHINE PROVISION METHOD ##################
|
854
|
+
################################################################
|
855
|
+
def self.vm_provision(vmname)
|
856
|
+
#ensure_environment
|
857
|
+
command_block = Proc.new {
|
858
|
+
machine_names = []
|
859
|
+
|
860
|
+
# Por ahora no dejo que el vmname esté vacío para realizar la operación sobre todas las vm
|
861
|
+
raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?)
|
862
|
+
#begin
|
654
863
|
|
655
|
-
|
656
|
-
|
864
|
+
#Provisioning
|
865
|
+
get_vms(vmname).each do |machine|
|
866
|
+
machine_names << machine.name
|
867
|
+
machine.action(:provision)
|
868
|
+
end
|
869
|
+
|
870
|
+
raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
|
657
871
|
|
658
|
-
|
872
|
+
machine_names
|
873
|
+
}
|
874
|
+
|
875
|
+
method("execute_queued").call(&command_block);
|
876
|
+
|
877
|
+
|
878
|
+
end
|
659
879
|
|
660
880
|
|
661
881
|
|
662
882
|
|
663
883
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
884
|
+
################################################################
|
885
|
+
################### VIRTUAL MACHINE SSHCONFIG## ###############
|
886
|
+
################################################################
|
887
|
+
def self.vm_ssh_config(vmname)
|
888
|
+
ensure_environment
|
889
|
+
|
890
|
+
|
891
|
+
#Ensure vmname exists and it is not empty
|
892
|
+
return nil if vmname.empty?
|
669
893
|
|
894
|
+
|
895
|
+
#begin
|
896
|
+
info = Array.new
|
897
|
+
get_vms(vmname).each do |machine|
|
898
|
+
info << machine.ssh_info
|
899
|
+
end
|
670
900
|
|
671
|
-
|
672
|
-
return nil if vmname.empty?
|
673
|
-
|
901
|
+
info[0]
|
674
902
|
|
675
|
-
|
676
|
-
|
677
|
-
get_vms(vmname).each do |machine|
|
678
|
-
info << machine.ssh_info
|
679
|
-
end
|
680
|
-
|
681
|
-
info[0]
|
682
|
-
|
683
|
-
# rescue => e
|
684
|
-
# puts e.message
|
903
|
+
# rescue => e
|
904
|
+
# puts e.message
|
685
905
|
# return nil
|
686
|
-
|
687
|
-
|
688
|
-
end
|
906
|
+
#end
|
689
907
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
908
|
+
end
|
909
|
+
|
910
|
+
################################################################
|
911
|
+
############ VIRTUAL MACHINE BACKUP TAKE METHOD #############
|
912
|
+
################################################################
|
913
|
+
def self.vm_snapshot_take_file(vmname)
|
914
|
+
ensure_environment
|
915
|
+
|
916
|
+
current_machine = nil
|
917
|
+
t = Time.now.strftime "%Y-%m-%d %H:%M:%S"
|
918
|
+
begin
|
919
|
+
|
920
|
+
machines=get_vms(vmname)
|
695
921
|
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
machines=get_vms(vmname)
|
922
|
+
return [404,"Virtual Machine not found"] if machines.empty?
|
923
|
+
|
924
|
+
machines.each do |machine|
|
701
925
|
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
env
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
res
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
return [200,res[:bak_filename]]
|
725
|
-
end
|
926
|
+
current_machine = machine.name.to_s
|
927
|
+
|
928
|
+
env =
|
929
|
+
{
|
930
|
+
:machine => machine,
|
931
|
+
:machine_action => SnapshotAction::BACKUP,
|
932
|
+
:path => @env.data_dir
|
933
|
+
}
|
934
|
+
|
935
|
+
@db.add_backup_log_entry(t,current_machine,BACKUP_IN_PROGRESS)
|
936
|
+
|
937
|
+
res = @env.action_runner.run(SnapshotAction,env)
|
938
|
+
|
939
|
+
if res[:bak_filename] == SnapshotAction::ERROR
|
940
|
+
@db.update_backup_log_entry(t,current_machine,BACKUP_ERROR)
|
941
|
+
return [500,"Internal Error"] if res[:bak_filename] == SnapshotAction::ERROR
|
942
|
+
else
|
943
|
+
@db.update_backup_log_entry(t,current_machine,BACKUP_SUCCESS)
|
944
|
+
return [200,res[:bak_filename]]
|
945
|
+
end
|
946
|
+
|
947
|
+
end
|
726
948
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
@db.update_backup_log_entry(t,current_machine,BACKUP_ERROR)
|
731
|
-
return [500,"Internal Error"]
|
732
|
-
end
|
733
|
-
|
949
|
+
rescue => e
|
950
|
+
@db.update_backup_log_entry(t,current_machine,BACKUP_ERROR)
|
951
|
+
return [500,"Internal Error"]
|
734
952
|
end
|
735
953
|
|
736
|
-
|
954
|
+
end
|
955
|
+
|
956
|
+
################################################################
|
737
957
|
################### NODE PASSWORD CHANGE ###################
|
738
958
|
################################################################
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
959
|
+
def self.password_change(new_password)
|
960
|
+
ensure_environment
|
961
|
+
|
962
|
+
@db.node_password_set(new_password,true)
|
963
|
+
true
|
964
|
+
end
|
965
|
+
|
966
|
+
################################################################
|
967
|
+
################# BACKUP LOG METHOD ###############
|
968
|
+
################################################################
|
969
|
+
#FIXME No está controlado el que el parámetro sea nil
|
970
|
+
def self.backup_log(vmname=nil)
|
971
|
+
ensure_environment
|
745
972
|
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
#FIXME No está controlado el que el parámetro sea nil
|
750
|
-
def self.backup_log(vmname=nil)
|
751
|
-
ensure_environment
|
752
|
-
|
753
|
-
#begin
|
754
|
-
|
755
|
-
@db.get_backup_log_entries(vmname)
|
756
|
-
|
757
|
-
# rescue => e
|
758
|
-
# puts e.message
|
759
|
-
# end
|
973
|
+
#begin
|
974
|
+
|
975
|
+
@db.get_backup_log_entries(vmname)
|
760
976
|
|
761
|
-
|
977
|
+
# rescue => e
|
978
|
+
# puts e.message
|
979
|
+
# end
|
762
980
|
|
981
|
+
end
|
763
982
|
|
764
|
-
|
983
|
+
|
984
|
+
################################################################
|
765
985
|
###################### CONFIG SHOW METHOD #####################
|
766
986
|
################################################################
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
987
|
+
def self.config_show
|
988
|
+
ensure_environment
|
989
|
+
|
990
|
+
file = @env.root_path+"Vagrantfile"
|
991
|
+
end
|
772
992
|
|
773
|
-
|
993
|
+
################################################################
|
774
994
|
###################### CONFIG UPLOAD METHOD #####################
|
775
995
|
################################################################
|
776
996
|
def self.config_upload(cfile)
|
@@ -783,14 +1003,24 @@ module Vagrant
|
|
783
1003
|
true
|
784
1004
|
end
|
785
1005
|
|
786
|
-
|
1006
|
+
################################################################
|
1007
|
+
####################### OPERATION METHODS #######################
|
1008
|
+
################################################################
|
787
1009
|
def self.operation_queued(id)
|
788
1010
|
ensure_environment
|
1011
|
+
|
789
1012
|
result = @db.get_queued_process_result(id)
|
790
1013
|
|
791
|
-
raise RestException.new(404,"The operation ID: #{id} not found") if result.
|
1014
|
+
raise RestException.new(404,"The operation ID: #{id} not found") if (result.size==0)
|
1015
|
+
|
1016
|
+
opres = Array.new
|
1017
|
+
|
1018
|
+
aux=result.first
|
1019
|
+
|
1020
|
+
opres[0]=aux["operation_status"]
|
1021
|
+
opres[1]=aux["operation_result"]
|
792
1022
|
|
793
|
-
|
1023
|
+
opres
|
794
1024
|
end
|
795
1025
|
|
796
1026
|
def self.operation_queued_last
|
@@ -803,69 +1033,82 @@ module Vagrant
|
|
803
1033
|
|
804
1034
|
|
805
1035
|
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
1036
|
+
################################################################
|
1037
|
+
####################### PRIVATE METHODS #######################
|
1038
|
+
################################################################
|
1039
|
+
private
|
1040
|
+
|
1041
|
+
BACKUP_ERROR = "ERROR"
|
1042
|
+
BACKUP_SUCCESS = "OK"
|
1043
|
+
BACKUP_IN_PROGRESS = "IN PROGRESS"
|
1044
|
+
|
1045
|
+
def self.ensure_environment
|
1046
|
+
#Due to the fact that the enviroment data can change
|
1047
|
+
#if we always use a stored value of env we won't be
|
1048
|
+
#able to notice those changes
|
819
1049
|
# if (!@env)
|
820
1050
|
# opts = {}
|
821
1051
|
# @env = Vagrant::Environment.new(opts)
|
822
1052
|
# end
|
823
|
-
|
824
|
-
opts = {}
|
825
|
-
@env = Vagrant::Environment.new(opts)
|
826
|
-
@db = DB::DBManager.new(@env.data_dir) if (!@db)
|
827
|
-
@pw = PwManager.new(@db) if (!@pw)
|
828
|
-
end
|
829
1053
|
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
1054
|
+
|
1055
|
+
|
1056
|
+
@env = ObManager.instance.reload_env
|
1057
|
+
@db = ObManager.instance.dbmanager
|
1058
|
+
@pw = ObManager.instance.pwmanager
|
1059
|
+
|
1060
|
+
#opts = {}
|
1061
|
+
#@env = Vagrant::Environment.new(opts)
|
1062
|
+
#@db = DB::DBManager.new(@env.data_dir) if (!@db)
|
1063
|
+
#@pw = PwManager.new(@db) if (!@pw)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
#FIXME REVISAR Y MEJORAR, LO HE HECHO DEPRISA PERO SE
|
1067
|
+
#PUEDE OPTIMIZAR
|
1068
|
+
def self.get_vms(vmname)
|
1069
|
+
machines = []
|
1070
|
+
provider=@env.default_provider
|
1071
|
+
|
1072
|
+
|
1073
|
+
|
1074
|
+
if (vmname && !vmname.empty?)
|
1075
|
+
#If a machine was specified launch only that machine
|
1076
|
+
name=vmname.to_sym
|
1077
|
+
|
1078
|
+
|
1079
|
+
if (@env.machine_names.index(name)!=nil)
|
1080
|
+
|
1081
|
+
@env.active_machines.each do |active_name, active_provider|
|
1082
|
+
|
1083
|
+
if name==active_name
|
1084
|
+
provider=active_provider
|
1085
|
+
break
|
848
1086
|
end
|
849
|
-
|
1087
|
+
|
850
1088
|
end
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
1089
|
+
machines << @env.machine(name,provider)
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
else
|
1093
|
+
|
1094
|
+
#If no machine was specified launch all
|
1095
|
+
@env.machine_names.each do |machine_name|
|
1096
|
+
@env.active_machines.each do |active_name, active_provider|
|
1097
|
+
if active_name==machine_name
|
1098
|
+
provider=active_provider
|
860
1099
|
|
1100
|
+
break
|
861
1101
|
end
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
machines
|
1102
|
+
|
1103
|
+
end
|
1104
|
+
machines << @env.machine(machine_name,provider)
|
1105
|
+
end
|
867
1106
|
|
868
|
-
end
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
machines
|
1110
|
+
|
1111
|
+
end
|
869
1112
|
|
870
1113
|
end
|
871
1114
|
end
|