Exemplo n.º 1
0
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(_LE("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(_LE("Error loading class by alias"),
                      exc_info=e1_info)
            LOG.error(_LE("Error loading class by class name"),
                      exc_info=True)
            raise ImportError(_("Class not found."))
    return class_to_load
Exemplo n.º 2
0
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(_LE("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(_LE("Error loading class by alias"), exc_info=e1_info)
            LOG.error(_LE("Error loading class by class name"), exc_info=True)
            raise ImportError(_("Class not found."))
    return class_to_load
Exemplo n.º 3
0
 def delete(self, plugin, context, device_id):
     nova = self._nova_client()
     try:
         instance = nova.servers.get(device_id)
     except self._novaclient.exceptions.NotFound:
         LOG.error(_LE("server %s is not found") % device_id)
         return
     instance.delete()
Exemplo n.º 4
0
 def delete(self, plugin, context, device_id):
     nova = self._nova_client()
     try:
         instance = nova.servers.get(device_id)
     except self._novaclient.exceptions.NotFound:
         LOG.error(_LE("server %s is not found") %
         device_id)
         return
     instance.delete()
Exemplo n.º 5
0
 def dettach_interface(self, plugin, context, device_id, port_id):
     LOG.debug(_('detaching interface %(device_id)s %(port_id)s'),
               {'device_id': device_id, 'port_id': port_id})
     nova = self._nova_client()
     try:
         instance = nova.servers.get(device_id)
     except self._novaclient.exceptions.NotFound:
         LOG.error(_LE("server %s is not found") %
         device_id)
         return
     instance.interface_detach(port_id)
Exemplo n.º 6
0
 def dettach_interface(self, plugin, context, device_id, port_id):
     LOG.debug(_('detaching interface %(device_id)s %(port_id)s'),
               {'device_id': device_id, 'port_id': port_id})
     nova = self._nova_client()
     try:
         instance = nova.servers.get(device_id)
     except self._novaclient.exceptions.NotFound:
         LOG.error(_LE("server %s is not found") %
                   device_id)
         return
     instance.interface_detach(port_id)
Exemplo n.º 7
0
    def _create_device_wait(self, context, device_dict, auth_attr):
        driver_name = self._infra_driver_name(device_dict)
        device_id = device_dict['id']
        instance_id = self._instance_id(device_dict)
        create_failed = False

        try:
            self._device_manager.invoke(driver_name,
                                        'create_wait',
                                        plugin=self,
                                        context=context,
                                        device_dict=device_dict,
                                        device_id=instance_id,
                                        auth_attr=auth_attr)
        except vnfm.DeviceCreateWaitFailed as e:
            LOG.error(_LE("VNF Create failed for vnf_id %s"), device_id)
            create_failed = True
            device_dict['status'] = constants.ERROR
            self.set_device_error_status_reason(context, device_id,
                                                six.text_type(e))

        if instance_id is None or create_failed:
            mgmt_url = None
        else:
            # mgmt_url = self.mgmt_url(context, device_dict)
            # FIXME(yamahata):
            mgmt_url = device_dict['mgmt_url']

        self._create_device_post(context, device_id, instance_id, mgmt_url,
                                 device_dict)
        self.mgmt_create_post(context, device_dict)

        if instance_id is None or create_failed:
            return

        device_dict['mgmt_url'] = mgmt_url

        kwargs = {
            mgmt_constants.KEY_ACTION: mgmt_constants.ACTION_CREATE_DEVICE,
            mgmt_constants.KEY_KWARGS: {
                'device': device_dict
            },
        }
        new_status = constants.ACTIVE
        try:
            self.mgmt_call(context, device_dict, kwargs)
        except Exception:
            LOG.exception(_('create_device_wait'))
            new_status = constants.ERROR
            self.set_device_error_status_reason(context, device_id,
                                                'Unable to configure VDU')
        device_dict['status'] = new_status
        self._create_device_status(context, device_id, new_status)
Exemplo n.º 8
0
    def _create_device_wait(self, context, device_dict, auth_attr):
        driver_name = self._infra_driver_name(device_dict)
        device_id = device_dict['id']
        instance_id = self._instance_id(device_dict)
        create_failed = False

        try:
            self._device_manager.invoke(
                driver_name, 'create_wait', plugin=self, context=context,
                device_dict=device_dict, device_id=instance_id,
                auth_attr=auth_attr)
        except vnfm.DeviceCreateWaitFailed as e:
            LOG.error(_LE("VNF Create failed for vnf_id %s"), device_id)
            create_failed = True
            device_dict['status'] = constants.ERROR
            self.set_device_error_status_reason(context, device_id,
                                                six.text_type(e))

        if instance_id is None or create_failed:
            mgmt_url = None
        else:
            # mgmt_url = self.mgmt_url(context, device_dict)
            # FIXME(yamahata):
            mgmt_url = device_dict['mgmt_url']

        self._create_device_post(
            context, device_id, instance_id, mgmt_url, device_dict)
        self.mgmt_create_post(context, device_dict)

        if instance_id is None or create_failed:
            return

        device_dict['mgmt_url'] = mgmt_url

        kwargs = {
            mgmt_constants.KEY_ACTION: mgmt_constants.ACTION_CREATE_DEVICE,
            mgmt_constants.KEY_KWARGS: {'device': device_dict},
        }
        new_status = constants.ACTIVE
        try:
            self.mgmt_call(context, device_dict, kwargs)
        except Exception:
            LOG.exception(_('create_device_wait'))
            new_status = constants.ERROR
            self.set_device_error_status_reason(context, device_id,
                    'Unable to configure VDU')
        device_dict['status'] = new_status
        self._create_device_status(context, device_id, new_status)