Remove links from simple listing
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 19 Jun 2013 14:56:38 +0000 (17:56 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 19 Jun 2013 14:56:38 +0000 (17:56 +0300)
kamaki/cli/commands/cyclades.py
kamaki/cli/utils.py

index 507fe7d..34a2f2e 100644 (file)
@@ -33,7 +33,7 @@
 
 from kamaki.cli import command
 from kamaki.cli.command_tree import CommandTree
 
 from kamaki.cli import command
 from kamaki.cli.command_tree import CommandTree
-from kamaki.cli.utils import print_dict
+from kamaki.cli.utils import print_dict, remove_from_items
 from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
 from kamaki.clients.cyclades import CycladesClient, ClientError
 from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
 from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
 from kamaki.clients.cyclades import CycladesClient, ClientError
 from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
@@ -118,6 +118,8 @@ class server_list(_init_cyclades, _optional_json):
     @errors.cyclades.date
     def _run(self):
         servers = self.client.list_servers(self['detail'], self['since'])
     @errors.cyclades.date
     def _run(self):
         servers = self.client.list_servers(self['detail'], self['since'])
+        if not (self['detail'] or self['json_output']):
+            remove_from_items(servers, 'links')
 
         kwargs = dict(with_enumeration=self['enum'])
         if self['more']:
 
         kwargs = dict(with_enumeration=self['enum'])
         if self['more']:
@@ -527,6 +529,8 @@ class flavor_list(_init_cyclades, _optional_json):
     @errors.cyclades.connection
     def _run(self):
         flavors = self.client.list_flavors(self['detail'])
     @errors.cyclades.connection
     def _run(self):
         flavors = self.client.list_flavors(self['detail'])
+        if not (self['detail'] or self['json_output']):
+            remove_from_items(flavors, 'links')
         pg_size = 10 if self['more'] and not self['limit'] else self['limit']
         self._print(
             flavors,
         pg_size = 10 if self['more'] and not self['limit'] else self['limit']
         self._print(
             flavors,
@@ -592,6 +596,8 @@ class network_list(_init_cyclades, _optional_json):
     @errors.cyclades.connection
     def _run(self):
         networks = self.client.list_networks(self['detail'])
     @errors.cyclades.connection
     def _run(self):
         networks = self.client.list_networks(self['detail'])
+        if not (self['detail'] or self['json_output']):
+            remove_from_items(networks, 'links')
         kwargs = dict(with_enumeration=self['enum'])
         if self['more']:
             kwargs['page_size'] = self['limit'] or 10
         kwargs = dict(with_enumeration=self['enum'])
         if self['more']:
             kwargs['page_size'] = self['limit'] or 10
index c2b5042..d381f90 100644 (file)
@@ -498,3 +498,9 @@ def get_path_size(testpath):
             if path.isfile(f):
                 total_size += path.getsize(f)
     return total_size
             if path.isfile(f):
                 total_size += path.getsize(f)
     return total_size
+
+
+def remove_from_items(list_of_dicts, key_to_remove):
+    for item in list_of_dicts:
+        assert isinstance(item, dict), 'Item %s not a dict' % item
+        item.pop(key_to_remove, None)