def get_db_info(context, id): if context is None: raise TypeError("Argument context not defined.") elif id is None: raise TypeError("Argument id not defined.") try: db_info = DBInstance.find_by(id=id, deleted=False) except exception.NotFound: raise exception.NotFound(uuid=id) except exception.ModelNotFoundError: raise exception.NotFound(uuid=id) if not context.is_admin and db_info.tenant_id != context.tenant: LOG.error("Tenant %s tried to access instance %s, owned by %s." % (context.tenant, id, db_info.tenant_id)) raise exception.NotFound(uuid=id) return db_info
def __init__(self, flavor=None, context=None, flavor_id=None): if flavor: self.flavor = flavor return if flavor_id and context: try: client = create_nova_client(context) self.flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound, e: raise exception.NotFound(uuid=flavor_id) except nova_exceptions.ClientException, e: raise exception.ReddwarfError(str(e))
def __init__(self, security_group=None, id=None, context=None): if id is None and security_group is None: msg = "Security Group does not have id defined!" raise exception.InvalidModelError(msg) elif security_group is None: try: client = reddwarf.common.remote.create_nova_client(context) self._data_object = client.security_groups.get(id) except nova_exceptions.NotFound, e: raise exception.NotFound(id=id) except nova_exceptions.ClientException, e: raise exception.ReddwarfError(str(e))
def get_by_id(cls, backup_id, deleted=False): """ get the backup for that id :param cls: :param backup_id: Id of the backup to return :param deleted: Return deleted backups :return: """ try: db_info = DBBackup.find_by(id=backup_id, deleted=deleted) return db_info except exception.NotFound: raise exception.NotFound(uuid=backup_id)
def _mapper(self, method, context, *args, **kwargs): """ Tries to call the respective driver method """ try: func = getattr(self.driver, method) except AttributeError: LOG.error(_("Method %s not found for driver %s"), method, self.driver) raise exception.NotFound("Method %s is not available for the " "chosen driver.") try: return func(*args, **kwargs) except Exception as e: LOG.error("Got an error running %s!" % method) LOG.debug(traceback.format_exc())
def _validate_flavor_id(self, id): try: if int(id) != float(id): raise exception.NotFound(uuid=id) except ValueError: raise exception.NotFound(uuid=id)
def load(context, name): client = create_nova_client(context) try: return DetailedHost(client.rdhosts.get(name)) except nova_exceptions.NotFound: raise exception.NotFound(uuid=name)