vagrant-nodemaster 0.0.2 → 1.0.0

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.
Files changed (38) hide show
  1. data/README.md +95 -0
  2. data/lib/vagrant-nodemaster.rb +4 -2
  3. data/lib/vagrant-nodemaster/apidesc.rb +105 -1
  4. data/lib/vagrant-nodemaster/node/nodeadd.rb +4 -4
  5. data/lib/vagrant-nodemaster/node/nodedbmanager.rb +49 -33
  6. data/lib/vagrant-nodemaster/node/nodelist.rb +2 -2
  7. data/lib/vagrant-nodemaster/node/nodeoperationcommand.rb +85 -0
  8. data/lib/vagrant-nodemaster/node/nodeoperationlast.rb +47 -0
  9. data/lib/vagrant-nodemaster/node/nodeoperationshow.rb +39 -0
  10. data/lib/vagrant-nodemaster/node/noderemove.rb +3 -3
  11. data/lib/vagrant-nodemaster/node/nodestatus.rb +2 -2
  12. data/lib/vagrant-nodemaster/node/nodeupdate.rb +2 -2
  13. data/lib/vagrant-nodemaster/node/nodeupdatepw.rb +72 -0
  14. data/lib/vagrant-nodemaster/nodecommand.rb +14 -0
  15. data/lib/vagrant-nodemaster/remote/configmanager.rb +16 -0
  16. data/lib/vagrant-nodemaster/remote/remoteboxadd.rb +11 -8
  17. data/lib/vagrant-nodemaster/remote/remoteconfigaddvm.rb +46 -0
  18. data/lib/vagrant-nodemaster/remote/remoteconfigcommand.rb +110 -0
  19. data/lib/vagrant-nodemaster/remote/remoteconfigdeletevm.rb +37 -0
  20. data/lib/vagrant-nodemaster/remote/remoteconfigshow.rb +31 -0
  21. data/lib/vagrant-nodemaster/remote/remoteconfigupload.rb +34 -0
  22. data/lib/vagrant-nodemaster/remote/remotehalt.rb +14 -5
  23. data/lib/vagrant-nodemaster/remote/remoteprovision.rb +31 -23
  24. data/lib/vagrant-nodemaster/remote/remoteresume.rb +16 -9
  25. data/lib/vagrant-nodemaster/remote/remotesnapshotcommand.rb +8 -3
  26. data/lib/vagrant-nodemaster/remote/remotesnapshotdelete.rb +31 -0
  27. data/lib/vagrant-nodemaster/remote/remotesnapshotlist.rb +1 -0
  28. data/lib/vagrant-nodemaster/remote/remotesnapshotrestore.rb +17 -9
  29. data/lib/vagrant-nodemaster/remote/remotesnapshottake.rb +16 -6
  30. data/lib/vagrant-nodemaster/remote/remotesuspend.rb +15 -7
  31. data/lib/vagrant-nodemaster/remote/remoteup.rb +18 -22
  32. data/lib/vagrant-nodemaster/remote/remotevmstatus.rb +1 -1
  33. data/lib/vagrant-nodemaster/remotecommand.rb +18 -5
  34. data/lib/vagrant-nodemaster/requestcontroller.rb +321 -69
  35. data/lib/vagrant-nodemaster/version.rb +1 -1
  36. data/vagrant-nodemaster.gemspec +7 -2
  37. metadata +18 -7
  38. data/Readme.md +0 -0
@@ -6,21 +6,31 @@ module Vagrant
6
6
  class SnapshotTake < Vagrant.plugin(2, :command)
7
7
  def execute
8
8
  options = {}
9
-
9
+ options[:async] = true
10
10
  opts = OptionParser.new do |opts|
11
- opts.banner = "Usage: vagrant remote snapshot take <node-name> <vmname> <name> [description]"
11
+ opts.banner = "Usage: vagrant remote snapshot take <node-name> <vmname> <name> [description] [--synchronous]"
12
+ opts.separator ""
13
+ opts.on("-s", "--synchronous", "Wait until the operation finishes") do |f|
14
+ options[:async] = false
15
+ end
12
16
  end
