Merge branch 'feature-id-to-name' into develop
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 26 Aug 2013 15:31:29 +0000 (18:31 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 26 Aug 2013 15:31:29 +0000 (18:31 +0300)
kamaki/cli/commands/cyclades.py
kamaki/cli/commands/image.py
kamaki/cli/commands/pithos.py

index 1cd40d2..53e795a 100644 (file)
@@ -292,7 +292,11 @@ class server_info(_init_cyclades, _optional_json):
     @errors.cyclades.connection
     @errors.cyclades.server_id
     def _run(self, server_id):
-        self._print(self.client.get_server_details(server_id), print_dict)
+        vm = self.client.get_server_details(server_id)
+        uuids = self._uuids2usernames([vm['user_id'], vm['tenant_id']])
+        vm['user_id'] += ' (%s)' % uuids[vm['user_id']]
+        vm['tenant_id'] += ' (%s)' % uuids[vm['tenant_id']]
+        self._print(vm, print_dict)
 
     def main(self, server_id):
         super(self.__class__, self)._run()
@@ -355,6 +359,9 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
     def _run(self, name, flavor_id, image_id):
         r = self.client.create_server(
             name, int(flavor_id), image_id, self['personality'])
+        usernames = self._uuids2usernames([r['user_id'], r['tenant_id']])
+        r['user_id'] += ' (%s)' % usernames[r['user_id']]
+        r['tenant_id'] += ' (%s)' % usernames[r['tenant_id']]
         self._print(r, print_dict)
         if self['wait']:
             self._wait(r['id'], r['status'])
@@ -781,6 +788,20 @@ class flavor_info(_init_cyclades, _optional_json):
         self._run(flavor_id=flavor_id)
 
 
+def _add_name(self, net):
+        user_id, tenant_id, uuids = net['user_id'], net['tenant_id'], []
+        if user_id:
+            uuids.append(user_id)
+        if tenant_id:
+            uuids.append(tenant_id)
+        if uuids:
+            usernames = self._uuids2usernames(uuids)
+            if user_id:
+                net['user_id'] += ' (%s)' % usernames[user_id]
+            if tenant_id:
+                net['tenant_id'] += ' (%s)' % usernames[tenant_id]
+
+
 @command(network_cmds)
 class network_info(_init_cyclades, _optional_json):
     """Detailed information on a network
@@ -792,6 +813,7 @@ class network_info(_init_cyclades, _optional_json):
     @errors.cyclades.network_id
     def _run(self, network_id):
         network = self.client.get_network_details(int(network_id))
+        _add_name(self, network)
         self._print(network, print_dict, exclude=('id'))
 
     def main(self, network_id):
@@ -920,8 +942,8 @@ class network_create(_init_cyclades, _optional_json, _network_wait):
             gateway=self['gateway'],
             dhcp=self['dhcp'],
             type=self['type'])
+        _add_name(self, r)
         self._print(r, print_dict)
-
         if self['wait']:
             self._wait(r['id'], 'PENDING')
 
index 11ba32c..55acc82 100644 (file)
@@ -482,6 +482,7 @@ class image_register(_init_image, _optional_json):
                     details=[
                         'Make sure the image file exists'] + howto_image_file)
             raise
+        r['owner'] += '( %s)' % self._uuid2username(r['owner'])
         self._print(r, print_dict)
 
         #upload the metadata file
@@ -528,11 +529,15 @@ class image_shared(_init_image, _optional_json):
     @errors.generic.all
     @errors.plankton.connection
     def _run(self, member):
-        self._print(self.client.list_shared(member), title=('image_id',))
+        r = self.client.list_shared(member)
+        if r:
+            uuid = self._username2uuid(member)
+            r = self.client.list_shared(uuid) if uuid else []
+        self._print(r, title=('image_id',))
 
-    def main(self, member):
+    def main(self, member_id_or_username):
         super(self.__class__, self)._run()
-        self._run(member)
+        self._run(member_id_or_username)
 
 
 @command(image_cmds)
@@ -548,7 +553,13 @@ class image_members_list(_init_image, _optional_json):
     @errors.plankton.connection
     @errors.plankton.id
     def _run(self, image_id):
-        self._print(self.client.list_members(image_id), title=('member_id',))
+        members = self.client.list_members(image_id)
+        if not self['json_output']:
+            uuids = [member['member_id'] for member in members]
+            usernames = self._uuids2usernames(uuids)
+            for member in members:
+                member['member_id'] += ' (%s)' % usernames[member['member_id']]
+        self._print(members, title=('member_id',))
 
     def main(self, image_id):
         super(self.__class__, self)._run()
@@ -565,9 +576,9 @@ class image_members_add(_init_image, _optional_output_cmd):
     def _run(self, image_id=None, member=None):
             self._optional_output(self.client.add_member(image_id, member))
 
-    def main(self, image_id, member):
+    def main(self, image_id, member_id):
         super(self.__class__, self)._run()
-        self._run(image_id=image_id, member=member)
+        self._run(image_id=image_id, member=member_id)
 
 
 @command(image_cmds)
@@ -595,9 +606,9 @@ class image_members_set(_init_image, _optional_output_cmd):
     def _run(self, image_id, members):
             self._optional_output(self.client.set_members(image_id, members))
 
-    def main(self, image_id, *members):
+    def main(self, image_id, *member_ids):
         super(self.__class__, self)._run()
-        self._run(image_id=image_id, members=members)
+        self._run(image_id=image_id, members=member_ids)
 
 
 # Compute Image Commands
@@ -695,6 +706,10 @@ class image_compute_info(_init_cyclades, _optional_json):
     @errors.plankton.id
     def _run(self, image_id):
         image = self.client.get_image_details(image_id)
+        uuids = [image['user_id'], image['tenant_id']]
+        usernames = self._uuids2usernames(uuids)
+        image['user_id'] += ' (%s)' % usernames[image['user_id']]
+        image['tenant_id'] += ' (%s)' % usernames[image['tenant_id']]
         self._print(image, print_dict)
 
     def main(self, image_id):
index a7e1777..a760494 100644 (file)
@@ -1509,7 +1509,7 @@ class file_delete(_file_container_command, _optional_output_cmd):
                     until=self['until'], delimiter=self['delimiter']))
             else:
                 print('Aborted')
-        else:
+        elif self.container:
             if self['recursive']:
                 ask_msg = 'Delete container contents'
             else:
@@ -1519,6 +1519,8 @@ class file_delete(_file_container_command, _optional_output_cmd):
                     until=self['until'], delimiter=self['delimiter']))
             else:
                 print('Aborted')
+        else:
+            raiseCLIError('Nothing to delete, please provide container[:path]')
 
     def main(self, container____path__=None):
         super(self.__class__, self)._run(container____path__)
@@ -2054,19 +2056,15 @@ class file_sharers(_file_account_command, _optional_json):
     @errors.pithos.connection
     def _run(self):
         accounts = self.client.get_sharing_accounts(marker=self['marker'])
-        uuids = [acc['name'] for acc in accounts]
-        try:
-            astakos_responce = self.auth_base.post_user_catalogs(uuids)
-            usernames = astakos_responce.json
-            r = usernames['uuid_catalog']
-        except Exception as e:
-            print 'WARNING: failed to call user_catalogs, %s' % e
-            r = dict(sharer_uuid=uuids)
-            usernames = accounts
-        if self['json_output'] or self['detail']:
-            self._print(usernames)
-        else:
-            self._print(r, print_dict)
+        if not self['json_output']:
+            usernames = self._uuids2usernames(
+                [acc['name'] for acc in accounts])
+            for item in accounts:
+                uuid = item['name']
+                item['id'], item['name'] = uuid, usernames[uuid]
+                if not self['detail']:
+                    item.pop('last_modified')
+        self._print(accounts)
 
     def main(self):
         super(self.__class__, self)._run()