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

Add since arg in server_list

parent 3fe56be4
......@@ -69,7 +69,10 @@ class server_list(_init_cyclades):
"""List servers"""
arguments = dict(
detail=FlagArgument('show detailed output', '-l')
detail=FlagArgument('show detailed output', '-l'),
since=ValueArgument(
'show only items since date (\' d/m/Y H:M:S \')',
'--since')
)
def _info_print(self, server):
......@@ -98,8 +101,14 @@ class server_list(_init_cyclades):
def main(self):
super(self.__class__, self).main()
try:
servers = self.client.list_servers(self['detail'])
servers = self.client.list_servers(self['detail'], self['since'])
self._print(servers)
except ClientError as ce:
if ce.status == 400 and 'changes-since' in ('%s' % ce):
raiseCLIError(None,
'Incorrect date format for --since',
details=['Accepted date format: d/m/y'])
raiseCLIError(ce)
except Exception as err:
raiseCLIError(err)
......
......@@ -93,6 +93,18 @@ class CycladesClient(CycladesClientApi):
r = self.servers_post(server_id, 'action', json_data=req, success=202)
r.release()
def list_servers(self, detail=False, changes_since=None):
"""
:param detail: (bool) append full server details to each item if true
:param changes_since: (date)
:returns: list of server ids and names
"""
detail = 'detail' if detail else ''
r = self.servers_get(command=detail, changes_since=changes_since)
return r.json['servers']['values']
def list_server_nics(self, server_id):
"""
:param server_id: integer (str or int)
......
......@@ -39,6 +39,30 @@ import json
class CycladesClientApi(ComputeClient):
"""GRNet Cyclades REST API Client"""
def servers_get(self,
server_id='',
command='',
success=200,
changes_since=None,
**kwargs):
"""GET 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
:param changes_since: (date)
:returns: request response
"""
path = path4url('servers', server_id, command)
self.set_param('changes-since', changes_since, changes_since)
return self.get(path, success=success, **kwargs)
def networks_get(self,
network_id='', command='', success=(200, 203), **kwargs):
"""GET base_url/networks[/network_id][/command] request
......
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