def get_default_host_quota(db, host_id): """ Get default disk quota from host trait. :rtype: int :return: Returns the default disk quota set on the host, or None if no default quota is set. """ et = EntityTrait(db) try: et.find(host_id) trait = et.get_trait(_Co.trait_host_disk_quota) except Errors.NotFoundError: trait = None trait = trait or {} return trait.get('numval')
def has_disk_quota(db, disk_id): """ Check if disk has disk quotas enabled. Quotas are enabled/disabled by setting a disk quota trait on the disk. The trait may have no default disk quota. :rtype: bool :return: True if quota is enabled. """ et = EntityTrait(db) try: et.find(disk_id) except Errors.NotFoundError: trait = None else: trait = et.get_trait(_Co.trait_disk_quota) return trait is not None
def is_affiliated_entity(self, entity): u""" Check if entity is affiliated with project. :param Entity entity: An entity to check :return bool: Returns True if entity is affiliated with project """ try: trait_code = self._get_affiliate_trait(entity.entity_type) except Errors.CerebrumError: return False try: trait = EntityTrait(self._db) trait.find(entity.entity_id) return trait.get_trait(trait_code)['target_id'] == self.entity_id except Errors.NotFoundError: return False except TypeError: return False
def is_affiliated_entity(self, entity): """Check if entity is affiliated with project. :param Entity entity: An entity to check :return bool: Returns True if entity is affiliated with project """ try: trait_code = self._get_affiliate_trait(entity.entity_type) except Errors.CerebrumError: return False try: trait = EntityTrait(self._db) trait.find(entity.entity_id) return trait.get_trait(trait_code)['target_id'] == self.entity_id except Errors.NotFoundError: return False except TypeError: return False