vagrant-nodemaster 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/lib/vagrant-nodemaster/apidesc.rb +47 -21
- data/lib/vagrant-nodemaster/node/nodeinfo.rb +58 -0
- data/lib/vagrant-nodemaster/node/nodeoperationlast.rb +15 -15
- data/lib/vagrant-nodemaster/node/nodeupdate.rb +3 -3
- data/lib/vagrant-nodemaster/nodecommand.rb +5 -0
- data/lib/vagrant-nodemaster/remote/remoteboxcommand.rb +5 -0
- data/lib/vagrant-nodemaster/remote/remoteboxdownload.rb +44 -0
- data/lib/vagrant-nodemaster/remote/remotevminfo.rb +54 -0
- data/lib/vagrant-nodemaster/remotecommand.rb +60 -55
- data/lib/vagrant-nodemaster/requestcontroller.rb +550 -510
- data/lib/vagrant-nodemaster/version.rb +1 -1
- metadata +81 -86
@@ -8,382 +8,403 @@ require 'vagrant-nodemaster/node/nodedbmanager'
|
|
8
8
|
|
9
9
|
|
10
10
|
module Vagrant
|
11
|
-
|
11
|
+
module NodeMaster
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
class RequestController
|
16
|
+
include RestRoutes
|
17
|
+
GET_VERB = :get
|
18
|
+
POST_VERB = :post
|
19
|
+
DELETE_VERB = :delete
|
20
|
+
PUT_VERB = :put
|
21
|
+
SYNC_TIME = 10
|
22
|
+
|
23
|
+
def self.box_downloads(host)
|
24
|
+
client=get_host_parameters(host)
|
25
|
+
resource = RestClient::Resource.new(
|
26
|
+
RouteManager.box_download_url(client[:address],client[:port])
|
27
|
+
)
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
response = execute(client,GET_VERB,resource);
|
30
|
+
JSON.parse(response.to_str,{:symbolize_names => true})
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.get_remote_boxes(host)
|
34
|
+
client=get_host_parameters(host)
|
35
|
+
|
36
|
+
resource = RestClient::Resource.new(
|
37
|
+
RouteManager.box_list_url(client[:address],client[:port])
|
38
|
+
)
|
39
|
+
|
40
|
+
response = execute(client,GET_VERB,resource);
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
JSON.parse(response.to_str)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.box_delete(host,box,provider)
|
46
|
+
client=get_host_parameters(host)
|
47
|
+
|
48
|
+
|
49
|
+
resource = RestClient::Resource.new(
|
50
|
+
RouteManager.box_delete_url(client[:address],client[:port],box,provider)
|
51
|
+
)
|
52
|
+
|
53
|
+
response = execute(client,DELETE_VERB,resource);
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
55
|
+
JSON.parse(response.to_str)
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
RouteManager.box_add_url(client[:address],client[:port]),
|
54
|
-
:timeout => -1
|
55
|
-
)
|
56
|
-
|
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
|
-
|
64
|
-
|
65
|
-
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.box_add(host,box,url,async=true)
|
60
|
+
client=get_host_parameters(host)
|
66
61
|
|
67
|
-
|
68
|
-
client
|
69
|
-
|
70
|
-
|
71
|
-
resource = RestClient::Resource.new(
|
72
|
-
RouteManager.vm_up_url(client[:address],client[:port]),
|
73
|
-
:timeout => -1
|
74
|
-
)
|
75
|
-
|
76
|
-
|
77
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
78
|
-
|
79
|
-
return JSON.parse(response.to_str) if async ==false
|
80
|
-
response
|
81
|
-
|
82
|
-
end
|
62
|
+
resource = RestClient::Resource.new(
|
63
|
+
RouteManager.box_add_url(client[:address],client[:port]),
|
64
|
+
:timeout => -1
|
65
|
+
)
|
83
66
|
|
84
|
-
def self.vm_halt(host,vmname,force,async=true)
|
85
|
-
client=get_host_parameters(host)
|
86
|
-
#Due to the fact that halting the machines can take long,
|
87
|
-
#setting the request not to expire
|
88
|
-
resource = RestClient::Resource.new(
|
89
|
-
RouteManager.vm_halt_url(client[:address],client[:port]),
|
90
|
-
:timeout => -1
|
91
|
-
)
|
92
|
-
|
93
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname,:force=>force},async);
|
94
|
-
return JSON.parse(response.to_str) if async ==false
|
95
|
-
response
|
96
|
-
|
97
|
-
end
|
98
67
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
resource = RestClient::Resource.new(
|
103
|
-
RouteManager.vm_destroy_url(client[:address],client[:port]),
|
104
|
-
:timeout => -1
|
105
|
-
)
|
106
|
-
|
107
|
-
|
108
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname});
|
109
|
-
|
110
|
-
JSON.parse(response.to_str)
|
111
|
-
|
112
|
-
end
|
68
|
+
response = execute(client,POST_VERB,resource,{:box => box,:url => url},async);
|
69
|
+
|
70
|
+
return JSON.parse(response.to_str) if async ==false
|
113
71
|
|
114
|
-
|
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
|
72
|
+
response
|
132
73
|
|
133
74
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
150
|
-
|
151
|
-
def self.vm_status(host,vmname)
|
152
|
-
client=get_host_parameters(host)
|
153
|
-
|
154
|
-
#get_vm_status(client[:address],client[:port],vmname)
|
155
|
-
get_vm_status(client,vmname)
|
156
|
-
|
157
|
-
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.vm_up(host,vmname,async=true)
|
78
|
+
client=get_host_parameters(host)
|
79
|
+
#Due to the fact that starting the machines can take long,
|
80
|
+
#setting the request not to expire
|
81
|
+
resource = RestClient::Resource.new(
|
82
|
+
RouteManager.vm_up_url(client[:address],client[:port]),
|
83
|
+
:timeout => -1
|
84
|
+
)
|
158
85
|
|
159
|
-
def self.vm_ssh_config(host,vmname)
|
160
|
-
client=get_host_parameters(host)
|
161
|
-
|
162
86
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
response = execute(client,GET_VERB,resource);
|
168
|
-
result=JSON.parse(response.to_str, {:symbolize_names => true})
|
169
|
-
|
170
|
-
|
171
|
-
#Change the target machine
|
172
|
-
result[:host]=client[:address]
|
173
|
-
|
174
|
-
result
|
175
|
-
end
|
87
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
88
|
+
|
89
|
+
return JSON.parse(response.to_str) if async ==false
|
90
|
+
response
|
176
91
|
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.vm_halt(host,vmname,force,async=true)
|
95
|
+
client=get_host_parameters(host)
|
96
|
+
#Due to the fact that halting the machines can take long,
|
97
|
+
#setting the request not to expire
|
98
|
+
resource = RestClient::Resource.new(
|
99
|
+
RouteManager.vm_halt_url(client[:address],client[:port]),
|
100
|
+
:timeout => -1
|
101
|
+
)
|
102
|
+
|
103
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname,:force=>force},async);
|
104
|
+
return JSON.parse(response.to_str) if async ==false
|
105
|
+
response
|
177
106
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
resource = RestClient::Resource.new(
|
183
|
-
RouteManager.vm_suspend_url(client[:address],client[:port]),
|
184
|
-
:timeout => -1
|
185
|
-
)
|
186
|
-
|
187
|
-
|
188
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
189
|
-
|
190
|
-
return JSON.parse(response.to_str) if async ==false
|
191
|
-
response
|
192
|
-
|
193
|
-
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.vm_destroy (host,vmname)
|
110
|
+
client=get_host_parameters(host)
|
194
111
|
|
195
|
-
|
196
|
-
client
|
197
|
-
|
198
|
-
|
199
|
-
resource = RestClient::Resource.new(
|
200
|
-
RouteManager.vm_resume_url(client[:address],client[:port]),
|
201
|
-
:timeout => -1
|
202
|
-
)
|
203
|
-
|
204
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
205
|
-
|
206
|
-
return JSON.parse(response.to_str) if async ==false
|
207
|
-
response
|
208
|
-
|
209
|
-
end
|
112
|
+
resource = RestClient::Resource.new(
|
113
|
+
RouteManager.vm_destroy_url(client[:address],client[:port]),
|
114
|
+
:timeout => -1
|
115
|
+
)
|
210
116
|
|
211
117
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
#setting the request not to expire
|
216
|
-
resource = RestClient::Resource.new(
|
217
|
-
RouteManager.vm_provision_url(client[:address],client[:port]),
|
218
|
-
:timeout => -1
|
219
|
-
)
|
220
|
-
|
221
|
-
|
222
|
-
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
223
|
-
|
224
|
-
return JSON.parse(response.to_str) if async ==false
|
225
|
-
response
|
226
|
-
|
227
|
-
end
|
118
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname});
|
119
|
+
|
120
|
+
JSON.parse(response.to_str)
|
228
121
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
122
|
+
end
|
123
|
+
|
124
|
+
#Deletes from the remote node config the machine with name 'vmname'
|
125
|
+
def self.vm_delete(host,vmname,remove=false)
|
126
|
+
client=get_host_parameters(host)
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
resource = RestClient::Resource.new(
|
131
|
+
RouteManager.vm_delete_url(client[:address],client[:port],vmname),:payload => { :remove => remove }
|
132
|
+
)
|
133
|
+
|
134
|
+
execute(client,DELETE_VERB,resource);
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def self.vm_add(host,config,rename=false)
|
140
|
+
client=get_host_parameters(host)
|
141
|
+
|
142
|
+
resource = RestClient::Resource.new(
|
143
|
+
RouteManager.vm_add_url(client[:address],client[:port]),
|
144
|
+
:timeout => -1 ,
|
145
|
+
# :payload => {
|
146
|
+
# :content_type => 'text/plain',
|
147
|
+
# :file => File.new(config, 'rb')
|
148
|
+
# }
|
149
|
+
)
|
150
|
+
|
151
|
+
execute(client,PUT_VERB,resource,{:file => File.read(config), :content_type => 'text/plain',:rename => rename})
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def self.vm_status(host,vmname)
|
157
|
+
client=get_host_parameters(host)
|
245
158
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
#setting the request not to expire
|
251
|
-
|
252
|
-
resource = RestClient::Resource.new(
|
253
|
-
RouteManager.vm_snapshot_take_url(client[:address],client[:port],vmname),
|
254
|
-
:timeout => -1,
|
255
|
-
)
|
159
|
+
#get_vm_status(client[:address],client[:port],vmname)
|
160
|
+
get_vm_status(client,vmname)
|
161
|
+
|
162
|
+
end
|
256
163
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
#JSON.parse(response.to_str,{:symbolize_names => true})
|
261
|
-
return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
|
262
|
-
response
|
263
|
-
|
264
|
-
end
|
164
|
+
def self.vm_info(host,vmname)
|
165
|
+
client=get_host_parameters(host)
|
265
166
|
|
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
167
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
168
|
+
resource = RestClient::Resource.new(
|
169
|
+
RouteManager.vm_info_url(client[:address],client[:port],vmname)
|
170
|
+
)
|
171
|
+
|
172
|
+
response = execute(client,GET_VERB,resource);
|
173
|
+
|
174
|
+
JSON.parse(response.to_str)
|
282
175
|
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
def self.vm_ssh_config(host,vmname)
|
181
|
+
client=get_host_parameters(host)
|
283
182
|
|
284
|
-
def self.vm_snapshot_restore(host,vmname,snapid,async=true)
|
285
|
-
|
286
|
-
client=get_host_parameters(host)
|
287
183
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
184
|
+
resource = RestClient::Resource.new(
|
185
|
+
RouteManager.vm_sshconfig_url(client[:address],client[:port],vmname)
|
186
|
+
)
|
187
|
+
|
188
|
+
response = execute(client,GET_VERB,resource);
|
189
|
+
result=JSON.parse(response.to_str, {:symbolize_names => true})
|
190
|
+
|
191
|
+
|
192
|
+
#Change the target machine
|
193
|
+
result[:host]=client[:address]
|
194
|
+
|
195
|
+
result
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
def self.vm_suspend(host,vmname,async=true)
|
200
|
+
client=get_host_parameters(host)
|
201
|
+
#Due to the fact that suspending the machines can take long,
|
202
|
+
#setting the request not to expire
|
203
|
+
resource = RestClient::Resource.new(
|
204
|
+
RouteManager.vm_suspend_url(client[:address],client[:port]),
|
205
|
+
:timeout => -1
|
206
|
+
)
|
207
|
+
|
208
|
+
|
209
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
210
|
+
|
211
|
+
return JSON.parse(response.to_str) if async ==false
|
212
|
+
response
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.vm_resume(host,vmname,async=true)
|
217
|
+
client=get_host_parameters(host)
|
218
|
+
#Due to the fact that resuming the machines can take long,
|
219
|
+
#setting the request not to expire
|
220
|
+
resource = RestClient::Resource.new(
|
221
|
+
RouteManager.vm_resume_url(client[:address],client[:port]),
|
222
|
+
:timeout => -1
|
223
|
+
)
|
224
|
+
|
225
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
226
|
+
|
227
|
+
return JSON.parse(response.to_str) if async ==false
|
228
|
+
response
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
def self.vm_provision(host,vmname,async=true)
|
234
|
+
client=get_host_parameters(host)
|
235
|
+
#Due to the fact that provisioning the machines can take long,
|
236
|
+
#setting the request not to expire
|
237
|
+
resource = RestClient::Resource.new(
|
238
|
+
RouteManager.vm_provision_url(client[:address],client[:port]),
|
239
|
+
:timeout => -1
|
240
|
+
)
|
241
|
+
|
242
|
+
|
243
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname},async);
|
244
|
+
|
245
|
+
return JSON.parse(response.to_str) if async ==false
|
246
|
+
response
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.get_remote_snapshots(host,vmname)
|
251
|
+
|
252
|
+
client=get_host_parameters(host)
|
253
|
+
|
254
|
+
resource = RestClient::Resource.new(
|
255
|
+
RouteManager.snapshot_list_url(client[:address],client[:port],vmname)
|
256
|
+
)
|
257
|
+
|
258
|
+
|
259
|
+
response = execute(client,GET_VERB,resource);
|
260
|
+
|
261
|
+
JSON.parse(response.to_str,{:symbolize_names => true})
|
262
|
+
# return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
|
263
|
+
# response
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.vm_snapshot_take(host,vmname,sname,sdesc,async=true)
|
268
|
+
client=get_host_parameters(host)
|
294
269
|
|
270
|
+
#Due to the fact that taking the snapshot can take long,
|
271
|
+
#setting the request not to expire
|
295
272
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
273
|
+
resource = RestClient::Resource.new(
|
274
|
+
RouteManager.vm_snapshot_take_url(client[:address],client[:port],vmname),
|
275
|
+
:timeout => -1,
|
276
|
+
)
|
277
|
+
|
278
|
+
|
279
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname,:name => sname,:desc => sdesc},async);
|
300
280
|
|
281
|
+
#JSON.parse(response.to_str,{:symbolize_names => true})
|
282
|
+
return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
|
283
|
+
response
|
301
284
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
285
|
+
end
|
286
|
+
|
287
|
+
def self.vm_snapshot_delete(host,vmname,snapid)
|
288
|
+
client=get_host_parameters(host)
|
289
|
+
|
290
|
+
#Due to the fact that deleting the snapshot can take long,
|
291
|
+
#setting the request not to expire
|
292
|
+
resource = RestClient::Resource.new(
|
293
|
+
RouteManager.vm_snapshot_delete_url(client[:address],client[:port],vmname,snapid),
|
294
|
+
:timeout => -1,
|
295
|
+
)
|
296
|
+
|
297
|
+
|
298
|
+
response = execute(client,DELETE_VERB,resource);
|
299
|
+
|
300
|
+
# JSON.parse(response.to_str,{:symbolize_names => true})
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
def self.vm_snapshot_restore(host,vmname,snapid,async=true)
|
306
|
+
|
307
|
+
client=get_host_parameters(host)
|
308
|
+
|
309
|
+
resource = RestClient::Resource.new(
|
310
|
+
RouteManager.vm_snapshot_restore_url(client[:address],client[:port],vmname),
|
311
|
+
:timeout => -1
|
312
|
+
)
|
312
313
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
314
|
+
response = execute(client,POST_VERB,resource,{:vmname => vmname,:snapid => snapid},async);
|
315
|
+
|
316
|
+
|
317
|
+
#JSON.parse(response.to_str,{:symbolize_names => true})
|
318
|
+
return JSON.parse(response.to_str,{:symbolize_names => true}) if async ==false
|
319
|
+
response
|
320
|
+
end
|
321
|
+
|
322
|
+
|
323
|
+
def self.node_operation_queued(host,id)
|
324
|
+
client=get_host_parameters(host)
|
325
|
+
resource = RestClient::Resource.new(
|
326
|
+
RouteManager.node_queue_url(client[:address],client[:port],id)
|
327
|
+
)
|
328
|
+
|
329
|
+
response = execute(client,GET_VERB,resource);
|
330
|
+
|
331
|
+
JSON.parse(response.to_str,{:symbolize_names => true})
|
332
|
+
end
|
333
|
+
|
334
|
+
def self.node_operation_queued_last(host)
|
335
|
+
client=get_host_parameters(host)
|
336
|
+
resource = RestClient::Resource.new(
|
337
|
+
RouteManager.node_queue_last_url(client[:address],client[:port])
|
338
|
+
)
|
339
|
+
|
340
|
+
response = execute(client,GET_VERB,resource);
|
341
|
+
|
342
|
+
JSON.parse(response.to_str,{:symbolize_names => true})
|
343
|
+
end
|
344
|
+
|
345
|
+
def self.node_backup_take(ui,target_dir,host=nil,vmname=nil)
|
346
|
+
|
347
|
+
current_client=nil
|
348
|
+
current_file = nil
|
349
|
+
download_backup = false
|
323
350
|
|
324
|
-
|
351
|
+
begin
|
325
352
|
|
326
|
-
|
327
|
-
|
328
|
-
download_backup =
|
353
|
+
raise "Directory \"#{target_dir}\" does not exists" if target_dir && !File.directory?(target_dir)
|
354
|
+
|
355
|
+
download_backup = true if target_dir
|
329
356
|
|
330
|
-
|
357
|
+
clients = []
|
358
|
+
if (host)
|
359
|
+
clients << get_host_parameters(host)
|
360
|
+
else
|
361
|
+
#FIXME QUITAR ESTO DE AQUI
|
362
|
+
#@dbmanager=DB::NodeDBManager.new if !@dbmanager
|
363
|
+
clients = DB::NodeDBManager.get_nodes
|
364
|
+
end
|
365
|
+
|
366
|
+
clients.each do |client|
|
367
|
+
current_client=client
|
368
|
+
#Fist get remote virtual machines
|
369
|
+
vms=get_vm_status(client,vmname)
|
331
370
|
|
332
|
-
raise "Directory \"#{target_dir}\" does not exists" if target_dir && !File.directory?(target_dir)
|
333
|
-
|
334
|
-
download_backup = true if target_dir
|
335
371
|
|
336
|
-
|
337
|
-
if (host)
|
338
|
-
clients << get_host_parameters(host)
|
339
|
-
else
|
340
|
-
#FIXME QUITAR ESTO DE AQUI
|
341
|
-
#@dbmanager=DB::NodeDBManager.new if !@dbmanager
|
342
|
-
clients = DB::NodeDBManager.get_nodes
|
343
|
-
end
|
344
|
-
|
345
|
-
clients.each do |client|
|
346
|
-
current_client=client
|
347
|
-
#Fist get remote virtual machines
|
348
|
-
vms=get_vm_status(client,vmname)
|
372
|
+
vms.each do |vm|
|
349
373
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
if (ui)
|
355
|
-
th = Thread.new(ui) do |ui|
|
356
|
-
draw_progress(ui,download_backup,client[:name],vm["name"])
|
357
|
-
end
|
374
|
+
th = nil
|
375
|
+
if (ui)
|
376
|
+
th = Thread.new(ui) do |ui|
|
377
|
+
draw_progress(ui,download_backup,client[:name],vm["name"])
|
358
378
|
end
|
359
|
-
|
379
|
+
end
|
380
|
+
|
360
381
|
|
361
382
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
383
|
+
resource = RestClient::Resource.new(
|
384
|
+
RouteManager.vm_snapshot_take_url(client[:address],client[:port],vm["name"]),
|
385
|
+
:download => download_backup,
|
386
|
+
:timeout => -1
|
387
|
+
)
|
388
|
+
|
389
|
+
#OLD. FIXME REMOVE
|
390
|
+
#response = resource.get({:params => {'download' => download_backup}})
|
391
|
+
response = execute(client,GET_VERB,resource,:params => {'download' => download_backup});
|
392
|
+
|
393
|
+
th.kill if th
|
394
|
+
|
395
|
+
if response.code==200
|
396
|
+
if download_backup && response.headers[:content_type]=="Application/octet-stream"
|
376
397
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
398
|
+
time = Time.now
|
399
|
+
|
400
|
+
basename = "Backup.#{client[:name]}.#{vm["name"]}.#{time.year}.#{time.month}.#{time.day}.#{time.hour}.#{time.min}.#{time.sec}"
|
401
|
+
current_file = "#{target_dir}/#{basename}.zip"
|
402
|
+
File.open(current_file, "w") do |f|
|
403
|
+
f.write(response.body)
|
404
|
+
end
|
405
|
+
|
406
|
+
current_file=""
|
407
|
+
#FIXME DELETE If we want to use the filename of the attachment
|
387
408
|
# if response.headers[:content_disposition] =~ /^attachment; filename=\"(.*?)\"$/
|
388
409
|
# current_file = "#{target_dir}/#{$1}"
|
389
410
|
# File.open(current_file, "w") do |f|
|
@@ -391,203 +412,222 @@ module Vagrant
|
|
391
412
|
# end
|
392
413
|
# current_file=""
|
393
414
|
# end
|
394
|
-
end
|
395
|
-
|
396
|
-
ui.success("OK") if ui
|
397
|
-
|
398
415
|
end
|
399
416
|
|
417
|
+
ui.success("OK") if ui
|
418
|
+
|
400
419
|
end
|
401
420
|
|
402
421
|
end
|
403
422
|
|
404
|
-
|
405
|
-
ui.error("Remote Client \"#{current_client[:name]}\": Box \"#{vmname}\" could not be found") if ui
|
406
|
-
rescue Exception => e
|
407
|
-
ui.error("ERROR: "+e.message) if ui
|
408
|
-
#Checking that the tmp file is removed
|
409
|
-
File.delete(current_file) if current_file && File.exists?(current_file)
|
410
|
-
end
|
423
|
+
end
|
411
424
|
|
412
|
-
|
425
|
+
rescue RestClient::ResourceNotFound => e
|
426
|
+
ui.error("Remote Client \"#{current_client[:name]}\": Box \"#{vmname}\" could not be found") if ui
|
427
|
+
rescue Exception => e
|
428
|
+
ui.error("ERROR: "+e.message) if ui
|
429
|
+
#Checking that the tmp file is removed
|
430
|
+
File.delete(current_file) if current_file && File.exists?(current_file)
|
431
|
+
end
|
413
432
|
|
414
|
-
|
415
|
-
|
416
|
-
raise "Error finding the node" if node==nil
|
417
|
-
|
418
|
-
client = get_host_parameters(node)
|
419
|
-
|
420
|
-
resource = RestClient::Resource.new(
|
421
|
-
RouteManager.backup_log_url(client[:address],client[:port],vmname),
|
422
|
-
:timeout => -1
|
423
|
-
)
|
433
|
+
end
|
424
434
|
|
425
|
-
|
426
|
-
|
427
|
-
response = execute(client,GET_VERB,resource,:vmname => vmname);
|
428
|
-
|
429
|
-
JSON.parse(response.to_str)
|
430
|
-
|
431
|
-
end
|
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
|
-
|
435
|
+
def self.node_backup_log(ui,node,vmname=nil)
|
448
436
|
|
437
|
+
raise "Error finding the node" if node==nil
|
449
438
|
|
450
|
-
|
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
|
-
|
477
|
-
|
478
|
-
private
|
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
|
439
|
+
client = get_host_parameters(node)
|
530
440
|
|
441
|
+
resource = RestClient::Resource.new(
|
442
|
+
RouteManager.backup_log_url(client[:address],client[:port],vmname),
|
443
|
+
:timeout => -1
|
444
|
+
)
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
response = execute(client,GET_VERB,resource,:vmname => vmname);
|
449
|
+
|
450
|
+
JSON.parse(response.to_str)
|
531
451
|
|
452
|
+
end
|
453
|
+
|
454
|
+
def self.node_info(node)
|
455
|
+
raise "Please enter a valid node" if node==nil
|
456
|
+
client=get_host_parameters(node)
|
457
|
+
|
458
|
+
resource = RestClient::Resource.new(
|
459
|
+
RouteManager.node_info_url(client[:address],client[:port]),:timeout => -1
|
460
|
+
)
|
461
|
+
|
462
|
+
response=execute(client,GET_VERB,resource);
|
463
|
+
|
532
464
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
465
|
+
|
466
|
+
JSON.parse(response.to_str,{:symbolize_names => true})
|
467
|
+
|
468
|
+
end
|
469
|
+
|
470
|
+
|
471
|
+
def self.node_config_show(node)
|
472
|
+
raise "Please enter a valid node" if node==nil
|
473
|
+
client=get_host_parameters(node)
|
474
|
+
|
475
|
+
|
476
|
+
resource = RestClient::Resource.new(
|
477
|
+
RouteManager.config_show_url(client[:address],client[:port]),:timeout => -1
|
478
|
+
)
|
479
|
+
|
480
|
+
|
481
|
+
execute(client,GET_VERB,resource);
|
482
|
+
|
483
|
+
end
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
def self.node_config_upload(node,config_path)
|
488
|
+
client=get_host_parameters(node)
|
489
|
+
|
490
|
+
|
491
|
+
resource = RestClient::Resource.new(
|
492
|
+
RouteManager.config_upload_url(client[:address],client[:port]),
|
493
|
+
:timeout => -1
|
494
|
+
)
|
495
|
+
|
496
|
+
execute(client,POST_VERB,resource,{:file => File.read(config_path), :content_type => 'text/plain'})
|
497
|
+
|
498
|
+
end
|
499
|
+
|
500
|
+
|
501
|
+
def self.node_password_change(node,password)
|
502
|
+
client=get_host_parameters(node)
|
503
|
+
|
504
|
+
|
505
|
+
resource = RestClient::Resource.new(
|
506
|
+
RouteManager.node_password_change_url(client[:address],client[:port]),:timeout => -1
|
507
|
+
)
|
508
|
+
|
509
|
+
execute(client,POST_VERB,resource,{:password => Digest::MD5.hexdigest(password)});
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
|
514
|
+
private
|
515
|
+
|
516
|
+
def self.execute(host,http_method,resource,params=nil,async=true)
|
517
|
+
client = login(host)
|
518
|
+
|
519
|
+
#FIXME AÑADIR AQUI GESTION DE ERRORES
|
520
|
+
#SI NO HAY COOKIE
|
521
|
+
#SI NO HAY TOKEN
|
522
|
+
#Y EnVIAR DESDE SERVeR ALGUNA EXECPCION
|
523
|
+
#PARA MONITORIZAR LA FALTA DE ALGUN PARAMETRO Y REPETIR LA TRANSACCION
|
524
|
+
resource.options[:headers] = { :content_md5 => CGI.escape(client[:token]),
|
525
|
+
:cookies => client[:cookies]
|
526
|
+
}
|
527
|
+
|
528
|
+
data= {}
|
529
|
+
|
530
|
+
data.merge!(params) if params!=nil
|
531
|
+
|
532
|
+
|
533
|
+
|
534
|
+
#response = resource.send http_method.to_sym, :content_md5 => client[:token], :cookies => client[:cookies]
|
535
|
+
|
536
|
+
response = resource.send http_method.to_sym, data
|
537
|
+
|
538
|
+
if response.code == 202 && async==false
|
539
|
+
#Getting the location operation id
|
540
|
+
opid = response.gsub!(/\D/, "")
|
541
|
+
|
542
|
+
begin
|
543
|
+
sleep SYNC_TIME
|
544
|
+
client1 = login(host)
|
545
|
+
resourceop = RestClient::Resource.new(
|
546
|
+
RouteManager.node_queue_url(client1[:address],client1[:port],opid)
|
547
|
+
)
|
548
|
+
|
549
|
+
resourceop.options[:headers] = { :content_md5 => CGI.escape(client1[:token]),
|
550
|
+
:cookies => client1[:cookies]
|
551
|
+
}
|
552
|
+
|
553
|
+
responseop = resourceop.send GET_VERB
|
554
|
+
|
555
|
+
res = JSON.parse(responseop.to_str)
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
end while (res[0].eql? "IN PROGRESS") #While operation code is IN PROGRESS iterate
|
560
|
+
|
561
|
+
res[1]
|
562
|
+
|
563
|
+
else
|
564
|
+
response
|
565
|
+
end
|
566
|
+
|
567
|
+
end
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
def self.login(host)
|
572
|
+
|
573
|
+
response = RestClient.get RouteManager.login_url(host[:address],host[:port])
|
574
|
+
|
575
|
+
host[:token] = Digest::MD5.hexdigest(response.headers[:content_md5]+host[:password])
|
576
|
+
host[:cookies] = response.cookies
|
577
|
+
|
578
|
+
host
|
579
|
+
end
|
580
|
+
|
581
|
+
def self.get_host_parameters(host)
|
582
|
+
|
583
|
+
#@dbmanager=DB::NodeDBManager.get_reference if !@dbmanager
|
584
|
+
DB::NodeDBManager.get_node(host)
|
585
|
+
|
586
|
+
end
|
587
|
+
|
588
|
+
def self.get_vm_status(client,vmname)
|
589
|
+
|
590
|
+
resource = RestClient::Resource.new(
|
591
|
+
RouteManager.vm_status_url(client[:address],client[:port],vmname)
|
592
|
+
)
|
593
|
+
|
594
|
+
response = execute(client,GET_VERB,resource);
|
595
|
+
|
596
|
+
JSON.parse(response.to_str)
|
542
597
|
|
543
|
-
|
598
|
+
end
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
def self.draw_progress(ui,download,node,vmname)
|
603
|
+
return if !ui
|
604
|
+
ui.info("Downloading ",:new_line => false) if download
|
605
|
+
ui.info("Waiting for ",:new_line => false) if !download
|
544
606
|
|
545
|
-
|
546
|
-
DB::NodeDBManager.get_node(host)
|
547
|
-
|
548
|
-
end
|
607
|
+
ui.info("backup of Virtual Machine \'#{vmname}\' from Node \'#{node}\' . . . ",:new_line => false)
|
549
608
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
RouteManager.vm_status_url(client[:address],client[:port],vmname)
|
554
|
-
)
|
609
|
+
val=0
|
610
|
+
while true
|
611
|
+
sleep(0.1)
|
555
612
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
ui.info("Waiting for ",:new_line => false) if !download
|
566
|
-
|
567
|
-
ui.info("backup of Virtual Machine \'#{vmname}\' from Node \'#{node}\' . . . ",:new_line => false)
|
568
|
-
|
569
|
-
val=0
|
570
|
-
while true
|
571
|
-
sleep(0.1)
|
572
|
-
|
573
|
-
case val
|
574
|
-
when 0 then
|
575
|
-
ui.info("|\b",:new_line => false)
|
576
|
-
when 1 then
|
577
|
-
ui.info("/\b",:new_line => false)
|
578
|
-
when 2 then
|
579
|
-
ui.info("-\b",:new_line => false)
|
580
|
-
when 3 then
|
581
|
-
ui.info("\\\b",:new_line => false)
|
582
|
-
end
|
583
|
-
val=val+1
|
584
|
-
|
585
|
-
val=0 if val==4
|
613
|
+
case val
|
614
|
+
when 0 then
|
615
|
+
ui.info("|\b",:new_line => false)
|
616
|
+
when 1 then
|
617
|
+
ui.info("/\b",:new_line => false)
|
618
|
+
when 2 then
|
619
|
+
ui.info("-\b",:new_line => false)
|
620
|
+
when 3 then
|
621
|
+
ui.info("\\\b",:new_line => false)
|
586
622
|
end
|
623
|
+
val=val+1
|
624
|
+
|
625
|
+
val=0 if val==4
|
587
626
|
end
|
588
|
-
|
589
|
-
|
590
627
|
end
|
591
|
-
|
628
|
+
|
629
|
+
|
630
|
+
end
|
631
|
+
end
|
592
632
|
end
|
593
633
|
|