13
17
 
14
18
 
15
19
  argv = parse_options(opts)
16
20
 
17
21
  return if !argv
22
+
18
23
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 3 || argv.length > 4
19
-
20
- snapshot = RequestController.vm_snapshot_take(argv[0],argv[1],argv[2],argv[3])
24
+
25
+ snapshot = RequestController.vm_snapshot_take(argv[0],argv[1],argv[2],argv[3],options[:async])
26
+
27
+ if options[:async] == false
28
+ @env.ui.info("Remote Client: #{argv[0]}", :prefix => false)
29
+ @env.ui.info("Snapshot \"#{snapshot[:name]}\" with UUID #{snapshot[:id]} succesfully created.")
30
+ else
31
+ @env.ui.info("Remote Client \"#{argv[0]}\": The operation ID is \"#{snapshot.gsub!(/\D/, "")}\"")
32
+ end
21
33
 
22
- @env.ui.info("Remote Client: #{argv[0]}", :prefix => false)
23
- @env.ui.info("Snapshot \"#{snapshot[:name]}\" with UUID #{snapshot[:id]} succesfully created.")
24
34
 
25
35
  0
26
36
  end
@@ -6,9 +6,14 @@ module Vagrant
6
6
  def execute
7
7
 
8
8
  options = {}
9
+ options[:async] = true
9
10
 
10
11
  opts = OptionParser.new do |opts|
11
- opts.banner = "Usage: vagrant remote suspend <node-name> [vm_name]"
12
+ opts.banner = "Usage: vagrant remote suspend <node-name> [vm_name] [--synchronous]"
13
+ opts.separator ""
14
+ opts.on("-s", "--synchronous", "Wait until the operation finishes") do |f|
15
+ options[:async] = false
16
+ end
12
17
  end
13
18
 
14
19
  argv = parse_options(opts)
@@ -16,14 +21,17 @@ module Vagrant
16
21
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 || argv.length > 2)
17
22
 
18
23
 
19
- machines=RequestController.vm_suspend(argv[0],argv[1])
24
+ machines=RequestController.vm_suspend(argv[0],argv[1],options[:async])
20
25
 
21
-
22
- machines.each do |machine|
23
- @env.ui.info("Remote Client \"#{argv[0]}\":Virtual Machine \"#{machine}\" suspended")
24
- end
26
+ if options[:async] == false
27
+ machines.each do |machine|
28
+ @env.ui.success("Remote Client \"#{argv[0]}\":Virtual Machine \"#{machine["vmname"]}\" suspended")
29
+ end
30
+ else
31
+ @env.ui.info("Remote Client \"#{argv[0]}\": The operation ID is \"#{machines.gsub!(/\D/, "")}\"")
32
+ end
25
33
 
26
- @env.ui.info(" ")
34
+
27
35
  0
28
36
  end
29
37
 
@@ -4,37 +4,33 @@ module Vagrant
4
4
  module NodeMaster
5
5
  class UpVM < Vagrant.plugin(2, :command)
6
6
  def execute
7
- options = {}
8
-
7
+ options = {}
8
+ options[:async] = true
9
+
9
10
  opts = OptionParser.new do |opts|
10
- opts.banner = "Usage: vagrant remote up <node-name> [vm_name]"
11
+ opts.banner = "Usage: vagrant remote up <node-name> [vm_name] [--synchronous]"
12
+ opts.separator ""
13
+ opts.on("-s", "--synchronous", "Wait until the operation finishes") do |f|
14
+ options[:async] = false
15
+ end
11
16
  end
12
17
 
13
18
  argv = parse_options(opts)
14
19
  return if !argv
15
20
  raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 || argv.length > 2)
16
21
 
17
- # begin
18
-
19
22
 
20
- machines=RequestController.vm_up(argv[0],argv[1])
23
+ machines=RequestController.vm_up(argv[0],argv[1],options[:async])
21
24
 
