示例#1
0
文件: utils.py 项目: pineunity/apmec
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
示例#2
0
 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))
示例#3
0
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
示例#4
0
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)
示例#5
0
 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)
示例#6
0
        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)
示例#7
0
class MECAInUse(exceptions.InUse):
    message = _('MECA %(meca_id)s is still in use')
示例#8
0
class VimFromMeaNotFoundException(exceptions.NotFound):
    message = _('VIM from MEA %(mea_id)s could not be found')
示例#9
0
class VimGetResourceNameNotUnique(exceptions.ApmecException):
    message = _("Getting resource id from VIM with resource name %(name)s "
                "by %(cmd)s returns more than one")
示例#10
0
class VimUnsupportedResourceTypeException(exceptions.ApmecException):
    message = _("Resource type %(type)s is unsupported by VIM")
示例#11
0
class VimRegionNotFoundException(exceptions.ApmecException):
    message = _("Unknown VIM region name %(region_name)s")
示例#12
0
class VimNotFoundException(exceptions.ApmecException):
    message = _("Specified VIM id %(vim_id)s is invalid. Please verify and "
                "pass a valid VIM id")
示例#13
0
文件: meso.py 项目: pineunity/apmec-1
class MESInUse(exceptions.InUse):
    message = _('MES %(mes_id)s is still in use')
示例#14
0
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.')
示例#15
0
class AuthTypeInvalidError(ApmecException):
    message = _("Invalid auth_type was specified, auth_type: %(type)s")
示例#16
0
class VimDefaultNotDefined(exceptions.ApmecException):
    message = _("Default VIM is not defined.")
示例#17
0
class VimDefaultDuplicateException(exceptions.ApmecException):
    message = _("Default VIM already exists %(vim_id)s.")
示例#18
0
文件: meso.py 项目: pineunity/apmec-1
class MESNotFound(exceptions.NotFound):
    message = _('MES %(mes_id)s could not be found')
示例#19
0
class MECANotFound(exceptions.NotFound):
    message = _('MECA %(meca_id)s could not be found')
示例#20
0
文件: meso.py 项目: pineunity/apmec-1
class VNFFGDNotFound(exceptions.NotFound):
    message = _('VNFFGD template(s) not existed for MESD %(mesd_name)')
示例#21
0
class VimKeyNotFoundException(exceptions.ApmecException):
    message = _("Unable to find key file for VIM %(vim_id)s")
示例#22
0
文件: meso.py 项目: pineunity/apmec-1
class MECDriverNotfound(exceptions.NotFound):
    message = _('MEC driver not specified for the MESD %(mesd_name)')
示例#23
0
class VimGetResourceException(exceptions.ApmecException):
    message = _("Error while trying to issue %(cmd)s to find resource type "
                "%(type)s by resource name %(name)s")
示例#24
0
文件: meso.py 项目: pineunity/apmec-1
class NFVDriverNotFound(exceptions.NotFound):
    message = _('NFV driver is not specified for the MESD %(mesd_name)')
示例#25
0
class VimGetResourceNotFoundException(exceptions.ApmecException):
    message = _("Getting resource id from VIM with resource name %(name)s "
                "by %(cmd)s returns nothing")
示例#26
0
class VimUnauthorizedException(exceptions.ApmecException):
    message = _("%(message)s")
示例#27
0
class ToscaParserFailed(exceptions.InvalidInput):
    message = _("tosca-parser failed: - %(error_msg_details)s")
示例#28
0
class VimConnectionException(exceptions.ApmecException):
    message = _("%(message)s")
示例#29
0
class NoTasksException(exceptions.ApmecException):
    message = _('No tasks to run for %(action)s on %(resource)s')
示例#30
0
class VimInUseException(exceptions.ApmecException):
    message = _("VIM %(vim_id)s is still in use by MEA")