vagrant-node 1.1.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,11 +4,11 @@ vagrant-node
4
4
  This plugin allows you to set a computer with a virtual environment, configured with Vagrant, to be controlled and managed remotely. The remote machine must have installed the controller plugin, [Vagrant-NodeMaster](https://github.com/fjsanpedro/vagrant-nodemaster/tree/master/lib/vagrant-nodemaster).
5
5
 
6
6
  With this plugin installed, the Vagrant environment can perform requests, that you usually can execute locally, but commanded by a remote computer. This service is provided through a REST API that this plugin exposes.
7
-
7
+
8
8
  This plugin has been developed in the context of the [Catedra SAES](http://www.catedrasaes.org) of the University of Murcia(Spain).
9
9
 
10
10
  ##Installation
11
- Requires Vagrant 1.2 and libsqlite3-dev
11
+ Requires Vagrant (minimum version 1.2.2) and MySql Server
12
12
 
13
13
  ```bash
14
14
  $ vagrant plugin install vagrant-node
@@ -1,4 +1,4 @@
1
- require 'pp'
1
+ require 'pp'
2
2
  require 'rubygems'
3
3
  require 'vagrant-node/util/downloader'
4
4
  require "vagrant/util/platform"
@@ -11,11 +11,17 @@ module Vagrant
11
11
  @app = app
12
12
  end
13
13
 
14
- def call(env)
14
+ def download_boxes(env)
15
15
  @temp_path = env[:tmp_path].join("box" + Time.now.to_i.to_s)
16
16
 
17
+ result=ObManager.instance.dbmanager.get_box_to_download
18
+
19
+ next_id=result["id"]
20
+
21
+ next_box_name = result["box_name"]
17
22
 
18
- url = env[:box_url]
23
+ url = result["box_url"]
24
+
19
25
  if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i
20
26
  file_path = File.expand_path(url)
21
27
  file_path = Util::Platform.cygwin_windows_path(file_path)
@@ -27,7 +33,7 @@ module Vagrant
27
33
  downloader_options[:insecure] = env[:box_download_insecure]
28
34
  downloader_options[:ui] = env[:ui]
29
35
  downloader_options[:db] = env[:db]
30
- downloader_options[:box_name] = env[:box_name]
36
+ downloader_options[:box_name] = next_box_name
31
37
 
32
38
 
33
39
 
@@ -39,34 +45,29 @@ module Vagrant
39
45
 
40
46
 
41
47
  begin
42
- downloader = Util::Downloader.new(url, @temp_path, downloader_options)
48
+ downloader = Util::Downloader.new(url, @temp_path, downloader_options)
43
49
  downloader.download!
50
+
44
51
  rescue Errors::DownloaderInterrupted
45
52
  # The downloader was interrupted, so just return, because that
46
53
  # means we were interrupted as well.
47
54
  #env[:ui].info(I18n.t("vagrant.actions.box.download.interrupted"))
48
55
  return
49
56
  rescue Errors::DownloaderError => msg
50
- #puts msg.message.split(/\r\n/).inspect.length
51
-
52
- #puts "CONTROLAR ESTE MENSAJE DE ERROR"
53
-
54
-
55
57
  return
56
58
  end
57
59
 
58
- # Add the box
59
- #env[:ui].info I18n.t("vagrant.actions.box.add.adding", :name => env[:box_name])
60
+ # Add the box
60
61
  added_box = nil
61
62
  error=false
62
63
 
63
64
  begin
64
-
65
- #last_id=env[:db].add_box_uncompression(env[:box_name],url)
66
- last_id=ObManager.instance.dbmanager.add_box_uncompression(env[:box_name],url)
67
65
 
66
+ #last_id=env[:db].add_box_uncompression(env[:box_name],url)
67
+ ObManager.instance.dbmanager.add_box_uncompression(next_id)
68
+
68
69
  added_box = env[:box_collection].add(
69
- @temp_path, env[:box_name], env[:box_provider], env[:box_force])
70
+ @temp_path, next_box_name, env[:box_provider], env[:box_force])
70
71
 
71
72
  error=false
72
73
  rescue Vagrant::Errors::BoxUpgradeRequired
@@ -75,22 +76,30 @@ module Vagrant
75
76
  # Upgrade the box
76
77
  #@db.set_box_uncompression_error(last_id)
77
78
 
78
- env[:box_collection].upgrade(env[:box_name])
79
+ env[:box_collection].upgrade(next_box_name)
79
80
 
80
81
  # Try adding it again
81
82
  retry
82
83
  end
83
84
 
84
85
 
85
- #env[:db].clear_box_uncompression(last_id) if (error==false)
86
- #env[:db].clear_box_uncompression(last_id)
87
- ObManager.instance.dbmanager.clear_box_uncompression(last_id)
86
+
87
+ ObManager.instance.dbmanager.clear_box_uncompression(next_id)
88
88
 
89
89
  #env[:db].close_db_connection
90
90
  # Call the 'recover' method in all cases to clean up the
91
91
  # downloaded temporary file.
92
92
  recover(env)
93
+ end
94
+
95
+ def call(env)
93
96
 
97
+
98
+ while ObManager.instance.dbmanager.are_boxes_queued
99
+ download_boxes(env)
100
+ end
101
+
102
+
94
103
  # Success, we added a box!
95
104
  #env[:ui].success(
96
105
  # I18n.t("vagrant.actions.box.add.added", name: added_box.name, provider: added_box.provider))
@@ -281,30 +281,5 @@ module Vagrant
281
281
  end
282
282
  end
283
283
 
284
- # def driver.list
285
- # puts "LISTING SNAPSHOT"
286
- # begin
287
- # snapshots = []
288
- # puts "UUID #{self.uuid}"
289
- # execute("snapshot",self.uuid,"list").split("\n").each do |line|
290
- # snapshot = {}
291
- #
292
- # if line =~ /Name:\s(.*?)\s\(UUID:\s(.*?)\)$/
293
- # snapshot[:name] = $1
294
- # snapshot[:id] = $2
295
- # snapshot[:current_state] = false
296
- # elsif line =~ /Name:\s(.*?)\s\(UUID:\s(.*?)\)\s\*$/
297
- # snapshot[:name] = $1
298
- # snapshot[:id] = $2
299
- # snapshot[:current_state] = true
300
- # end
301
- # snapshots.push(snapshot)
302
- # end
303
- # rescue Exception => e
304
- # puts e.message
305
- # end
306
- #
307
- # puts snapshots
308
- # return snapshots
309
- # end
284
+
310
285
 
@@ -31,24 +31,17 @@ module ServerAPI
31
31
  #before '^.*(^login).*' do
32
32
  before %r{^(?!#{RouteManager.login_route}$)} do
33
33
  content_type :json
34
- #FIXME REMOVE
35
- #puts "ENTRO BEFORE"
36
- #pp request.env
34
+
37
35
  token = ""
38
36
  cookie = ""
39
37
 
40
- #pp "TOKEN DESCAPADO = #{CGI::unescape(request.env['HTTP_CONTENT_MD5'])}"
38
+
41
39
 
42
40
 
43
41
  cookie = request.cookies[COOKIE_TOKEN_ID]
44
42
  token = CGI::unescape(request.env['HTTP_CONTENT_MD5']) if request.env['HTTP_CONTENT_MD5']!=nil
45
43
 
46
- #FIXME REMOVE
47
- # pp "COOKIES = #{cookie}"
48
- # pp "TOKEN = #{token}"
49
- #
50
- # pp "TIENE COOKIE " if (@session_table.has_key?(cookie))
51
- # pp "CONTIENE TOKEN " if (challenged?(token))
44
+
52
45
 
53
46
  if (!@session_table.has_key?(cookie)||
54
47
  !challenged?(token))
@@ -131,14 +124,14 @@ module ServerAPI
131
124
 
132
125
  #accept :vmname as paramter. This parameter
133
126
  #could be empty
134
- post RouteManager.vm_up_route do
135
- execute_async(:vm_up,params[:vmname])
127
+ post RouteManager.vm_up_route do
128
+ execute_async(:vm_up,params[:vmname])
136
129
  end
137
130
 
138
131
  #accept :vmname and :force as paramters
139
132
  post RouteManager.vm_halt_route do
140
133
  #handle_response_result(ClientController.vm_halt(params[:vmname],params[:force])
141
- execute_async(:vm_halt,params[:vmname],params[:force])
134
+ execute_async(:vm_halt,params[:vmname],params[:force])
142
135
  end
143
136
 
144
137
  #accept :vmname as paramter. This parameter
@@ -271,13 +264,13 @@ private
271
264
  #FIXME Factorizar estos dos métodos
272
265
  def execute_async(method,*params)
273
266
  begin
274
-
267
+
275
268
  if params.empty?
276
269
  result=ClientController.send method.to_sym
277
270
  else
278
271
  result=ClientController.send method.to_sym,*params
279
272
  end
280
-
273
+
281
274
 
282
275
  #pp result
283
276
  status 202
@@ -287,8 +280,8 @@ private
287
280
  rescue => e
288
281
  #FIXME DELETE PUTS
289
282
  #puts "EN EXCEPCION"
290
- puts e.class
291
- puts e.message
283
+ # puts e.class
284
+ # puts e.message
292
285
 
293
286
 
294
287
  exception = ((e.class==RestException)? e:ExceptionMutator.new(e))
@@ -301,17 +294,15 @@ private
301
294
  #def execute(method,params = {} ,to_json = true)
302
295
  def execute(method,to_json = true,*params)
303
296
  begin
304
-
297
+
305
298
  #raise Vagrant::Errors::VirtualBoxNotDetected
306
299
 
307
300
  if params.empty?
308
- result=ClientController.send method.to_sym
301
+ result=ClientController.send method.to_sym
309
302
  else
310
- result=ClientController.send method.to_sym,*params
303
+ result=ClientController.send method.to_sym,*params
311
304
  end
312
- #puts "A JSON " if to_json
313
- #puts "resultado #{result}"
314
- return result.to_json if to_json
305
+ return result.to_json.gsub("\n"," ") if to_json
315
306
  result
316
307
 
317
308
  rescue => e
@@ -321,6 +312,7 @@ private
321
312
  if (e.class==Vagrant::Errors::VirtualBoxNotDetected)
322
313
  #puts "******* SE HA GENERADO LA EXCEPCION VIRTUALBOXNOTDETECTED ******"
323
314
 
315
+ @env = ObManager.instance.reload_env
324
316
 
325
317
  restart_server
326
318
  halt 503,"Node had a problem. Restarting. Try again in a few seconds"
@@ -329,8 +321,8 @@ private
329
321
  #system("vagrant nodeserver stop;sleep 10;vagrant nodeserver start")
330
322
  end
331
323
 
332
- puts e.class
333
- puts e.message
324
+ # puts e.class
325
+ # puts e.message
334
326
 
335
327
  exception = ((e.class==RestException)? e:ExceptionMutator.new(e))
336
328
 
@@ -7,7 +7,8 @@ require 'vagrant-node/pwmanager'
7
7
  require 'vagrant-node/exceptions.rb'
8
8
  require 'vagrant-node/configmanager'
9
9
  require 'vagrant-node/obmanager'
10
- require 'usagewatch'
10
+ require 'vagrant-node/util/hwfunctions'
11
+ #require 'usagewatch'
11
12
  require "sys/cpu"
12
13
  require 'facter'
13
14
 
@@ -36,7 +37,7 @@ module Vagrant
36
37
  pid = fork do
37
38
  begin
38
39
  @db.create_queued_process(rpid)
39
- res = yield
40
+ res = yield
40
41
  @db.set_queued_process_result(rpid,res.to_json)
41
42
 
42
43
  rescue Exception => e
@@ -64,22 +65,44 @@ module Vagrant
64
65
  ################################################################
65
66
  ####################### NODE INFO (CPU,MEMORY) ################
66
67
  ################################################################
68
+
67
69
  def self.nodeinfo
68
70
 
69
71
 
70
- usw = Usagewatch
72
+ #usw = Usagewatch
71
73
 
72
-
73
- Facter.loadfacts
74
+ begin
75
+ Facter.loadfacts
74
76
 
75
-
76
-
77
- result=Hash[Facter.to_hash.map{|(k,v)| [k.to_sym,v]}]
77
+ mem_values = Util::HwFunctions.get_mem_values
78
+
79
+ disk_values = Util::HwFunctions.get_disk_values
80
+
78
81
 
79
- result[:cpuaverage] = Sys::CPU.load_avg;
80
- result[:diskusage] = usw.uw_diskused
82
+
83
+ result=Hash[Facter.to_hash.map{|(k,v)| [k.to_sym,v]}]
81
84
 
82
- result
85
+
86
+ #Overriding memory values of Facter
87
+ result[:memorysize] = (mem_values[0] / 1024.0).round(2) #Converting to GB and rounding
88
+ result[:memoryfree] = (mem_values[1] / 1024.0).round(2) #Converting to GB
89
+ result[:memorysize_mb] = mem_values[0]
90
+ result[:memoryfree_mb] = mem_values[1]
91
+
92
+
93
+
94
+ result[:cpuaverage] = Sys::CPU.load_avg;
95
+ #result[:diskusage] = usw.uw_diskused
96
+ result[:diskusage] = disk_values
97
+
98
+ result[:vagrant_version] = Vagrant::VERSION
99
+
100
+ result
101
+
102
+ rescue Exception => e
103
+ raise RestException.new(500,"Error gathering node hardware information")
104
+ end
105
+
83
106
 
84
107
 
85
108
  end
@@ -134,11 +157,16 @@ module Vagrant
134
157
  boxes = @env.boxes.all.sort
135
158
 
136
159
  fboxes = Array.new
137
- boxes.each do |name, provider|
138
- fboxes << {"name" => name,"provider" => provider}
160
+
161
+ #From version 1.6.5 (I'think) the box array is different from previous ones
162
+ boxes.each do |entry|
163
+ if entry.size==3
164
+ fboxes << {"name" => entry[0],"provider" => entry[2]}
165
+ else
166
+ fboxes << {"name" => entry[0],"provider" => entry[1]}
167
+ end
139
168
  end
140
169
 
141
-
142
170
  fboxes
143
171
 
144
172
 
@@ -180,163 +208,144 @@ module Vagrant
180
208
  ################################################################
181
209
  ######################## BOX ADD METHOD #######################
182
210
  ################################################################
183
- def self.box_add(box,url,user="guest",pass="--no-pass")
211
+ # def self.box_add(box,url,user="guest",pass="--no-pass")
184
212
 
185
- @env.boxes.all.each do |box_name,provider|
213
+
214
+ # @env.boxes.all.each do |box_name,provider|
215
+ # if box_name==box
216
+ # raise RestException.new(500,"There is a box with the same name")
217
+ # end
218
+ # end
219
+
220
+ # #Adding the box to the list
221
+ # @db.add_box_download_info(box,url)
186
222
 
187
- if box_name==box
188
- raise RestException.new(500,"There is a box with the same name")
189
- end
190
- end
191
223
 
224
+ # #If the box is downloading or there isn't any box return
225
+ # return [] if (@db.is_box_downloading)
226
+
192
227
 
193
228
 
194
- command_block = Proc.new {
195
- #ensure_environment
229
+ # command_block = Proc.new {
230
+ # #ensure_environment
196
231
 
197
- boxes = []
232
+ # boxes = []
198
233
 
199
- #TODO
200
234
 
201
- # Get the provider if one was set
202
- provider = nil
203
- # provider = options[:provider].to_sym if options[:provider]
235
+
236
+ # # Get the provider if one was set
237
+ # provider = nil
238
+ # # provider = options[:provider].to_sym if options[:provider]
204
239
 
205
- begin
240
+ # begin
206
241
 
207
- #uri = "\\\\155.54.190.227\\boxtmp\\boxes\\debian_squeeze_32.box"
208
- #
209
- # if uri=~ /^\\\\(.*?)\\(.*?)\\(.*?)$/
210
- # puts "EL HOST ES #{$1}"
211
- # puts "EL Share ES #{$2}"
212
- # puts "EL PATH ES #{$3}"
213
- # host = $1
214
- # share = $2
215
- # path = $3
216
- #
217
- # Getting and checking box file
218
- # boxname=File.basename(path.gsub('\\',File::SEPARATOR))
219
- #
220
- # raise 'Box file format not supported' if File.extname(boxname)!=".box"
221
- #
222
- # samba = nil
223
- # begin
224
- # samba = Sambal::Client.new( :host => host,
225
- # :share => share,
226
- # :user => user,
227
- # :password => pass)
228
- #
229
- #
230
- #
231
- # Get the tmp file name
232
- # temp_path = @env.tmp_path.join("box" + Time.now.to_i.to_s)
233
- #
234
- #
235
- # response = nil
236
- #
237
- # smbclient //155.54.190.227/boxtmp --no-pass -W WORKGROUP -U guest -p 445
238
- # smbclient //155.54.190.227/boxtmp -D boxes -c "get debian_squeeze_321.box" -N
239
- #
240
- # command="smbclient //#{host}/#{share} -D #{dirlocation} -c \"get #{boxname}\" -U #{user} --no-pass"
241
- #
242
- #
243
- # FIXME encontrar si existe algún tipo de notificación por
244
- # interrupciónde la descarga
245
- # FIXME a little hack beacuse in version 0.1.2 of sambal there is
246
- # a timeout that close the download after 10 seconds
247
- # def samba.ask(cmd)
248
- # @i.printf("#{cmd}\n")
249
- # response = @o.expect(/^smb:.*\\>/)[0]
250
- # end
251
- #
252
- # response = samba.get(path, temp_path.to_s)
253
- # FIXME DELETE
254
- # pp response.inspect
255
- #
256
- # raise response.message if !response.success?
257
- #
258
- # if response.success?
259
- # File download succesfully
260
- # added_box = nil
261
- # begin
262
- # provider=nil
263
- # force = true
264
- # added_box = @env.boxes.add(temp_path,box,nil,force)
265
- # boxes << {:name=>box,:provider=>added_box.provider.to_s}
266
- # rescue Vagrant::Errors::BoxUpgradeRequired
267
- # Upgrade the box
268
- # env.boxes.upgrade(box)
269
- #
270
- # Try adding it again
271
- # retry
272
- # rescue Exception => e
273
- # boxes = nil
274
- # end
275
- #
276
- # end
277
- #
278
- # rescue Exception => e
279
- # puts "EXCEPCION de descarga" if response
280
- # puts "EXCEPCION de conexion" if !response
281
- # puts e.message
282
- # boxes=nil
283
- # end
284
- #
285
- #
286
- # Closing connection
287
- # samba.close if samba
288
- #
289
- #
290
- # Cleaning
291
- # if temp_path && File.exist?(temp_path)
292
- # File.unlink(temp_path)
293
- # end
294
- #
295
- #
296
- # else
242
+
297
243
 
298
244
 
299
- copy_db = @db.clone
245
+ # copy_db = @db.clone
300
246
 
301
247
 
302
248
 
303
- boxes <<{:name=>box}
304
- # FIXME Ver qué poner en los parámetros de la llamada
305
- provider=nil
306
- force = true # Always overwrite box if exists
307
- insecure = true #Don't validate SSL certs
308
- #Calling original box add action
249
+ # boxes <<{:name=>box}
250
+ # # FIXME Ver qué poner en los parámetros de la llamada
251
+ # provider=nil
252
+ # force = true # Always overwrite box if exists
253
+ # insecure = true #Don't validate SSL certs
254
+ # #Calling original box add action
309
255
 
310
256
 
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
- })
257
+ # @env.action_runner.run(BoxAddAction, {
258
+ # :box_name => box,
259
+ # :box_provider => provider,
260
+ # :box_url => url,
261
+ # :box_force => force,
262
+ # :box_download_insecure => insecure,
263
+ # :db => copy_db,
264
+ # })
319
265
 
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
- # })
327
-
328
- # end
329
-
266
+
330
267
 
331
268
 
332
269
 
270
+ # puts "HA TERMINADO LA ACCION"
271
+
272
+ # boxes
273
+
274
+ # rescue =>e
275
+ # puts e.message
276
+ # end
277
+
278
+ # }
279
+
280
+ # method("execute_queued").call(&command_block);
281
+
282
+ # end
283
+
284
+ def self.box_add(box,url,user="guest",pass="--no-pass")
285
+
286
+
287
+ @env.boxes.all.each do |box_name,provider|
288
+ if box_name==box
289
+ raise RestException.new(500,"There is a box with the same name")
290
+ end
291
+ end
292
+
293
+
294
+
295
+
296
+
297
+ command_block = Proc.new {
298
+ #ensure_environment
299
+
300
+ boxes = []
301
+ boxes <<{:name=>box}
302
+ #Adding the box to the list
303
+ @db.add_box_download_info(box,url)
304
+
305
+
306
+ #If the box is downloading or there isn't any box return
307
+ if (!@db.is_box_downloading)
308
+
309
+ # Get the provider if one was set
310
+ provider = nil
311
+
312
+ begin
313
+
314
+
315
+
316
+
317
+ copy_db = @db.clone
318
+
319
+
320
+
321
+ #boxes <<{:name=>box}
322
+
323
+
324
+ provider=nil
325
+ force = true # Always overwrite box if exists
326
+ insecure = true #Don't validate SSL certs
327
+ #Calling original box add action
328
+
329
+
330
+ @env.action_runner.run(BoxAddAction, {
331
+ :box_provider => provider,
332
+ :box_force => force,
333
+ :box_download_insecure => insecure,
334
+ :db => copy_db,
335
+ })
333
336
 
334
-
335
- boxes
336
337
 
337
- rescue =>e
338
- puts e.message
339
- end
338
+
339
+
340
+
341
+
342
+ rescue =>e
343
+ puts e.message
344
+ end
345
+
346
+ boxes
347
+
348
+ end
340
349
 
341
350
  }
342
351
 
@@ -351,7 +360,7 @@ module Vagrant
351
360
  ################################################################
352
361
  def self.vm_up(vmname)
353
362
 
354
-
363
+
355
364
 
356
365
  command_block = Proc.new {
357
366
 
@@ -382,7 +391,7 @@ module Vagrant
382
391
  end
383
392
 
384
393
  raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
385
-
394
+
386
395
  machine_names
387
396
 
388
397
  rescue Exception => e
@@ -511,7 +520,7 @@ module Vagrant
511
520
  end
512
521
 
513
522
  raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?)
514
-
523
+
515
524
  machine_names
516
525
 
517
526
  rescue Exception => e
@@ -1015,19 +1024,37 @@ module Vagrant
1015
1024
 
1016
1025
  opres = Array.new
1017
1026
 
1027
+
1028
+
1029
+
1018
1030
  aux=result.first
1031
+
1032
+
1033
+
1019
1034
 
1020
1035
  opres[0]=aux["operation_status"]
1021
1036
  opres[1]=aux["operation_result"]
1022
1037
 
1038
+
1039
+
1023
1040
  opres
1024
1041
  end
1025
1042
 
1026
1043
  def self.operation_queued_last
1027
1044
  ensure_environment
1028
1045
 
1029
- @db.get_queued_last
1030
-
1046
+ opres = Array.new
1047
+
1048
+ result=@db.get_queued_last
1049
+
1050
+ result.each do |row|
1051
+ aux=Array.new
1052
+ aux[0]=row["operation_status"]
1053
+ aux[1]=row["operation_result"]
1054
+ opres << aux
1055
+ end
1056
+
1057
+ opres
1031
1058
  end
1032
1059
 
1033
1060