Revision 2377e7c2 snf-astakos-client/astakosclient/__init__.py
b/snf-astakos-client/astakosclient/__init__.py | ||
---|---|---|
40 | 40 |
import simplejson |
41 | 41 |
from astakosclient.utils import retry, scheme_to_class |
42 | 42 |
from astakosclient.errors import \ |
43 |
AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden |
|
43 |
AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \ |
|
44 |
NoDisplayName, NoUUID |
|
44 | 45 |
|
45 | 46 |
|
46 | 47 |
# -------------------------------------------------------------------- |
... | ... | |
190 | 191 |
req_body = simplejson.dumps({'uuids': uuids}) |
191 | 192 |
data = self._callAstakos( |
192 | 193 |
token, req_path, req_headers, req_body, "POST") |
193 |
# XXX: check if exists |
|
194 |
return data.get("uuid_catalog") |
|
194 |
if "uuid_catalog" in data: |
|
195 |
return data.get("uuid_catalog") |
|
196 |
else: |
|
197 |
m = "_uuidCatalog request returned %s. No uuid_catalog found" \ |
|
198 |
% data |
|
199 |
self.logger.error(m) |
|
200 |
raise AstakosClientException(m) |
|
195 | 201 |
|
196 | 202 |
def getDisplayNames(self, token, uuids): |
197 | 203 |
"""Return a uuid_catalog dictionary for the given uuids |
... | ... | |
214 | 220 |
self.logger.error(m) |
215 | 221 |
raise ValueError(m) |
216 | 222 |
uuid_dict = self.getDisplayNames(token, [uuid]) |
217 |
# XXX: check if exists |
|
218 |
return uuid_dict.get(uuid) |
|
223 |
if uuid in uuid_dict: |
|
224 |
return uuid_dict.get(uuid) |
|
225 |
else: |
|
226 |
raise NoDisplayName(uuid) |
|
219 | 227 |
|
220 | 228 |
def getServiceDisplayNames(self, token, uuids): |
221 | 229 |
"""Return a uuid_catalog dict using a service's token""" |
... | ... | |
229 | 237 |
self.logger.error(m) |
230 | 238 |
raise ValueError(m) |
231 | 239 |
uuid_dict = self.getServiceDisplayNames(token, [uuid]) |
232 |
# XXX: check if exists |
|
233 |
return uuid_dict.get(uuid) |
|
240 |
if uuid in uuid_dict: |
|
241 |
return uuid_dict.get(uuid) |
|
242 |
else: |
|
243 |
raise NoDisplayName(uuid) |
|
234 | 244 |
|
235 | 245 |
# ---------------------------------- |
236 | 246 |
def _displayNameCatalog(self, token, display_names, req_path): |
... | ... | |
238 | 248 |
req_body = simplejson.dumps({'displaynames': display_names}) |
239 | 249 |
data = self._callAstakos( |
240 | 250 |
token, req_path, req_headers, req_body, "POST") |
241 |
# XXX: check if exists |
|
242 |
return data.get("displayname_catalog") |
|
251 |
if "displayname_catalog" in data: |
|
252 |
return data.get("displayname_catalog") |
|
253 |
else: |
|
254 |
m = "_displayNameCatalog request returned %s. " \ |
|
255 |
"No displayname_catalog found" % data |
|
256 |
self.logger.error(m) |
|
257 |
raise AstakosClientException(m) |
|
243 | 258 |
|
244 | 259 |
def getUUIDs(self, token, display_names): |
245 | 260 |
"""Return a displayname_catalog for the given names |
... | ... | |
262 | 277 |
self.logger.error(m) |
263 | 278 |
raise ValueError(m) |
264 | 279 |
name_dict = self.getUUIDs(token, [display_name]) |
265 |
# XXX: check if exists |
|
266 |
return name_dict.get(display_name) |
|
280 |
if display_name in name_dict: |
|
281 |
return name_dict.get(display_name) |
|
282 |
else: |
|
283 |
raise NoUUID(display_name) |
|
267 | 284 |
|
268 | 285 |
def getServiceUUIDs(self, token, display_names): |
269 | 286 |
"""Return a display_name catalog using a service's token""" |
... | ... | |
277 | 294 |
self.logger.error(m) |
278 | 295 |
raise ValueError(m) |
279 | 296 |
name_dict = self.getServiceUUIDs(token, [display_name]) |
280 |
# XXX: check if exists |
|
281 |
return name_dict.get(display_name) |
|
297 |
if display_name in name_dict: |
|
298 |
return name_dict.get(display_name) |
|
299 |
else: |
|
300 |
raise NoUUID(display_name) |
|
282 | 301 |
|
283 | 302 |
# ---------------------------------- |
284 | 303 |
def getServices(self): |
Also available in: Unified diff