Commit ef2e6c9f authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Implement servers/?/action/? ReST and methods

Refs: #4139
parent 0b179c69
......@@ -175,15 +175,33 @@ class ComputeClient(ComputeRestClient):
r = self.servers_delete(server_id)
return r.headers
def change_admin_password(self, server_id, new_password):
"""
:param server_id: (int)
:param new_password: (str)
"""
req = {"changePassword": {"adminPass": new_password}}
r = self.servers_action_post(server_id, json_data=req)
return r.headers
def rebuild_server(self, server_id, response_headers=dict(location=None)):
"""OS"""
server = self.get_server_details(server_id)
r = self.servers_action_post(
server_id, json_data=dict(rebuild=server['server']))
for k, v in response_headers.items():
response_headers[k] = r.headers.get(k, v)
return r.json['server']
def reboot_server(self, server_id, hard=False):
"""
:param server_id: integer (str or int)
:param hard: perform a hard reboot if true, soft reboot otherwise
"""
boot_type = 'HARD' if hard else 'SOFT'
req = {'reboot': {'type': boot_type}}
r = self.servers_post(server_id, 'action', json_data=req)
req = {'reboot': {'type': 'HARD' if hard else 'SOFT'}}
r = self.servers_action_post(server_id, json_data=req)
return r.headers
def resize_server(self, server_id, flavor_id):
......@@ -195,7 +213,37 @@ class ComputeClient(ComputeRestClient):
:returns: (dict) request headers
"""
req = {'resize': {'flavorRef': flavor_id}}
r = self.servers_post(server_id, 'action', json_data=req)
r = self.servers_action_post(server_id, json_data=req)
return r.headers
def confirm_resize_server(self, server_id):
"""OS"""
r = self.servers_action_post(
server_id, json_data=dict(confirmResize=None))
return r.headers
def revert_resize_server(self, server_id):
"""OS"""
r = self.servers_action_post(
server_id, json_data=dict(revertResize=None))
return r.headers
def create_server_image(self, server_id, image_name, **metadata):
"""OpenStack method for taking snapshots"""
req = dict(createImage=dict(name=image_name, metadata=metadata))
r = self.servers_action_post(server_id, json_data=req)
return r.headers['location']
def start_server(self, server_id):
"""OS Extentions"""
req = {'os-start': None}
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def shutdown_server(self, server_id):
"""OS Extentions"""
req = {'os-stop': None}
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def get_server_metadata(self, server_id, key='', response_headers=dict(
......
......@@ -250,12 +250,23 @@ class ComputeRestClient(Client):
path = path4url('servers', server_id, 'metadata', key)
return self.delete(path, success=success, **kwargs)
def servers_actions_post(
self, server_id, json_data=None, success=202, **kwargs):
"""POST base_url/servers/<server_id>/action
:returns: request response
"""
if json_data:
json_data = json.dumps(json_data)
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Length', len(json_data))
path = path4url('servers', server_id, 'action')
return self.post(path, data=json_data, success=success, **kwargs)
"""
def servers_actions_post
def servers_ips_get
"""
"""
def servers_get(self, server_id='', command='', success=200, **kwargs):
""GET base_url/servers[/server_id][/command] request
......@@ -270,23 +281,6 @@ class ComputeRestClient(Client):
:returns: request response
""
path = path4url('servers', server_id, command)
""
def servers_delete(self, server_id='', command='', success=204, **kwargs):
""DEL ETE base_url/servers[/server_id][/command] request
:param server_id: integer (as int or str)
:param command: 'ips', 'stats', or ''
:param success: success code or list or tupple of accepted success
codes. if server response code is not in this list, a ClientError
raises
:returns: request response
""
path = path4url('servers', server_id, command)
return self.delete(path, success=success, **kwargs)
def servers_post(
self,
......@@ -317,36 +311,6 @@ class ComputeRestClient(Client):
path = path4url('servers', server_id, command)
return self.post(path, data=data, success=success, **kwargs)
def servers_put(
self,
server_id='',
command='',
json_data=None,
success=204,
**kwargs):
""PUT base_url/servers[/server_id]/[command] request
:param server_id: integer (as int or str)
:param command: 'ips', 'stats', or ''
:param json_data: a json-formated dict that will be send as data
:param success: success code or list or tupple of accepted success
codes. if server response code is not in this list, a ClientError
raises
:returns: request response
""
data = json_data
if json_data is not None:
data = json.dumps(json_data)
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Length', len(data))
path = path4url('servers', server_id, command)
return self.put(path, data=data, success=success, **kwargs)
"""
def flavors_get(self, flavor_id='', command='', success=200, **kwargs):
......
......@@ -81,7 +81,7 @@ class CycladesClient(CycladesRestClient):
:returns: (dict) response headers
"""
req = {'start': {}}
r = self.servers_post(server_id, 'action', json_data=req, success=202)
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def shutdown_server(self, server_id):
......@@ -92,7 +92,7 @@ class CycladesClient(CycladesRestClient):
:returns: (dict) response headers
"""
req = {'shutdown': {}}
r = self.servers_post(server_id, 'action', json_data=req, success=202)
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def get_server_console(self, server_id):
......@@ -102,7 +102,7 @@ class CycladesClient(CycladesRestClient):
:returns: (dict) info to set a VNC connection to VM
"""
req = {'console': {'type': 'vnc'}}
r = self.servers_post(server_id, 'action', json_data=req, success=200)
r = self.servers_action_post(server_id, json_data=req, success=200)
return r.json['console']
def get_firewall_profile(self, server_id):
......@@ -131,7 +131,7 @@ class CycladesClient(CycladesRestClient):
:returns: (dict) response headers
"""
req = {'firewallProfile': {'profile': profile}}
r = self.servers_post(server_id, 'action', json_data=req, success=202)
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def list_servers(self, detail=False, changes_since=None):
......@@ -463,9 +463,8 @@ class CycladesClient(CycladesRestClient):
"""
server_id = int(server_id)
assert address, 'address is needed for attach_floating_ip'
r = self.servers_post(
server_id, 'action',
json_data=dict(addFloatingIp=dict(address=address)))
req = dict(addFloatingIp=dict(address=address))
r = self.servers_action_post(server_id, json_data=req)
return r.headers
def detach_floating_ip(self, server_id, address):
......@@ -485,7 +484,6 @@ class CycladesClient(CycladesRestClient):
"""
server_id = int(server_id)
assert address, 'address is needed for detach_floating_ip'
r = self.servers_post(
server_id, 'action',
json_data=dict(removeFloatingIp=dict(address=address)))
req = dict(removeFloatingIp=dict(address=address))
r = self.servers_action_post(server_id, json_data=req)
return r.headers
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment