Commit 65a8b1da authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Implement OScompute_v2 servers/?/metadata/? calls

Refs: #4139
parent dbcbf446
......@@ -171,7 +171,10 @@ class ComputeRestClient(Client):
path = path4url('servers')
return self.post(path, data=json_data, success=success, **kwargs)
def servers_put(self, server_id, json_data=None, success=204, **kwargs):
def servers_put(
self,
server_id, server_name=None, json_data=None, success=204,
**kwargs):
"""PUT base_url/servers/<server_id>
:param json_data: a json-formated dict that will be send as data
......@@ -182,6 +185,8 @@ class ComputeRestClient(Client):
:returns: request response
"""
self.set_param('server', server_name, iff=server_name)
if json_data:
json_data = json.dumps(json_data)
self.set_header('Content-Type', 'application/json')
......@@ -203,15 +208,49 @@ class ComputeRestClient(Client):
path = path4url('servers', server_id)
return self.delete(path, success=success, **kwargs)
def servers_metadata_get(self, server_id, key=None, success=200, **kwargs):
"""GET base_url/servers/<server_id>/metadata[/key]
:returns: request response
"""
path = path4url('servers', server_id, 'metadata', key or '')
return self.get(path, success=success, **kwargs)
def servers_metadata_post(
self, server_id, json_data=None, success=202, **kwargs):
"""POST base_url/servers/<server_id>/metadata
: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, 'metadata')
return self.post(path, data=json_data, success=success, **kwargs)
def servers_metadata_put(
self, server_id, key=None, json_data=None, success=204, **kwargs):
"""PUT base_url/servers/<server_id>/metadata[/key]
: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, 'metadata', key or '')
return self.put(path, data=json_data, success=success, **kwargs)
def servers_metadata_delete(self, server_id, key, success=204, **kwargs):
"""DEL ETE base_url/servers/<server_id>/metadata[/key]
:returns: request response
"""
path = path4url('servers', server_id, 'metadata', key)
return self.delete(path, success=success, **kwargs)
"""
def servers_get
def servers_post
def servers_put
def servers_delete
def servers_metadata_get
def servers_metadata_post
def servers_metadata_put
def servers_metadata_delete
def servers_actions_post
def servers_ips_get
"""
......@@ -231,11 +270,10 @@ class ComputeRestClient(Client):
:returns: request response
""
path = path4url('servers', server_id, command)
return self.get(path, success=success, **kwargs)
"""
""
def servers_delete(self, server_id='', command='', success=204, **kwargs):
"""DEL ETE base_url/servers[/server_id][/command] request
""DEL ETE base_url/servers[/server_id][/command] request
:param server_id: integer (as int or str)
......@@ -246,11 +284,10 @@ class ComputeRestClient(Client):
raises
:returns: request response
"""
""
path = path4url('servers', server_id, command)
return self.delete(path, success=success, **kwargs)
"""
def servers_post(
self,
server_id='',
......
......@@ -61,10 +61,6 @@ class CycladesClient(CycladesRestClient):
:raises ClientError: wraps request errors
"""
req = {'server': {'name': name,
'flavorRef': flavor_id,
'imageRef': image_id}}
image = self.get_image_details(image_id)
metadata = metadata or dict()
for key in ('os', 'users'):
......@@ -72,27 +68,10 @@ class CycladesClient(CycladesRestClient):
metadata[key] = image['metadata'][key]
except KeyError:
pass
if metadata:
req['server']['metadata'] = metadata
if personality:
req['server']['personality'] = personality
try:
r = self.servers_post(json_data=req)
except ClientError as err:
try:
if isinstance(err.details, list):
tmp_err = err.details
else:
errd = '%s' % err.details
tmp_err = errd.split(',')
tmp_err = tmp_err[0].split(':')
tmp_err = tmp_err[2].split('"')
err.message = tmp_err[1]
finally:
raise err
return r.json['server']
return super(CycladesClient, self).create_server(
name, flavor_id, image_id,
metadata=metadata, personality=personality)
def start_server(self, server_id):
"""Submit a startup request
......@@ -163,8 +142,7 @@ class CycladesClient(CycladesRestClient):
:returns: list of server ids and names
"""
detail = 'detail' if detail else ''
r = self.servers_get(command=detail, changes_since=changes_since)
r = self.servers_get(detail=bool(detail), changes_since=changes_since)
return r.json['servers']
def list_server_nics(self, server_id):
......
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