def to_native(self, location): entity_id = None location = str(location) i = location.rfind('/') if i + 1 < len(location): entity_id = location[i+1:] entity = Entity(EntityKind) entity.occi_import_attributes([('occi.core.id', entity_id)], validate=False) return entity
def to_native(self, location): entity_id = None location = str(location) i = location.rfind('/') if i + 1 < len(location): entity_id = location[i + 1:] entity = Entity(EntityKind) entity.occi_import_attributes([('occi.core.id', entity_id)], validate=False) return entity
def get_entity_id(self): """Extract Entity ID from `DataObject` if found. >>> dao = DataObject() >>> dao.location = 'http://example.com/compute/10000000-0000-4000-0000-000000000000' >>> dao.get_entity_id() UUID('10000000-0000-4000-0000-000000000000') >>> dao.attributes.append(('occi.core.id', '20000000-0000-4000-0000-000000000000')) >>> dao.get_entity_id() UUID('20000000-0000-4000-0000-000000000000') """ entity_id = None if self.attributes: for attr, value in self.attributes: if attr == "occi.core.id": entity = Entity(EntityKind) entity.occi_import_attributes([("occi.core.id", value)], validate=False) entity_id = entity.id elif self.location: entity = self.translator.to_native(self.location) if entity: entity_id = entity.id return entity_id
def get_entity_id(self): """Extract Entity ID from `DataObject` if found. >>> dao = DataObject() >>> dao.location = 'http://example.com/compute/10000000-0000-4000-0000-000000000000' >>> dao.get_entity_id() UUID('10000000-0000-4000-0000-000000000000') >>> dao.attributes.append(('occi.core.id', '20000000-0000-4000-0000-000000000000')) >>> dao.get_entity_id() UUID('20000000-0000-4000-0000-000000000000') """ entity_id = None if self.attributes: for attr, value in self.attributes: if attr == 'occi.core.id': entity = Entity(EntityKind) entity.occi_import_attributes([('occi.core.id', value)], validate=False) entity_id = entity.id elif self.location: entity = self.translator.to_native(self.location) if entity: entity_id = entity.id return entity_id
def _delete_entities(self, entity_ids, user=None): for entity_id in entity_ids: entity_id = str(entity_id) try: entity = self._db[entity_id] if isinstance(entity, Resource): for l in entity.links: self._db.pop(l.id, None) elif isinstance(entity, Link): try: entity.source.links.remove(entity) except ValueError: pass del self._db[entity_id] except KeyError: raise Entity.DoesNotExist(entity_id)
def get_entity(self, entity_id, user=None): entity_id = str(entity_id) try: return self._db[entity_id] except KeyError: raise Entity.DoesNotExist(entity_id)