22
-
23
- machines.each do |machine|
24
- @env.ui.info("Remote Client \"#{argv[0]}\": Virtual Machine \"#{machine}\" launched")
25
- end
26
-
27
- @env.ui.info(" ")
28
-
29
- # rescue RestClient::RequestFailed => e
30
- # @env.ui.error("Remote Client \"#{argv[0]}\": Request Failed")
31
- # rescue RestClient::ResourceNotFound => e
32
- # @env.ui.error("Remote Client \"#{argv[0]}\": Virtual Machine \"#{argv[1]}\" could not be found")
33
- # rescue RestClient::ExceptionWithResponse=> e
34
- # @env.ui.error(e.response)
35
- # rescue Exception => e
36
- # @env.ui.error(e.message)
37
- # end
25
+ if options[:async] == false
26
+ machines.each do |machine|
27
+ @env.ui.success("Remote Client \"#{argv[0]}\": Virtual Machine \"#{machine["vmname"]}\" launched")
28
+ end
29
+
30
+ @env.ui.info(" ")
31
+ else
32
+ @env.ui.info("Remote Client \"#{argv[0]}\": The operation ID is \"#{machines.gsub!(/\D/, "")}\"")
33
+ end
38
34
 
39
35
  end
40
36
 
@@ -18,7 +18,7 @@ module Vagrant
18
18
  machine_status=RequestController.vm_status(argv[0],argv[1])
19
19
 
20
20
  @env.ui.info("Remote Client: #{argv[0]}", :prefix => false)
21
-
21
+
22
22
  machine_status.each do |machine|
23
23
  @env.ui.info(" * #{machine["name"].ljust(25)} #{machine["status"]} (#{machine["provider"]})", :prefix => false)
24
24
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'vagrant/plugin'
3
-
3
+ require 'vagrant-nodemaster/node/nodedbmanager'
4
4
 
5
5
  module Vagrant
6
6
  module NodeMaster
@@ -10,7 +10,10 @@ module Vagrant
10
10
  super
11
11
 
12
12
  @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
-
13
+
14
+ #Initializing db structure
15
+ DB::NodeDBManager.new(@env.data_dir)
16
+
14
17
  # puts "MAIN ARGS #{@main_args}"
15
18
  # puts "SUB COMMAND #{@sub_command}"
16
19
  # puts "SUB ARGS #{@sub_args}"
@@ -41,6 +44,11 @@ module Vagrant
41
44
  HaltVM
42
45
  end
43
46
 
47
+ # @subcommands.register(:add) do
48
+ # require File.expand_path("../remote/remoteadd", __FILE__)
49
+ # AddVM
50
+ # end
51
+
44
52
  @subcommands.register(:suspend) do
45
53
  require File.expand_path("../remote/remotesuspend", __FILE__)
46
54
  SuspendVM
@@ -81,6 +89,11 @@ module Vagrant
81
89
  BackupCommand
82
90
  end
83
91
 
92
+ @subcommands.register(:config) do
93
+ require File.expand_path("../remote/remoteconfigcommand", __FILE__)
94
+ ConfigCommand
95
+ end
96
+
84
97
  end
85
98
 
86
99
  def execute
@@ -99,12 +112,12 @@ module Vagrant
99
112
  begin
100
113
  # Initialize and execute the command class
101
114
  command_class.new(@sub_args, @env).execute
115
+ rescue RestClient::ExceptionWithResponse=> e
116
+ @env.ui.error(e.response)
102
117
  rescue RestClient::RequestFailed => e
103
118
  @env.ui.error("Remote Client \"#{@sub_args[0]}\": Request Failed")
104
119
  rescue RestClient::ResourceNotFound => e
105
- @env.ui.error("Remote Client \"#{@sub_args[0]}\": Virtual Machine \"#{@sub_args[1]}\" could not be found")
106
- rescue RestClient::ExceptionWithResponse=> e
107
- @env.ui.error(e.response)
120
+ @env.ui.error("Remote Client \"#{@sub_args[0]}\": Virtual Machine \"#{@sub_args[1]}\" could not be found")
108
121
  rescue Exception => e
