def load_class_by_alias_or_classname(namespace, name): """Load class using stevedore alias or the class name Load class using the stevedore driver manager :param namespace: namespace where the alias is defined :param name: alias or class name of the class to be loaded :returns: class if calls can be loaded :raises ImportError: if class cannot be loaded """ if not name: LOG.error("Alias or class name is not set") raise ImportError(_("Class not found.")) try: # Try to resolve class by alias mgr = driver.DriverManager(namespace, name) class_to_load = mgr.driver except RuntimeError: e1_info = sys.exc_info() # Fallback to class name try: class_to_load = importutils.import_class(name) except (ImportError, ValueError): LOG.error("Error loading class by alias", exc_info=e1_info) LOG.error("Error loading class by class name", exc_info=True) raise ImportError(_("Class not found.")) return class_to_load
def show(self, request, id): # NOTE(dprince): the extensions alias is used as the 'id' for show ext = self.extension_manager.extensions.get(id) if not ext: raise webob.exc.HTTPNotFound( _("Extension with alias %s does not exist") % id) return dict(extension=self._translate(ext))
class ApmecException(Exception): """Base Apmec Exception. To correctly use this class, inherit from it and define a 'message' property. That message will get printf'd with the keyword arguments provided to the constructor. """ message = _("An unknown exception occurred.") def __init__(self, **kwargs): try: super(ApmecException, self).__init__(self.message % kwargs) self.msg = self.message % kwargs except Exception: with excutils.save_and_reraise_exception() as ctxt: if not self.use_fatal_exceptions(): ctxt.reraise = False # at least get the core message out if something happened super(ApmecException, self).__init__(self.message) if six.PY2: def __unicode__(self): return unicode(self.msg) def __str__(self): return self.msg def use_fatal_exceptions(self): """Is the instance using fatal exceptions. :returns: Always returns False. """ return False
class NetworkVlanRangeError(ApmecException): message = _("Invalid network VLAN range: '%(vlan_range)s' - '%(error)s'") def __init__(self, **kwargs): # Convert vlan_range tuple to 'start:end' format for display if isinstance(kwargs['vlan_range'], tuple): kwargs['vlan_range'] = "%d:%d" % kwargs['vlan_range'] super(NetworkVlanRangeError, self).__init__(**kwargs)
def __init__(self, kind, match): # Process the match try: self.target_field = re.findall(r'^\%\((.*)\)s$', match)[0] except IndexError: err_reason = (_("Unable to identify a target field from:%s. " "Match should be in the form %%(<field_name>)s") % match) LOG.exception(err_reason) raise exceptions.PolicyInitError(policy="%s:%s" % (kind, match), reason=err_reason) super(OwnerCheck, self).__init__(kind, match)
def _update_meca_wait(self_obj, meca_id, execution_id): exec_state = "RUNNING" mistral_retries = MISTRAL_RETRIES while exec_state == "RUNNING" and mistral_retries > 0: time.sleep(MISTRAL_RETRY_WAIT) exec_state = self._vim_drivers.invoke( driver_type, 'get_execution', execution_id=execution_id, auth_dict=self.get_auth_dict(context)).state LOG.debug('status: %s', exec_state) if exec_state == 'SUCCESS' or exec_state == 'ERROR': break mistral_retries = mistral_retries - 1 error_reason = None if mistral_retries == 0 and exec_state == 'RUNNING': error_reason = _( "MECA update is not completed within" " {wait} seconds as creation of mistral" " execution {mistral} is not completed").format( wait=MISTRAL_RETRIES * MISTRAL_RETRY_WAIT, mistral=execution_id) exec_obj = self._vim_drivers.invoke( driver_type, 'get_execution', execution_id=execution_id, auth_dict=self.get_auth_dict(context)) self._vim_drivers.invoke(driver_type, 'delete_execution', execution_id=execution_id, auth_dict=self.get_auth_dict(context)) self._vim_drivers.invoke(driver_type, 'delete_workflow', workflow_id=workflow['id'], auth_dict=self.get_auth_dict(context)) super(MeoPlugin, self)._update_meca_post(context, meca_id, exec_obj, mead_dict, error_reason)
class MECAInUse(exceptions.InUse): message = _('MECA %(meca_id)s is still in use')
class VimFromMeaNotFoundException(exceptions.NotFound): message = _('VIM from MEA %(mea_id)s could not be found')
class VimGetResourceNameNotUnique(exceptions.ApmecException): message = _("Getting resource id from VIM with resource name %(name)s " "by %(cmd)s returns more than one")
class VimUnsupportedResourceTypeException(exceptions.ApmecException): message = _("Resource type %(type)s is unsupported by VIM")
class VimRegionNotFoundException(exceptions.ApmecException): message = _("Unknown VIM region name %(region_name)s")
class VimNotFoundException(exceptions.ApmecException): message = _("Specified VIM id %(vim_id)s is invalid. Please verify and " "pass a valid VIM id")
class MESInUse(exceptions.InUse): message = _('MES %(mes_id)s is still in use')
class InsufficientCredentialDataError(ApmecException): message = _('Insufficient credential data was provided, either ' '"token" must be set in the passed conf, or a context ' 'with an "auth_token" property must be passed.')
class AuthTypeInvalidError(ApmecException): message = _("Invalid auth_type was specified, auth_type: %(type)s")
class VimDefaultNotDefined(exceptions.ApmecException): message = _("Default VIM is not defined.")
class VimDefaultDuplicateException(exceptions.ApmecException): message = _("Default VIM already exists %(vim_id)s.")
class MESNotFound(exceptions.NotFound): message = _('MES %(mes_id)s could not be found')
class MECANotFound(exceptions.NotFound): message = _('MECA %(meca_id)s could not be found')
class VNFFGDNotFound(exceptions.NotFound): message = _('VNFFGD template(s) not existed for MESD %(mesd_name)')
class VimKeyNotFoundException(exceptions.ApmecException): message = _("Unable to find key file for VIM %(vim_id)s")
class MECDriverNotfound(exceptions.NotFound): message = _('MEC driver not specified for the MESD %(mesd_name)')
class VimGetResourceException(exceptions.ApmecException): message = _("Error while trying to issue %(cmd)s to find resource type " "%(type)s by resource name %(name)s")
class NFVDriverNotFound(exceptions.NotFound): message = _('NFV driver is not specified for the MESD %(mesd_name)')
class VimGetResourceNotFoundException(exceptions.ApmecException): message = _("Getting resource id from VIM with resource name %(name)s " "by %(cmd)s returns nothing")
class VimUnauthorizedException(exceptions.ApmecException): message = _("%(message)s")
class ToscaParserFailed(exceptions.InvalidInput): message = _("tosca-parser failed: - %(error_msg_details)s")
class VimConnectionException(exceptions.ApmecException): message = _("%(message)s")
class NoTasksException(exceptions.ApmecException): message = _('No tasks to run for %(action)s on %(resource)s')
class VimInUseException(exceptions.ApmecException): message = _("VIM %(vim_id)s is still in use by MEA")