def _custom_version(self, service):
return self.config.get_cloud(self.cloud, '%s_version' % service)
+ def _uuid2username(self, uuid):
+ r = self.auth_base.post_user_catalogs([uuid])
+ uuids = r.json['uuid_catalog']
+ return uuids.get(uuid, None)
+
+ def _username2uuid(self, username):
+ r = self.auth_base.post_user_catalogs(displaynames=[username])
+ names = r.json['displayname_catalog']
+ return names.get(username, None)
+
def _set_log_params(self):
try:
self.client.LOG_TOKEN, self.client.LOG_DATA = (
size_max=IntArgument('filter by maximum size', '--size-max'),
status=ValueArgument('filter by status', '--status'),
owner=ValueArgument('filter by owner', '--owner'),
+ owner_name=ValueArgument('filter by owners username', '--owner-name'),
order=ValueArgument(
'order by FIELD ( - to reverse order)',
'--order',
def _filtered_by_owner(self, detail, *list_params):
images = []
- MINKEYS = set([
- 'id', 'size', 'status', 'disk_format', 'container_format', 'name'])
+ ouuid = self['owner'] or self._username2uuid(self['owner_name'])
+ if not ouuid:
+ return images
for img in self.client.list_public(True, *list_params):
- if img['owner'] == self['owner']:
+ if img['owner'] == ouuid:
if not detail:
- for key in set(img.keys()).difference(MINKEYS):
+ for key in set(img.keys()).difference(self.PERMANENTS):
img.pop(key)
images.append(img)
return images
def _filtered_by_name(self, images):
np, ns, nl = self['name_pref'], self['name_suff'], self['name_like']
- return [img for img in images if (
+
+ def augment_owner(img):
+ uuid = img.get('owner', None)
+ if uuid and not self['json_output']:
+ img['owner'] = '%s (%s)' % (uuid, self._uuid2username(uuid))
+ return img
+
+ return [augment_owner(img) for img in images if (
(not np) or img['name'].lower().startswith(np.lower())) and (
(not ns) or img['name'].lower().endswith(ns.lower())) and (
(not nl) or nl.lower() in img['name'].lower())]
order = self['order']
detail = self['detail'] or self['prop']
- if self['owner']:
+ if self['owner'] or self['owner_name']:
images = self._filtered_by_owner(detail, filters, order)
else:
images = self.client.list_public(detail, filters, order)
"""Get (cached) term, from user credentials"""
return self.user_info(token).get(key, None)
- def post_user_catalogs(self, uuids):
+ def post_user_catalogs(self, uuids=None, displaynames=None):
"""POST base_url/user_catalogs
:param uuids: (list or tuple) user uuids
- :returns: (dict) {uuid1: name1, uuid2: name2, ...}
+ :param displaynames: (list or tuple) usernames (mut. excl. to uuids)
+
+ :returns: (dict) {uuid1: name1, uuid2: name2, ...} or oposite
"""
account_url = self.get_service_endpoints('account')['publicURL']
account = AstakosClient(account_url, self.token)
- json_data = dict(uuids=uuids)
+ json_data = dict(uuids=uuids) if (
+ uuids) else dict(displaynames=displaynames)
return account.post('user_catalogs', json=json_data)