109
122
  @env.ui.error(e.message)
110
123
  end
@@ -4,28 +4,49 @@ require 'pp'
4
4
  require 'vagrant-nodemaster/apidesc'
5
5
  require 'vagrant-nodemaster/node/nodedbmanager'
6
6
 
7
+
8
+
9
+
7
10
  module Vagrant
8
11
  module NodeMaster
12
+
13
+
14
+
9
15
  class RequestController
10
16
  include RestRoutes
17
+ GET_VERB = :get
18
+ POST_VERB = :post
19
+ DELETE_VERB = :delete
20
+ PUT_VERB = :put
21
+ SYNC_TIME = 10
11
22
 
12
23
  def self.get_remote_boxes(host)
13
24
  client=get_host_parameters(host)
14
-
15
- response = RestClient.get RouteManager.box_list_url(client[:address],client[:port])
25
+
26
+ resource = RestClient::Resource.new(
27
+ RouteManager.box_list_url(client[:address],client[:port])
28
+ )
29
+
30
+ response = execute(client,GET_VERB,resource);
31
+
16
32
  JSON.parse(response.to_str)
17
33
  end
18
34
 
19
35
  def self.box_delete(host,box,provider)
20
- client=get_host_parameters(host)
21
-
22
- response = RestClient.delete RouteManager.box_delete_url(client[:address],client[:port],box,provider)
36
+ client=get_host_parameters(host)
37
+
38
+
39
+ resource = RestClient::Resource.new(
40
+ RouteManager.box_delete_url(client[:address],client[:port],box,provider)
41
+ )
42
+
43
+ response = execute(client,DELETE_VERB,resource);
23
44
 
24
45
  JSON.parse(response.to_str)
25
46
 
26
47
  end
27
48
 
28
- def self.box_add(host,box,url)
49
+ def self.box_add(host,box,url,async=true)
29
50
  client=get_host_parameters(host)
30
51
 
31
52
  resource = RestClient::Resource.new(
@@ -33,13 +54,17 @@ module Vagrant
33
54
  :timeout => -1
34
55
  )
35
56
 
36
- response = resource.post :box => box,:url => url
37
-
38
- JSON.parse(response.to_str)
57
+
58
+ response = execute(client,POST_VERB,resource,{:box => box,:url => url},async);
59
+
60
+ return JSON.parse(response.to_str) if async ==false
61
+
62
+ response
63
+
39
64
 
40
65
  end
41
66
 
42
- def self.vm_up(host,vmname)
67
+ def self.vm_up(host,vmname,async=true)
43
68
  client=get_host_parameters(host)
44
69
  #Due to the fact that starting the machines can take long,
45
70
  #setting the request not to expire
@@ -48,13 +73,15 @@ module Vagrant
48
73
  :timeout => -1
49
74
  )
50
75
 
51
- response = resource.post :vmname => vmname
52
-
53
- JSON.parse(response.to_str)
76
+
77
+ response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
78
+
79
+ return JSON.parse(response.to_str) if async ==false
80
+ response
54
81
 
55
82
  end
56
83
 
57
- def self.vm_halt(host,vmname,force)
84
+ def self.vm_halt(host,vmname,force,async=true)
58
85
  client=get_host_parameters(host)
59
86
  #Due to the fact that halting the machines can take long,
60
87
  #setting the request not to expire
@@ -63,40 +90,84 @@ module Vagrant
63
90
  :timeout => -1
64
91
  )
65
92
 
66
- response = resource.post :vmname => vmname,:force=>force
67
-
68
- JSON.parse(response.to_str)
93
+ response = execute(client,POST_VERB,resource,{:vmname => vmname,:force=>force},async);
94
+ return JSON.parse(response.to_str) if async ==false
95
+ response
69
96
 
70
97
  end
71
98
 
72
99
  def self.vm_destroy (host,vmname)
73
100
  client=get_host_parameters(host)
101
+
74
102
  resource = RestClient::Resource.new(
75
103
  RouteManager.vm_destroy_url(client[:address],client[:port]),
76
104
  :timeout => -1
77
105
  )
