Revision ef2e6c9f
b/kamaki/clients/compute/__init__.py | ||
---|---|---|
175 | 175 |
r = self.servers_delete(server_id) |
176 | 176 |
return r.headers |
177 | 177 |
|
178 |
def change_admin_password(self, server_id, new_password): |
|
179 |
""" |
|
180 |
:param server_id: (int) |
|
181 |
|
|
182 |
:param new_password: (str) |
|
183 |
""" |
|
184 |
req = {"changePassword": {"adminPass": new_password}} |
|
185 |
r = self.servers_action_post(server_id, json_data=req) |
|
186 |
return r.headers |
|
187 |
|
|
188 |
def rebuild_server(self, server_id, response_headers=dict(location=None)): |
|
189 |
"""OS""" |
|
190 |
server = self.get_server_details(server_id) |
|
191 |
r = self.servers_action_post( |
|
192 |
server_id, json_data=dict(rebuild=server['server'])) |
|
193 |
for k, v in response_headers.items(): |
|
194 |
response_headers[k] = r.headers.get(k, v) |
|
195 |
return r.json['server'] |
|
196 |
|
|
178 | 197 |
def reboot_server(self, server_id, hard=False): |
179 | 198 |
""" |
180 | 199 |
:param server_id: integer (str or int) |
181 | 200 |
|
182 | 201 |
:param hard: perform a hard reboot if true, soft reboot otherwise |
183 | 202 |
""" |
184 |
boot_type = 'HARD' if hard else 'SOFT' |
|
185 |
req = {'reboot': {'type': boot_type}} |
|
186 |
r = self.servers_post(server_id, 'action', json_data=req) |
|
203 |
req = {'reboot': {'type': 'HARD' if hard else 'SOFT'}} |
|
204 |
r = self.servers_action_post(server_id, json_data=req) |
|
187 | 205 |
return r.headers |
188 | 206 |
|
189 | 207 |
def resize_server(self, server_id, flavor_id): |
... | ... | |
195 | 213 |
:returns: (dict) request headers |
196 | 214 |
""" |
197 | 215 |
req = {'resize': {'flavorRef': flavor_id}} |
198 |
r = self.servers_post(server_id, 'action', json_data=req) |
|
216 |
r = self.servers_action_post(server_id, json_data=req) |
|
217 |
return r.headers |
|
218 |
|
|
219 |
def confirm_resize_server(self, server_id): |
|
220 |
"""OS""" |
|
221 |
r = self.servers_action_post( |
|
222 |
server_id, json_data=dict(confirmResize=None)) |
|
223 |
return r.headers |
|
224 |
|
|
225 |
def revert_resize_server(self, server_id): |
|
226 |
"""OS""" |
|
227 |
r = self.servers_action_post( |
|
228 |
server_id, json_data=dict(revertResize=None)) |
|
229 |
return r.headers |
|
230 |
|
|
231 |
def create_server_image(self, server_id, image_name, **metadata): |
|
232 |
"""OpenStack method for taking snapshots""" |
|
233 |
req = dict(createImage=dict(name=image_name, metadata=metadata)) |
|
234 |
r = self.servers_action_post(server_id, json_data=req) |
|
235 |
return r.headers['location'] |
|
236 |
|
|
237 |
def start_server(self, server_id): |
|
238 |
"""OS Extentions""" |
|
239 |
req = {'os-start': None} |
|
240 |
r = self.servers_action_post(server_id, json_data=req, success=202) |
|
241 |
return r.headers |
|
242 |
|
|
243 |
def shutdown_server(self, server_id): |
|
244 |
"""OS Extentions""" |
|
245 |
req = {'os-stop': None} |
|
246 |
r = self.servers_action_post(server_id, json_data=req, success=202) |
|
199 | 247 |
return r.headers |
200 | 248 |
|
201 | 249 |
def get_server_metadata(self, server_id, key='', response_headers=dict( |
b/kamaki/clients/compute/rest_api.py | ||
---|---|---|
250 | 250 |
path = path4url('servers', server_id, 'metadata', key) |
251 | 251 |
return self.delete(path, success=success, **kwargs) |
252 | 252 |
|
253 |
def servers_actions_post( |
|
254 |
self, server_id, json_data=None, success=202, **kwargs): |
|
255 |
"""POST base_url/servers/<server_id>/action |
|
256 |
|
|
257 |
:returns: request response |
|
258 |
""" |
|
259 |
if json_data: |
|
260 |
json_data = json.dumps(json_data) |
|
261 |
self.set_header('Content-Type', 'application/json') |
|
262 |
self.set_header('Content-Length', len(json_data)) |
|
263 |
path = path4url('servers', server_id, 'action') |
|
264 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
265 |
|
|
253 | 266 |
""" |
254 | 267 |
def servers_actions_post |
255 | 268 |
def servers_ips_get |
256 |
""" |
|
257 | 269 |
|
258 |
""" |
|
259 | 270 |
def servers_get(self, server_id='', command='', success=200, **kwargs): |
260 | 271 |
""GET base_url/servers[/server_id][/command] request |
261 | 272 |
|
... | ... | |
270 | 281 |
:returns: request response |
271 | 282 |
"" |
272 | 283 |
path = path4url('servers', server_id, command) |
273 |
"" |
|
274 |
|
|
275 |
def servers_delete(self, server_id='', command='', success=204, **kwargs): |
|
276 |
""DEL ETE base_url/servers[/server_id][/command] request |
|
277 |
|
|
278 |
:param server_id: integer (as int or str) |
|
279 |
|
|
280 |
:param command: 'ips', 'stats', or '' |
|
281 |
|
|
282 |
:param success: success code or list or tupple of accepted success |
|
283 |
codes. if server response code is not in this list, a ClientError |
|
284 |
raises |
|
285 |
|
|
286 |
:returns: request response |
|
287 |
"" |
|
288 |
path = path4url('servers', server_id, command) |
|
289 |
return self.delete(path, success=success, **kwargs) |
|
290 | 284 |
|
291 | 285 |
def servers_post( |
292 | 286 |
self, |
... | ... | |
317 | 311 |
|
318 | 312 |
path = path4url('servers', server_id, command) |
319 | 313 |
return self.post(path, data=data, success=success, **kwargs) |
320 |
|
|
321 |
def servers_put( |
|
322 |
self, |
|
323 |
server_id='', |
|
324 |
command='', |
|
325 |
json_data=None, |
|
326 |
success=204, |
|
327 |
**kwargs): |
|
328 |
""PUT base_url/servers[/server_id]/[command] request |
|
329 |
|
|
330 |
:param server_id: integer (as int or str) |
|
331 |
|
|
332 |
:param command: 'ips', 'stats', or '' |
|
333 |
|
|
334 |
:param json_data: a json-formated dict that will be send as data |
|
335 |
|
|
336 |
:param success: success code or list or tupple of accepted success |
|
337 |
codes. if server response code is not in this list, a ClientError |
|
338 |
raises |
|
339 |
|
|
340 |
:returns: request response |
|
341 |
"" |
|
342 |
data = json_data |
|
343 |
if json_data is not None: |
|
344 |
data = json.dumps(json_data) |
|
345 |
self.set_header('Content-Type', 'application/json') |
|
346 |
self.set_header('Content-Length', len(data)) |
|
347 |
|
|
348 |
path = path4url('servers', server_id, command) |
|
349 |
return self.put(path, data=data, success=success, **kwargs) |
|
350 | 314 |
""" |
351 | 315 |
|
352 | 316 |
def flavors_get(self, flavor_id='', command='', success=200, **kwargs): |
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
81 | 81 |
:returns: (dict) response headers |
82 | 82 |
""" |
83 | 83 |
req = {'start': {}} |
84 |
r = self.servers_post(server_id, 'action', json_data=req, success=202)
|
|
84 |
r = self.servers_action_post(server_id, json_data=req, success=202)
|
|
85 | 85 |
return r.headers |
86 | 86 |
|
87 | 87 |
def shutdown_server(self, server_id): |
... | ... | |
92 | 92 |
:returns: (dict) response headers |
93 | 93 |
""" |
94 | 94 |
req = {'shutdown': {}} |
95 |
r = self.servers_post(server_id, 'action', json_data=req, success=202)
|
|
95 |
r = self.servers_action_post(server_id, json_data=req, success=202)
|
|
96 | 96 |
return r.headers |
97 | 97 |
|
98 | 98 |
def get_server_console(self, server_id): |
... | ... | |
102 | 102 |
:returns: (dict) info to set a VNC connection to VM |
103 | 103 |
""" |
104 | 104 |
req = {'console': {'type': 'vnc'}} |
105 |
r = self.servers_post(server_id, 'action', json_data=req, success=200)
|
|
105 |
r = self.servers_action_post(server_id, json_data=req, success=200)
|
|
106 | 106 |
return r.json['console'] |
107 | 107 |
|
108 | 108 |
def get_firewall_profile(self, server_id): |
... | ... | |
131 | 131 |
:returns: (dict) response headers |
132 | 132 |
""" |
133 | 133 |
req = {'firewallProfile': {'profile': profile}} |
134 |
r = self.servers_post(server_id, 'action', json_data=req, success=202)
|
|
134 |
r = self.servers_action_post(server_id, json_data=req, success=202)
|
|
135 | 135 |
return r.headers |
136 | 136 |
|
137 | 137 |
def list_servers(self, detail=False, changes_since=None): |
... | ... | |
463 | 463 |
""" |
464 | 464 |
server_id = int(server_id) |
465 | 465 |
assert address, 'address is needed for attach_floating_ip' |
466 |
r = self.servers_post( |
|
467 |
server_id, 'action', |
|
468 |
json_data=dict(addFloatingIp=dict(address=address))) |
|
466 |
req = dict(addFloatingIp=dict(address=address)) |
|
467 |
r = self.servers_action_post(server_id, json_data=req) |
|
469 | 468 |
return r.headers |
470 | 469 |
|
471 | 470 |
def detach_floating_ip(self, server_id, address): |
... | ... | |
485 | 484 |
""" |
486 | 485 |
server_id = int(server_id) |
487 | 486 |
assert address, 'address is needed for detach_floating_ip' |
488 |
r = self.servers_post( |
|
489 |
server_id, 'action', |
|
490 |
json_data=dict(removeFloatingIp=dict(address=address))) |
|
487 |
req = dict(removeFloatingIp=dict(address=address)) |
|
488 |
r = self.servers_action_post(server_id, json_data=req) |
|
491 | 489 |
return r.headers |
Also available in: Unified diff