Ejemplo n.º 1
0
    def delete_network_and_bridge(self, instance, vif):
        net_name = self.get_vif_interim_net_name(vif['id'])
        network = network_utils.find_network_with_name_label(
            self._session, net_name)
        if network is None:
            LOG.debug("Didn't find network by name %s", net_name,
                      instance=instance)
            return
        LOG.debug('destroying patch port pair for vif: vif_id=%(vif_id)s',
                  {'vif_id': vif['id']})
        bridge_name = self._session.network.get_bridge(network)
        patch_port1, tap_name = self._get_patch_port_pair_names(vif['id'])
        try:
            # delete the patch port pair
            host_network.ovs_del_port(self._session, bridge_name, patch_port1)
        except Exception as e:
            LOG.warning("Failed to delete patch port pair for vif %(if)s,"
                        " exception:%(exception)s",
                        {'if': vif, 'exception': e}, instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete patch port pair"))

        LOG.debug('destroying network: network=%(network)s,'
                  'bridge=%(br)s',
                  {'network': network, 'br': bridge_name})
        try:
            self._session.network.destroy(network)
            # delete bridge if it still exists.
            # As there is patch port existing on this bridge when destroying
            # the VM vif (which happens when shutdown the VM), the bridge
            # won't be destroyed automatically by XAPI. So let's destroy it
            # at here.
            host_network.ovs_del_br(self._session, bridge_name)

            qbr_name = self._get_qbr_name(vif['id'])
            qvb_name, qvo_name = self._get_veth_pair_names(vif['id'])
            if self._device_exists(qbr_name):
                # delete tap port, qvb port and qbr
                LOG.debug(
                    "destroy linux bridge %(qbr)s when unplug vif %(vif)s",
                    {'qbr': qbr_name, 'vif': vif['id']})
                self._delete_linux_port(qbr_name, tap_name)
                self._delete_linux_port(qbr_name, qvb_name)
                self._delete_linux_bridge(qbr_name)
            host_network.ovs_del_port(self._session,
                                      CONF.xenserver.ovs_integration_bridge,
                                      qvo_name)
        except Exception as e:
            LOG.warning("Failed to delete bridge for vif %(if)s, "
                        "exception:%(exception)s",
                        {'if': vif, 'exception': e}, instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete bridge"))
Ejemplo n.º 2
0
    def delete_bridge(self, instance, vif_id, bridge_name):
        LOG.debug('destroying patch port pair for vif id: vif_id=%(vif_id)s',
                  {'vif_id': vif_id})
        patch_port1, tap_name = self._get_patch_port_pair_names(vif_id)
        try:
            # delete the patch port pair
            host_network.ovs_del_port(self._session, bridge_name, patch_port1)
        except Exception as e:
            LOG.warning(
                "Failed to delete patch port pair for vif id %(if)s,"
                " exception:%(exception)s", {
                    'if': vif_id,
                    'exception': e
                },
                instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete patch port pair"))

        LOG.debug('destroying bridge: bridge=%(br)s', {'br': bridge_name})
        try:
            # delete bridge if it still exists.
            # As there are patch ports existing on this bridge when
            # destroying won't be destroyed automatically by XAPI, let's
            # destroy it at here.
            host_network.ovs_del_br(self._session, bridge_name)
            qbr_name = self._get_qbr_name(vif_id)
            qvb_name, qvo_name = self._get_veth_pair_names(vif_id)
            if self._device_exists(qbr_name):
                # delete tap port, qvb port and qbr
                LOG.debug(
                    "destroy linux bridge %(qbr)s when unplug vif id"
                    " %(vif_id)s", {
                        'qbr': qbr_name,
                        'vif_id': vif_id
                    })
                self._delete_linux_port(qbr_name, tap_name)
                self._delete_linux_port(qbr_name, qvb_name)
                self._delete_linux_bridge(qbr_name)
            host_network.ovs_del_port(self._session,
                                      CONF.xenserver.ovs_integration_bridge,
                                      qvo_name)
        except Exception as e:
            LOG.warning(
                "Failed to delete bridge for vif id %(if)s, "
                "exception:%(exception)s", {
                    'if': vif_id,
                    'exception': e
                },
                instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete bridge"))
Ejemplo n.º 3
0
    def unplug(self, vif, cna_w_list=None):
        """Unplugs a virtual interface (network) from a VM.

        :param vif: The virtual interface to plug into the instance.
        :param cna_w_list: (Optional, Default: None) The list of Client Network
                           Adapters from pypowervm.  Providing this input
                           allows for an improvement in operation speed.
        :return cna_w: The deleted Client Network Adapter.
        """
        # This is a default implementation that most implementations will
        # require.

        # Need to find the adapters if they were not provided
        if not cna_w_list:
            cna_w_list = vm.get_cnas(self.adapter, self.instance)

        cna_w = self._find_cna_for_vif(cna_w_list, vif)
        if not cna_w:
            LOG.warning(
                'Unable to unplug VIF with mac %(mac)s.  The VIF was '
                'not found on the instance.', {'mac': vif['address']},
                instance=self.instance)
            return None

        LOG.info('Deleting VIF with mac %(mac)s.', {'mac': vif['address']},
                 instance=self.instance)
        try:
            cna_w.delete()
        except Exception as e:
            LOG.exception('Unable to unplug VIF with mac %(mac)s.',
                          {'mac': vif['address']},
                          instance=self.instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=six.text_type(e))
        return cna_w
Ejemplo n.º 4
0
def unplug(adapter, host_uuid, instance, vif, slot_mgr, cna_w_list=None):
    """Unplugs a virtual interface (network) from a VM.

    :param adapter: The pypowervm adapter.
    :param host_uuid: The host UUID for the PowerVM API.
    :param instance: The nova instance object.
    :param vif: The virtual interface to plug into the instance.
    :param slot_mgr: A NovaSlotManager.  Used to store/retrieve the client
                     slots used when a VIF is detached from the VM.
    :param cna_w_list: (Optional, Default: None) The list of Client Network
                       Adapters from pypowervm.  Providing this input
                       allows for an improvement in operation speed.
    """
    vif_drv = _build_vif_driver(adapter, host_uuid, instance, vif)
    try:
        vnet_w = vif_drv.unplug(vif, cna_w_list=cna_w_list)
        # Push a custom event, but only if the vif existed in the first place
        if vnet_w:
            _push_vif_event(adapter, 'unplug', vnet_w, instance, vif['type'])
    except pvm_ex.HttpError as he:
        # Log the message constructed by HttpError
        LOG.exception("HttpError during vif unplug operation.",
                      instance=instance)
        raise exception.VirtualInterfaceUnplugException(reason=he.args[0])

    if vnet_w:
        slot_mgr.drop_vnet(vnet_w)
Ejemplo n.º 5
0
    def execute(self, lpar_wrap):
        # If the state is not in an OK state for deleting, then throw an
        # error up front.
        modifiable, reason = lpar_wrap.can_modify_io()
        if not modifiable:
            LOG.error(
                "Unable to remove VIFs in the instance's current state. "
                "The reason reported by the system is: %(reason)s",
                {'reason': reason},
                instance=self.instance)
            raise exception.VirtualInterfaceUnplugException(reason=reason)

        # Get all the current Client Network Adapters (CNA) on the VM itself.
        cna_w_list = vm.get_cnas(self.adapter, self.instance)

        # Walk through the VIFs and delete the corresponding CNA on the VM.
        for network_info in self.network_infos:
            vif.unplug(self.adapter,
                       self.host_uuid,
                       self.instance,
                       network_info,
                       self.slot_mgr,
                       cna_w_list=cna_w_list)

        return cna_w_list
Ejemplo n.º 6
0
 def unplug(self, instance, vif):
     vif_type = vif['type']
     if vif_type == model.VIF_TYPE_HYPERV:
         self._vif_plugin.unplug(instance, vif)
     elif vif_type == model.VIF_TYPE_OVS:
         vif = os_vif_util.nova_to_osvif_vif(vif)
         instance = os_vif_util.nova_to_osvif_instance(instance)
         os_vif.unplug(vif, instance)
     else:
         reason = _("unexpected vif_type=%s") % vif_type
         raise exception.VirtualInterfaceUnplugException(reason=reason)
Ejemplo n.º 7
0
def unplug(adapter, instance, vif, cna_w_list=None):
    """Unplugs a virtual interface (network) from a VM.

    :param adapter: The pypowervm adapter.
    :param instance: The nova instance object.
    :param vif: The virtual interface to plug into the instance.
    :param cna_w_list: (Optional, Default: None) The list of Client Network
                       Adapters from pypowervm.  Providing this input
                       allows for an improvement in operation speed.
    """
    vif_drv = _build_vif_driver(adapter, instance, vif)
    try:
        vif_drv.unplug(vif, cna_w_list=cna_w_list)
    except pvm_ex.HttpError as he:
        LOG.exception('VIF unplug failed for instance', instance=instance)
        raise exception.VirtualInterfaceUnplugException(reason=he.args[0])
Ejemplo n.º 8
0
    def unplug(self, vif, cna_w_list=None):
        """Unplugs a virtual interface (network) from a VM.

        This will remove the adapter from the Open vSwitch and delete the
        trunk adapters.

        :param vif: The virtual interface to plug into the instance.
        :param cna_w_list: (Optional, Default: None) The list of Client Network
                           Adapters from pypowervm.  Providing this input
                           allows for an improvement in operation speed.
        :return cna_w: The deleted Client Network Adapter or None if the CNA
                       is not found.
        """
        # Need to find the adapters if they were not provided
        if not cna_w_list:
            cna_w_list = vm.get_cnas(self.adapter, self.instance)

        # Find the CNA for this vif.
        cna_w = self._find_cna_for_vif(cna_w_list, vif)

        if not cna_w:
            LOG.warning(
                'Unable to unplug VIF with mac %s for instance. The '
                'VIF was not found on the instance.',
                vif['address'],
                instance=self.instance)
            return None

        # Find and delete the trunk adapters
        trunks = pvm_cna.find_trunks(self.adapter, cna_w)
        for trunk in trunks:
            trunk.delete()

        # Now delete the client CNA
        LOG.info('Deleting VIF with mac %s for instance.',
                 vif['address'],
                 instance=self.instance)
        try:
            cna_w.delete()
        except Exception as e:
            LOG.error('Unable to unplug VIF with mac %s for instance.',
                      vif['address'],
                      instance=self.instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=six.text_type(e))
        return cna_w
Ejemplo n.º 9
0
 def delete_network_and_bridge(self, instance, vif_id):
     """Delete network and bridge:
     1. delete the patch port pair between the integration bridge and
        the qbr linux bridge(if exist) and the interim network.
     2. destroy the interim network
     3. delete the OVS bridge service for the interim network
     4. delete linux bridge qbr and related ports if exist
     """
     network = self._get_network_by_vif(vif_id)
     if not network:
         return
     vifs = self._session.network.get_VIFs(network)
     bridge_name = self._session.network.get_bridge(network)
     if vifs:
         # Still has vifs attached to this network
         for remain_vif in vifs:
             # if the remain vifs are on the local server, give up all the
             # operations. If the remain vifs are on the remote hosts, keep
             # the network and delete the bridge
             if self._get_host_by_vif(remain_vif) == self._session.host_ref:
                 return
     else:
         # No vif left, delete the network
         try:
             self._session.network.destroy(network)
         except Exception as e:
             LOG.warning(
                 "Failed to destroy network for vif (id=%(if)s), "
                 "exception:%(exception)s", {
                     'if': vif_id,
                     'exception': e
                 },
                 instance=instance)
             raise exception.VirtualInterfaceUnplugException(
                 reason=_("Failed to destroy network"))
     # Two cases:
     # 1) No vif left, just delete the bridge
     # 2) For resize/intra-pool migrate, vifs on both of the
     #    source and target VM will be connected to the same
     #    interim network. If the VM is resident on a remote host,
     #    linux bridge on current host will be deleted.
     self.delete_bridge(instance, vif_id, bridge_name)
Ejemplo n.º 10
0
    def execute(self):
        # If the LPAR is not in an OK state for deleting, then throw an
        # error up front.
        lpar_wrap = vm.get_instance_wrapper(self.adapter, self.instance)
        modifiable, reason = lpar_wrap.can_modify_io()
        if not modifiable:
            LOG.error(
                "Unable to remove VIFs from instance in the system's "
                "current state. The reason reported by the system is: "
                "%s",
                reason,
                instance=self.instance)
            raise exception.VirtualInterfaceUnplugException(reason=reason)

        # Get all the current Client Network Adapters (CNA) on the VM itself.
        cna_w_list = vm.get_cnas(self.adapter, self.instance)

        # Walk through the VIFs and delete the corresponding CNA on the VM.
        for network_info in self.network_infos:
            vif.unplug(self.adapter,
                       self.instance,
                       network_info,
                       cna_w_list=cna_w_list)
Ejemplo n.º 11
0
    def unplug(self, instance, vif, vm_ref):
        """unplug vif:
        1. delete the patch port pair between the integration bridge and
           the qbr linux bridge(if exist) and the interim network.
        2. destroy the interim network
        3. delete the OVS bridge service for the interim network
        4. delete linux bridge qbr and related ports if exist
        """
        super(XenAPIOpenVswitchDriver, self).unplug(instance, vif, vm_ref)

        net_name = self.get_vif_interim_net_name(vif)
        network = network_utils.find_network_with_name_label(
            self._session, net_name)
        if network is None:
            return
        vifs = self._session.network.get_VIFs(network)
        if vifs:
            # only remove the interim network when it's empty.
            # for resize/migrate on local host, vifs on both of the
            # source and target VM will be connected to the same
            # interim network.
            return
        LOG.debug('destroying patch port pair for vif: vif_id=%(vif_id)s',
                  {'vif_id': vif['id']})
        bridge_name = self._session.network.get_bridge(network)
        patch_port1, tap_name = self._get_patch_port_pair_names(vif['id'])
        try:
            # delete the patch port pair
            self._ovs_del_port(bridge_name, patch_port1)
        except Exception as e:
            LOG.warning(_LW("Failed to delete patch port pair for vif %(if)s,"
                            " exception:%(exception)s"), {
                                'if': vif,
                                'exception': e
                            },
                        instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete patch port pair"))

        LOG.debug('destroying network: network=%(network)s,'
                  'bridge=%(br)s', {
                      'network': network,
                      'br': bridge_name
                  })
        try:
            self._session.network.destroy(network)
            # delete bridge if it still exists.
            # As there is patch port existing on this bridge when destroying
            # the VM vif (which happens when shutdown the VM), the bridge
            # won't be destroyed automatically by XAPI. So let's destroy it
            # at here.
            self._ovs_del_br(bridge_name)

            qbr_name = self._get_qbr_name(vif['id'])
            qvb_name, qvo_name = self._get_veth_pair_names(vif['id'])
            if self._device_exists(qbr_name):
                # delete tap port, qvb port and qbr
                LOG.debug(
                    "destroy linux bridge %(qbr)s when unplug vif %(vif)s", {
                        'qbr': qbr_name,
                        'vif': vif['id']
                    })
                self._delete_linux_port(qbr_name, tap_name)
                self._delete_linux_port(qbr_name, qvb_name)
                self._delete_linux_bridge(qbr_name)
            self._ovs_del_port(CONF.xenserver.ovs_integration_bridge, qvo_name)
        except Exception as e:
            LOG.warning(_LW("Failed to delete bridge for vif %(if)s, "
                            "exception:%(exception)s"), {
                                'if': vif,
                                'exception': e
                            },
                        instance=instance)
            raise exception.VirtualInterfaceUnplugException(
                reason=_("Failed to delete bridge"))