78
106
 
79
- response = resource.post :vmname => vmname
80
-
107
+
108
+ response = execute(client,POST_VERB,resource,{:vmname => vmname});
109
+
81
110
  JSON.parse(response.to_str)
82
111
 
83
112
  end
84
113
 
114
+ #Deletes from the remote node config the machine with name 'vmname'
115
+ def self.vm_delete(host,vmname,remove=false)
116
+ client=get_host_parameters(host)
117
+
118
+
119
+
120
+ resource = RestClient::Resource.new(
121
+ RouteManager.vm_delete_url(client[:address],client[:port],vmname),
122
+ :payload => { :remove => remove }
123
+ )
124
+
125
+ execute(client,DELETE_VERB,resource);
126
+
127
+
128
+
129
+ # JSON.parse(response.to_str)
130
+
131
+ end
132
+
85
133
 
134
+ def self.vm_add(host,config,rename=false)
135
+ client=get_host_parameters(host)
136
+
137
+ resource = RestClient::Resource.new(
138
+ RouteManager.vm_add_url(client[:address],client[:port]),
139
+ :timeout => -1 ,
140
+ # :payload => {
141
+ # :content_type => 'text/plain',
142
+ # :file => File.new(config, 'rb')
143
+ # }
144
+ )
145
+
146
+ execute(client,PUT_VERB,resource,{:file => File.read(config), :content_type => 'text/plain',:rename => rename})
147
+ # JSON.parse(response.to_str)
148
+
149
+ end
86
150
 
87
151
  def self.vm_status(host,vmname)
88
152
  client=get_host_parameters(host)
89
153
 
90
- get_vm_status(client[:address],client[:port],vmname)
154
+ #get_vm_status(client[:address],client[:port],vmname)
155
+ get_vm_status(client,vmname)
91
156
 
92
157
  end
93
158
 
94
159
  def self.vm_ssh_config(host,vmname)
95
160
  client=get_host_parameters(host)
96
161
 
97
- response = RestClient.get RouteManager.vm_sshconfig_url(client[:address],client[:port],vmname)
162
+
163
+ resource = RestClient::Resource.new(
164
+ RouteManager.vm_sshconfig_url(client[:address],client[:port],vmname)
165
+ )
166
+
167
+ response = execute(client,GET_VERB,resource);
168
+ result=JSON.parse(response.to_str, {:symbolize_names => true})
169
+
98
170
 
99
- result=JSON.parse(response.to_str, {:symbolize_names => true})
100
171
  #Change the target machine
101
172
  result[:host]=client[:address]
102
173
 
@@ -104,7 +175,7 @@ module Vagrant
104
175
  end
105
176
 
106
177
 
107
- def self.vm_suspend(host,vmname)
178
+ def self.vm_suspend(host,vmname,async=true)
108
179
  client=get_host_parameters(host)
109
180
  #Due to the fact that suspending the machines can take long,
110
181
  #setting the request not to expire
@@ -113,77 +184,141 @@ module Vagrant
113
184
  :timeout => -1
114
185
  )
115
186
 
116
- response = resource.post :vmname => vmname
117
-
118
- JSON.parse(response.to_str)
187
+
188
+ response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
189
+
190
+ return JSON.parse(response.to_str) if async ==false
191
+ response
119
192
 
120
193
  end
121
194
 
122
- def self.vm_resume(host,vmname)
195
+ def self.vm_resume(host,vmname,async=true)
123
196
  client=get_host_parameters(host)
124
197
  #Due to the fact that resuming the machines can take long,
125
198
  #setting the request not to expire
126
199
  resource = RestClient::Resource.new(
127
200
  RouteManager.vm_resume_url(client[:address],client[:port]),
128
201
  :timeout => -1
129
- )
202
+ )
130
203
 
131
- response = resource.post :vmname => vmname
132
-
133
- JSON.parse(response.to_str)
204
+ response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
205
+
206
+ return JSON.parse(response.to_str) if async ==false
207
+ response
134
208
 
135
209
  end
