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

Implement OSv2 compute 1st level /servers calls

Refs: #4139
parent 703d7a77
......@@ -38,8 +38,187 @@ import json
class ComputeRestClient(Client):
# NON-cyclades
def limits_get(self, success=200, **kwargs):
"""GET base_url/limits
: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('limits')
return self.get(path, success=success, **kwargs)
def servers_get(
self,
server_id='', detail=False,
changes_since=None,
image=None,
flavor=None,
name=None,
marker=None,
limit=None,
status=None,
host=None,
success=200,
**kwargs):
"""GET base_url/servers/['detail'|<server_id>]
:param server_id: (int or int str) ignored if detail
:param detail: (boolean)
--- Parameters ---
:param changes-since: A time/date stamp for when the server last
changed status
:param image: Name of the image in URL format
:param flavor: Name of the flavor in URL format
:param name: Name of the server as a string
:param marker: UUID of the server at which you want to set a marker
:param limit: (int) limit of values to return
:param status: Status of the server (e.g. filter on "ACTIVE")
:param host: Name of the host as a string
:returns: request response
"""
if not server_id:
self.set_param('changes-since', changes_since, iff=changes_since)
self.set_param('image', image, iff=image)
self.set_param('flavor', flavor, iff=flavor)
self.set_param('name', name, iff=name)
self.set_param('marker', marker, iff=marker)
self.set_param('limit', limit, iff=limit)
self.set_param('status', status, iff=status)
self.set_param('host', host, iff=host)
path = path4url('servers', 'detail' if detail else server_id)
return self.get(path, success=success, **kwargs)
def servers_post(
self,
security_group=None,
user_data=None,
availability_zone=None,
server=None,
imageRef=None,
flavorRef=None,
name=None,
metadata=None,
personality=None,
json_data=None,
success=202,
**kwargs):
"""POST base_url/servers
:param json_data: a json-formated dict that will be send as data
--- Parameters
:param security_group: (str)
:param user_data: Use to pass configuration information or scripts upon
launch. Must be Base64 encoded.
:param availability_zone: (str)
:param server: Server
:param imageRef: ID or full URL.
:param flavorRef: ID or full URL.
:param name: (str) The name of the new server
:param metadata: (dict) Metadata key: value pairs. max size of the key
and value is 255 bytes each.
:param personality: (str) File path and contents (text only) to inject
into the server at launch. The maximum size of the file path data
is 255 bytes. The maximum limit refers to the number of bytes in
the decoded data and not the number of characters in the encoded
data.
:returns: request response
"""
self.set_param(security_group, security_group, iff=security_group)
self.set_param(user_data, user_data, iff=user_data)
self.set_param(
availability_zone, availability_zone, iff=availability_zone)
self.set_param(server, server, iff=server)
self.set_param(imageRef, imageRef, iff=imageRef)
self.set_param(flavorRef, flavorRef, iff=flavorRef)
self.set_param(name, name, iff=name)
if metadata: # don't json.dump None
self.set_param(metadata, json.dumps(metadata))
self.set_param(personality, personality, iff=personality)
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')
return self.post(path, data=json_data, success=success, **kwargs)
def servers_put(self, server_id, 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
:param success: success code (iterable of) codes
:raises ClientError: if returned code not in success list
: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)
return self.put(path, data=json_data, success=success, **kwargs)
def servers_delete(self, server_id, success=204, **kwargs):
"""DEL ETE base_url/servers/<server_id>
:param json_data: a json-formated dict that will be send as data
:param success: success code (iterable of) codes
:raises ClientError: if returned code not in success list
:returns: request response
"""
path = path4url('servers', server_id)
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
"""
"""
def servers_get(self, server_id='', command='', success=200, **kwargs):
"""GET base_url/servers[/server_id][/command] request
""GET base_url/servers[/server_id][/command] request
:param server_id: integer (as int or str)
......@@ -50,9 +229,10 @@ class ComputeRestClient(Client):
raises
: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
......@@ -70,6 +250,7 @@ class ComputeRestClient(Client):
path = path4url('servers', server_id, command)
return self.delete(path, success=success, **kwargs)
"""
def servers_post(
self,
server_id='',
......@@ -77,7 +258,7 @@ class ComputeRestClient(Client):
json_data=None,
success=202,
**kwargs):
"""POST base_url/servers[/server_id]/[command] request
""POST base_url/servers[/server_id]/[command] request
:param server_id: integer (as int or str)
......@@ -90,7 +271,7 @@ class ComputeRestClient(Client):
raises
:returns: request response
"""
""
data = json_data
if json_data:
data = json.dumps(json_data)
......@@ -107,7 +288,7 @@ class ComputeRestClient(Client):
json_data=None,
success=204,
**kwargs):
"""PUT base_url/servers[/server_id]/[command] request
""PUT base_url/servers[/server_id]/[command] request
:param server_id: integer (as int or str)
......@@ -120,7 +301,7 @@ class ComputeRestClient(Client):
raises
:returns: request response
"""
""
data = json_data
if json_data is not None:
data = json.dumps(json_data)
......@@ -129,6 +310,7 @@ class ComputeRestClient(Client):
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):
"""GET base_url[/flavor_id][/command]
......
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