Add since arg in server_list
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 3 Jan 2013 16:23:10 +0000 (18:23 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 3 Jan 2013 16:23:10 +0000 (18:23 +0200)
kamaki/cli/commands/cyclades_cli.py
kamaki/clients/cyclades.py
kamaki/clients/cyclades_rest_api.py

index db223ec..68e157b 100644 (file)
@@ -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)
 
index 84374e9..6e8604b 100644 (file)
@@ -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)
index f316806..e814f6a 100644 (file)
@@ -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