136
210
 
137
211
 
138
- def self.vm_provision(host,vmname)
212
+ def self.vm_provision(host,vmname,async=true)
139
213
  client=get_host_parameters(host)
140
214
  #Due to the fact that provisioning the machines can take long,
141
215
  #setting the request not to expire
142
216
  resource = RestClient::Resource.new(
143
217
  RouteManager.vm_provision_url(client[:address],client[:port]),
144
218
  :timeout => -1
145
- )
219
+ )
146
220
 
147
- response = resource.post :vmname => vmname
148
-
149
- JSON.parse(response.to_str)
221
+
222
+ response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
223
+
224
+ return JSON.parse(response.to_str) if async ==false
225
+ response
150
226
 
151
227
  end
152
228
 
153
- def self.get_remote_snapshots(host,vmname)
154
- client=get_host_parameters(host)
155
-
156
- url=RouteManager.snapshot_list_url(client[:address],client[:port],vmname)
157
-
158
- response = RestClient.get url
229
+ def self.get_remote_snapshots(host,vmname)
230
+
231
+ client=get_host_parameters(host)
159
232
 
233
+ resource = RestClient::Resource.new(
234
+ RouteManager.snapshot_list_url(client[:address],client[:port],vmname)
235
+ )
236
+
237
+
238
+ response = execute(client,GET_VERB,resource);
160
239
 
161
240
  JSON.parse(response.to_str,{:symbolize_names => true})
241
+ # return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
242
+ # response
162
243
 
163
244
  end
164
245
 
165
- def self.vm_snapshot_take(host,vmname,sname,sdesc)
166
- client=get_host_parameters(host)
246
+ def self.vm_snapshot_take(host,vmname,sname,sdesc,async=true)
247
+ client=get_host_parameters(host)
248
+
167
249
  #Due to the fact that taking the snapshot can take long,
168
- #setting the request not to expire
250
+ #setting the request not to expire
251
+
169
252
  resource = RestClient::Resource.new(
170
- RouteManager.vm_snapshot_take_url(client[:address],client[:port],vmname),
171
- :timeout => -1
172
- )
173
- response = resource.post :vmname => vmname,:name => sname,:desc => sdesc
253
+ RouteManager.vm_snapshot_take_url(client[:address],client[:port],vmname),
254
+ :timeout => -1,
255
+ )
256
+
257
+
258
+ response = execute(client,POST_VERB,resource,{:vmname => vmname,:name => sname,:desc => sdesc},async);
174
259
 
175
- JSON.parse(response.to_str,{:symbolize_names => true})
260
+ #JSON.parse(response.to_str,{:symbolize_names => true})
261
+ return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
262
+ response
176
263
 
177
264
  end
178
265
 
179
- def self.vm_snapshot_restore(host,vmname,snapid)
180
- client=get_host_parameters(host)
266
+ def self.vm_snapshot_delete(host,vmname,snapid)
267
+ client=get_host_parameters(host)
268
+
269
+ #Due to the fact that deleting the snapshot can take long,
270
+ #setting the request not to expire
271
+ resource = RestClient::Resource.new(
272
+ RouteManager.vm_snapshot_delete_url(client[:address],client[:port],vmname,snapid),
273
+ :timeout => -1,
274
+ )
275
+
276
+
277
+ response = execute(client,DELETE_VERB,resource);
278
+
279
+ # JSON.parse(response.to_str,{:symbolize_names => true})
280
+
281
+ end
282
+
283
+
284
+ def self.vm_snapshot_restore(host,vmname,snapid,async=true)
285
+
286
+ client=get_host_parameters(host)
287
+
181
288
  resource = RestClient::Resource.new(
182
289
  RouteManager.vm_snapshot_restore_url(client[:address],client[:port],vmname),
183
290
  :timeout => -1
184
291
  )
