Revision 95641ecc
b/kamaki/cli/commands/__init__.py | ||
---|---|---|
94 | 94 |
def _custom_version(self, service): |
95 | 95 |
return self.config.get_cloud(self.cloud, '%s_version' % service) |
96 | 96 |
|
97 |
def _uuid2username(self, uuid): |
|
98 |
r = self.auth_base.post_user_catalogs([uuid]) |
|
99 |
uuids = r.json['uuid_catalog'] |
|
100 |
return uuids.get(uuid, None) |
|
101 |
|
|
102 |
def _username2uuid(self, username): |
|
103 |
r = self.auth_base.post_user_catalogs(displaynames=[username]) |
|
104 |
names = r.json['displayname_catalog'] |
|
105 |
return names.get(username, None) |
|
106 |
|
|
97 | 107 |
def _set_log_params(self): |
98 | 108 |
try: |
99 | 109 |
self.client.LOG_TOKEN, self.client.LOG_DATA = ( |
b/kamaki/cli/commands/image.py | ||
---|---|---|
199 | 199 |
size_max=IntArgument('filter by maximum size', '--size-max'), |
200 | 200 |
status=ValueArgument('filter by status', '--status'), |
201 | 201 |
owner=ValueArgument('filter by owner', '--owner'), |
202 |
owner_name=ValueArgument('filter by owners username', '--owner-name'), |
|
202 | 203 |
order=ValueArgument( |
203 | 204 |
'order by FIELD ( - to reverse order)', |
204 | 205 |
'--order', |
... | ... | |
213 | 214 |
|
214 | 215 |
def _filtered_by_owner(self, detail, *list_params): |
215 | 216 |
images = [] |
216 |
MINKEYS = set([ |
|
217 |
'id', 'size', 'status', 'disk_format', 'container_format', 'name']) |
|
217 |
ouuid = self['owner'] or self._username2uuid(self['owner_name']) |
|
218 |
if not ouuid: |
|
219 |
return images |
|
218 | 220 |
for img in self.client.list_public(True, *list_params): |
219 |
if img['owner'] == self['owner']:
|
|
221 |
if img['owner'] == ouuid:
|
|
220 | 222 |
if not detail: |
221 |
for key in set(img.keys()).difference(MINKEYS):
|
|
223 |
for key in set(img.keys()).difference(self.PERMANENTS):
|
|
222 | 224 |
img.pop(key) |
223 | 225 |
images.append(img) |
224 | 226 |
return images |
225 | 227 |
|
226 | 228 |
def _filtered_by_name(self, images): |
227 | 229 |
np, ns, nl = self['name_pref'], self['name_suff'], self['name_like'] |
228 |
return [img for img in images if ( |
|
230 |
|
|
231 |
def augment_owner(img): |
|
232 |
uuid = img.get('owner', None) |
|
233 |
if uuid and not self['json_output']: |
|
234 |
img['owner'] = '%s (%s)' % (uuid, self._uuid2username(uuid)) |
|
235 |
return img |
|
236 |
|
|
237 |
return [augment_owner(img) for img in images if ( |
|
229 | 238 |
(not np) or img['name'].lower().startswith(np.lower())) and ( |
230 | 239 |
(not ns) or img['name'].lower().endswith(ns.lower())) and ( |
231 | 240 |
(not nl) or nl.lower() in img['name'].lower())] |
... | ... | |
259 | 268 |
|
260 | 269 |
order = self['order'] |
261 | 270 |
detail = self['detail'] or self['prop'] |
262 |
if self['owner']: |
|
271 |
if self['owner'] or self['owner_name']:
|
|
263 | 272 |
images = self._filtered_by_owner(detail, filters, order) |
264 | 273 |
else: |
265 | 274 |
images = self.client.list_public(detail, filters, order) |
b/kamaki/clients/astakos/__init__.py | ||
---|---|---|
155 | 155 |
"""Get (cached) term, from user credentials""" |
156 | 156 |
return self.user_info(token).get(key, None) |
157 | 157 |
|
158 |
def post_user_catalogs(self, uuids): |
|
158 |
def post_user_catalogs(self, uuids=None, displaynames=None):
|
|
159 | 159 |
"""POST base_url/user_catalogs |
160 | 160 |
|
161 | 161 |
:param uuids: (list or tuple) user uuids |
162 | 162 |
|
163 |
:returns: (dict) {uuid1: name1, uuid2: name2, ...} |
|
163 |
:param displaynames: (list or tuple) usernames (mut. excl. to uuids) |
|
164 |
|
|
165 |
:returns: (dict) {uuid1: name1, uuid2: name2, ...} or oposite |
|
164 | 166 |
""" |
165 | 167 |
account_url = self.get_service_endpoints('account')['publicURL'] |
166 | 168 |
account = AstakosClient(account_url, self.token) |
167 |
json_data = dict(uuids=uuids) |
|
169 |
json_data = dict(uuids=uuids) if ( |
|
170 |
uuids) else dict(displaynames=displaynames) |
|
168 | 171 |
return account.post('user_catalogs', json=json_data) |
Also available in: Unified diff