def fetch_remote_nodecluster(identifier, raise_exceptions=True): try: if is_uuid4(identifier): try: return tutum.NodeCluster.fetch(identifier) except Exception: raise ObjectNotFound( "Cannot find a node cluster with the identifier '%s'" % identifier) else: objects_same_identifier = tutum.NodeCluster.list(uuid__startswith=identifier) or \ tutum.NodeCluster.list(name=identifier) if len(objects_same_identifier) == 1: uuid = objects_same_identifier[0].uuid return tutum.NodeCluster.fetch(uuid) elif len(objects_same_identifier) == 0: raise ObjectNotFound( "Cannot find a node cluster with the identifier '%s'" % identifier) raise NonUniqueIdentifier( "More than one node cluster has the same identifier, please use the long uuid" ) except (NonUniqueIdentifier, ObjectNotFound) as e: if not raise_exceptions: return e raise e
def get_uuids_of_webhookhandler(webhookhandler, identifiers): uuid_list = [] for identifier in identifiers: if is_uuid4(identifier): uuid_list.append(identifier) else: handlers = webhookhandler.list(uuid__startswith=identifier) or \ webhookhandler.list(name=identifier) for handler in handlers: uuid = handler.get('uuid', "") if uuid: uuid_list.append(uuid) if not uuid_list: raise ObjectNotFound( "Cannot find a webhook handler with the identifier '%s'" % identifier) return uuid_list