185
- response = resource.post :vmname => vmname,:snapid => snapid
186
- JSON.parse(response.to_str,{:symbolize_names => true})
292
+
293
+ response = execute(client,POST_VERB,resource,{:vmname => vmname,:snapid => snapid},async);
294
+
295
+
296
+ #JSON.parse(response.to_str,{:symbolize_names => true})
297
+ return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
298
+ response
299
+ end
300
+
301
+
302
+ def self.node_operation_queued(host,id)
303
+ client=get_host_parameters(host)
304
+ resource = RestClient::Resource.new(
305
+ RouteManager.node_queue_url(client[:address],client[:port],id)
306
+ )
307
+
308
+ response = execute(client,GET_VERB,resource);
309
+
310
+ JSON.parse(response.to_str,{:symbolize_names => true})
311
+ end
312
+
313
+ def self.node_operation_queued_last(host)
314
+ client=get_host_parameters(host)
315
+ resource = RestClient::Resource.new(
316
+ RouteManager.node_queue_last_url(client[:address],client[:port])
317
+ )
318
+
319
+ response = execute(client,GET_VERB,resource);
320
+
321
+ JSON.parse(response.to_str,{:symbolize_names => true})
187
322
  end
188
323
 
189
324
  def self.node_backup_take(ui,target_dir,host=nil,vmname=nil)
@@ -191,6 +326,7 @@ module Vagrant
191
326
  current_client=nil
192
327
  current_file = nil
193
328
  download_backup = false
329
+
194
330
  begin
195
331
 
196
332
  raise "Directory \"#{target_dir}\" does not exists" if target_dir && !File.directory?(target_dir)
@@ -201,14 +337,16 @@ module Vagrant
201
337
  if (host)
202
338
  clients << get_host_parameters(host)
203
339
  else
204
- dbmanager=DB::NodeDBManager.new
205
- clients = dbmanager.get_nodes
340
+ #FIXME QUITAR ESTO DE AQUI
341
+ #@dbmanager=DB::NodeDBManager.new if !@dbmanager
342
+ clients = DB::NodeDBManager.get_nodes
206
343
  end
207
344
 
208
345
  clients.each do |client|
209
346
  current_client=client
210
347
  #Fist get remote virtual machines
211
- vms=get_vm_status(client[:address],client[:port],vmname)
348
+ vms=get_vm_status(client,vmname)
349
+
212
350
 
213
351
  vms.each do |vm|
214
352
 
@@ -227,7 +365,9 @@ module Vagrant
227
365
  :timeout => -1
228
366
  )
229
367
 
230
- response = resource.get({:params => {'download' => download_backup}})
368
+ #OLD. FIXME REMOVE
369
+ #response = resource.get({:params => {'download' => download_backup}})
370
+ response = execute(client,GET_VERB,resource,:params => {'download' => download_backup});
231
371
 
232
372
  th.kill if th
233
373
 
@@ -272,8 +412,6 @@ module Vagrant
272
412
  end
273
413
 
274
414
  def self.node_backup_log(ui,node,vmname=nil)
275
- clients = []
276
-
277
415
 
278
416
  raise "Error finding the node" if node==nil
279
417
 
@@ -281,30 +419,144 @@ module Vagrant
281
419
 
282
420
  resource = RestClient::Resource.new(
283
421
  RouteManager.backup_log_url(client[:address],client[:port],vmname),
284
- :timeout => -1
422
+ :timeout => -1
285
423
  )
286
424
 
287
-
288
- response = resource.get :vmname => vmname
289
-
425
+
426
+
427
+ response = execute(client,GET_VERB,resource,:vmname => vmname);
428
+
290
429
  JSON.parse(response.to_str)
291
430
 
292
431
  end
293
432
 
433
+ def self.node_config_show(node)
434
+ raise "Please enter a valid node" if node==nil
435
+ client=get_host_parameters(node)
436
+
437
+
438
+ resource = RestClient::Resource.new(
439
+ RouteManager.config_show_url(client[:address],client[:port]),
440
+ :timeout => -1
441
+ )
442
+
443
+
444
+ execute(client,GET_VERB,resource);
445
+
446
+ end
447
+
448
+
449
+
450
+ def self.node_config_upload(node,config_path)
451
+ client=get_host_parameters(node)
452
+
453
+
454
+ resource = RestClient::Resource.new(
455
+ RouteManager.config_upload_url(client[:address],client[:port]),
456
+ :timeout => -1
457
+ )
458
+
459
+ execute(client,POST_VERB,resource,{:file => File.read(config_path), :content_type => 'text/plain'})
460
+
461
+ end
462
+
463
+
464
+ def self.node_password_change(node,password)
465
+ client=get_host_parameters(node)
466
+
467
+
468
+ resource = RestClient::Resource.new(
469
+ RouteManager.node_password_change_url(client[:address],client[:port]),
470
+ :timeout => -1
471
+ )
472
+
473
+ execute(client,POST_VERB,resource,{:password => Digest::MD5.hexdigest(password)});
474
+
475
+ end
476
+
294
477
 
295
478
  private
296
479
 
480
+ def self.execute(host,http_method,resource,params=nil,async=true)
481
+ client = login(host)
482
+
483
+ #FIXME AÑADIR AQUI GESTION DE ERRORES
484
+ #SI NO HAY COOKIE
485
+ #SI NO HAY TOKEN
486
+ #Y EnVIAR DESDE SERVeR ALGUNA EXECPCION
487
+ #PARA MONITORIZAR LA FALTA DE ALGUN PARAMETRO Y REPETIR LA TRANSACCION
488
+ resource.options[:headers] = { :content_md5 => CGI.escape(client[:token]),
489
+ :cookies => client[:cookies]
490
+ }
491
+
492
+ data= {}
493
+
494
+ data.merge!(params) if params!=nil
495
+
496
+
497
+
498
+ #response = resource.send http_method.to_sym, :content_md5 => client[:token], :cookies => client[:cookies]
499
+
500
+ response = resource.send http_method.to_sym, data
501
+
502
+ if response.code == 202 && async==false
503
+ #Getting the location operation id
504
+ opid = response.gsub!(/\D/, "")
505
+
506
+ begin
507
+ sleep SYNC_TIME
508
+ client1 = login(host)
509
+ resourceop = RestClient::Resource.new(
510
+ RouteManager.node_queue_url(client1[:address],client1[:port],opid)
511
+ )
512
+ resourceop.options[:headers] = { :content_md5 => CGI.escape(client1[:token]),
513
+ :cookies => client1[:cookies]
514
+ }
515
+ responseop = resourceop.send GET_VERB
516
+
517
+ res = JSON.parse(responseop.to_str)
518
+ pp res[0]
519
+
520
+
521
+ end while (res[0].eql? "IN PROGRESS") #While operation code is IN PROGRESS iterate
522
+
523
+ res[1]
524
+
525
+ else
526
+ response
527
+ end
528
+
529
+ end
530
+
531
+
532
+
533
+ def self.login(host)
534
+
535
+ response = RestClient.get RouteManager.login_url(host[:address],host[:port])
536
+
537
+ host[:token] = Digest::MD5.hexdigest(response.headers[:content_md5]+host[:password])
538
+ host[:cookies] = response.cookies
539
+
540
+ host
541
+ end
542
+
297
543
  def self.get_host_parameters(host)
298
544
 
299
- dbmanager=DB::NodeDBManager.new
300
-
301
- return dbmanager.get_node(host)
545
+ #@dbmanager=DB::NodeDBManager.get_reference if !@dbmanager
546
+ DB::NodeDBManager.get_node(host)
302
547
 
303
548
  end
304
549
 
305
- def self.get_vm_status(address,port,vmname)
306
- response = RestClient.get RouteManager.vm_status_url(address,port,vmname)
550
+ def self.get_vm_status(client,vmname)
551
+
552
+ resource = RestClient::Resource.new(
553
+ RouteManager.vm_status_url(client[:address],client[:port],vmname)
554
+ )
555
+
556
+ response = execute(client,GET_VERB,resource);
557
+
307
558
  JSON.parse(response.to_str)
559
+
308
560
  end
309
561
 
310
562
  def self.draw_progress(ui,download,node,vmname)