Пример #1
0
    def _plug_bridge_with_port(self, instance, vif, port):
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute('tee',
                          ('/sys/class/net/%s/bridge/multicast_snooping' %
                           br_name),
                          process_input='0',
                          run_as_root=True,
                          check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            if port == 'ovs':
                linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                              v2_name, iface_id,
                                              vif['address'], instance.uuid)
            elif port == 'ivs':
                linux_net.create_ivs_vif_port(v2_name, iface_id,
                                              vif['address'], instance.uuid)
Пример #2
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        super(LibvirtGenericVIFDriver,
              self).plug(instance, vif)

        network, mapping = vif
        iface_id = self.get_ovs_interfaceid(mapping)
        br_name = self.get_br_name(mapping['vif_uuid'])
        v1_name, v2_name = self.get_veth_pair_names(mapping['vif_uuid'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(self.get_bridge_name(network),
                                          v2_name, iface_id, mapping['mac'],
                                          instance['uuid'])
Пример #3
0
    def plug(self, instance, vif, port='ovs'):
        iface_id = self._get_ovs_interfaceid(vif)
        br_name = self._get_br_name(vif['id'])
        v1_name, v2_name = self._get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute('tee',
                          ('/sys/class/net/%s/bridge/multicast_snooping' %
                           br_name),
                          process_input='0',
                          run_as_root=True,
                          check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            if port == 'ovs':
                linux_net.create_ovs_vif_port(self._get_bridge_name(vif),
                                              v2_name, iface_id,
                                              vif['address'], instance.uuid)
            elif port == 'ivs':
                linux_net.create_ivs_vif_port(v2_name, iface_id,
                                              vif['address'], instance.uuid)
Пример #4
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via an ovs internal port device. Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        vm_port_name = self.get_vm_ovs_port_name(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute('tee',
                          ('/sys/class/net/%s/bridge/multicast_snooping' %
                           br_name),
                          process_input='0',
                          run_as_root=True,
                          check_exit_code=[0, 1])

        #fix bridge's state is down after host reboot.
        linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                      vm_port_name, iface_id,
                                      vif['address'], instance['uuid'],
                                      internal=True)
        utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)

        try:
            utils.execute('brctl', 'addif', br_name, vm_port_name,
                            run_as_root=True)
        except processutils.ProcessExecutionError:
            pass
Пример #5
0
 def plug_vhostuser(self, instance, vif):
     ovs_plug = vif["details"].get(network_model.VIF_DETAILS_VHOSTUSER_OVS_PLUG, False)
     if ovs_plug:
         iface_id = self.get_ovs_interfaceid(vif)
         port_name = os.path.basename(vif["details"][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
         linux_net.create_ovs_vif_port(self.get_bridge_name(vif), port_name, iface_id, vif["address"], instance.uuid)
         linux_net.ovs_set_vhostuser_port_type(port_name)
Пример #6
0
    def plug(self, vif, slot_num, new_vif=True):
        """Plugs a virtual interface (network) into a VM.

        Extends the Lio implementation.  Will make sure that the trunk device
        has the appropriate metadata (ex. port id) set on it so that the
        Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        :param new_vif: (Optional, Default: True) If set, indicates that it is
                        a brand new VIF.  If False, it indicates that the VIF
                        is already on the client but should be treated on the
                        bridge.
        :return: The new vif that was created.  Only returned if new_vif is
                 set to True.  Otherwise None is expected.
        """
        cna_w = super(PvmOvsVifDriver, self).plug(vif,
                                                  slot_num,
                                                  new_vif=new_vif)
        dev_name = self.get_trunk_dev_name(vif)
        # There will only be one trunk wrap, as we have created with just the
        # mgmt lpar.  Next step is to connect to the OVS.
        mtu = vif['network'].get_meta('mtu')
        linux_net.create_ovs_vif_port(vif['network']['bridge'],
                                      dev_name,
                                      self.get_ovs_interfaceid(vif),
                                      vif['address'],
                                      self.instance.uuid,
                                      mtu=mtu)

        return cna_w
Пример #7
0
    def plug_ovs(self, instance, vif):
        LOG.info('8888888888888')
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        bridge = vif['network']['bridge']

        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return
        undo_mgr = utils.UndoManager()

        try:
            LOG.info('7777777aaaa')
            LOG.info('ip', 'link', 'add', 'name', if_local_name, 'type',
                          'veth', 'peer', 'name', if_remote_name,
                          run_as_root=True)
            utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type',
                          'veth', 'peer', 'name', if_remote_name,
                          run_as_root=True)
            linux_net.create_ovs_vif_port(bridge, if_local_name,
                                          network.get_ovs_interfaceid(vif),
                                          vif['address'],
                                          instance['uuid'])
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
        except Exception:
            LOG.exception("Failed to configure network")
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Пример #8
0
    def plug_ovs(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard LXC mechanisms.
        """
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute(
                'tee',
                ('/sys/class/net/%s/bridge/multicast_snooping' % br_name),
                process_input='0',
                run_as_root=True,
                check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(self.get_bridge_name(vif), v2_name,
                                          iface_id, vif['address'],
                                          instance['uuid'])

        container_utils.write_lxc_usernet(instance, br_name)
Пример #9
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        super(LibvirtGenericVIFDriver,
              self).plug(instance, vif)

        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                          v2_name, iface_id, vif['address'],
                                          instance['uuid'])
Пример #10
0
 def plug_hw_veb(self, instance, vif):
     if vif['vnic_type'] == network_model.VNIC_TYPE_MACVTAP:
         linux_net.set_vf_interface_vlan(
             vif['profile']['pci_slot'],
             mac_addr=vif['address'],
             vlan=vif['details'][network_model.VIF_DETAILS_VLAN])
     # add by bob
     if CONF.acc.nic_vender == 'netronome' or CONF.acc.nic_vender == 'Netronome':
         bridge = CONF.acc.ovs_bridge
         netro = NetronomeResourceManage(bridge_name=bridge)
         port_name = netro.get_port_name_by_pci_slot(
             vif['profile']['pci_slot'])
         port_id = netro.get_port_id(port_name)
         iface_id = self.get_ovs_interfaceid(vif)
         mtu = vif['network'].get_meta('mtu')
         if port_name:
             linux_net.create_ovs_vif_port(bridge, port_name, iface_id,
                                           vif['address'], instance.uuid,
                                           mtu)
             LOG.debug("Success add port:%s on bridge:%s" %
                       (port_name, bridge))
             netro.bind_port(port_id, iface_id, instance.uuid)
         else:
             LOG.debug("Fail add port on bridge:%s with pci_slot:%s" %
                       (bridge, vif['profile']['pci_slot']))
Пример #11
0
    def plug_vhostuser_fp(self, instance, vif):
        """Create a fp netdevice interface with a vhostuser socket"""
        dev = self.get_vif_devname(vif)
        if linux_net.device_exists(dev):
            return

        ovs_plug = vif['details'].get(
            network_model.VIF_DETAILS_VHOSTUSER_OVS_PLUG, False)
        sockmode_qemu, sockpath = self._get_vhostuser_settings(vif)
        sockmode_port = 'client' if sockmode_qemu == 'server' else 'server'

        try:
            linux_net.create_fp_dev(dev, sockpath, sockmode_port)

            if ovs_plug:
                if vif.is_hybrid_plug_enabled():
                    self.plug_ovs_hybrid(instance, vif)
                    utils.execute('brctl',
                                  'addif',
                                  self.get_br_name(vif['id']),
                                  dev,
                                  run_as_root=True)
                else:
                    iface_id = self.get_ovs_interfaceid(vif)
                    mtu = vif['network'].get_meta('mtu')
                    linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                                  dev, iface_id,
                                                  vif['address'],
                                                  instance.uuid, mtu)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while plugging vif"), instance=instance)
Пример #12
0
    def _plug_bridge_with_port(self, instance, vif, port):
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif["id"])
        v1_name, v2_name = self.get_veth_pair_names(vif["id"])

        if not linux_net.device_exists(br_name):
            utils.execute("brctl", "addbr", br_name, run_as_root=True)
            utils.execute("brctl", "setfd", br_name, 0, run_as_root=True)
            utils.execute("brctl", "stp", br_name, "off", run_as_root=True)
            utils.execute(
                "tee",
                ("/sys/class/net/%s/bridge/multicast_snooping" % br_name),
                process_input="0",
                run_as_root=True,
                check_exit_code=[0, 1],
            )

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute("ip", "link", "set", br_name, "up", run_as_root=True)
            utils.execute("brctl", "addif", br_name, v1_name, run_as_root=True)
            if port == "ovs":
                linux_net.create_ovs_vif_port(
                    self.get_bridge_name(vif), v2_name, iface_id, vif["address"], instance.uuid
                )
            elif port == "ivs":
                linux_net.create_ivs_vif_port(v2_name, iface_id, vif["address"], instance.uuid)
Пример #13
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        super(LibvirtGenericVIFDriver,
              self).plug(instance, vif)

        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute('tee',
                          ('/sys/class/net/%s/bridge/multicast_snooping' %
                           br_name),
                          process_input='0',
                          run_as_root=True,
                          check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                          v2_name, iface_id, vif['address'],
                                          instance['uuid'])
Пример #14
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard libvirt mechanisms.
        """
        super(LibvirtGenericVIFDriver, self).plug(instance, vif)

        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif["id"])
        v1_name, v2_name = self.get_veth_pair_names(vif["id"])

        if not linux_net.device_exists(br_name):
            utils.execute("brctl", "addbr", br_name, run_as_root=True)
            utils.execute("brctl", "setfd", br_name, 0, run_as_root=True)
            utils.execute("brctl", "stp", br_name, "off", run_as_root=True)
            utils.execute(
                "tee",
                ("/sys/class/net/%s/bridge/multicast_snooping" % br_name),
                process_input="0",
                run_as_root=True,
                check_exit_code=[0, 1],
            )

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute("ip", "link", "set", br_name, "up", run_as_root=True)
            utils.execute("brctl", "addif", br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(
                self.get_bridge_name(vif), v2_name, iface_id, vif["address"], instance["uuid"]
            )
Пример #15
0
    def plug_vhostuser_fp(self, instance, vif):
        """Create a fp netdevice interface with a vhostuser socket"""
        dev = self.get_vif_devname(vif)
        if linux_net.device_exists(dev):
            return

        ovs_plug = vif['details'].get(
                                network_model.VIF_DETAILS_VHOSTUSER_OVS_PLUG,
                                False)
        sockmode_qemu, sockpath = self._get_vhostuser_settings(vif)
        sockmode_port = 'client' if sockmode_qemu == 'server' else 'server'

        try:
            linux_net.create_fp_dev(dev, sockpath, sockmode_port)

            if ovs_plug:
                if vif.is_hybrid_plug_enabled():
                    self.plug_ovs_hybrid(instance, vif)
                    utils.execute('brctl', 'addif',
                                  self.get_br_name(vif['id']),
                                  dev, run_as_root=True)
                else:
                    iface_id = self.get_ovs_interfaceid(vif)
                    mtu = vif['network'].get_meta('mtu')
                    linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                                  dev, iface_id,
                                                  vif['address'],
                                                  instance.uuid, mtu)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while plugging vif"), instance=instance)
Пример #16
0
    def plug_ovs(self, instance, vif):
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        bridge = vif['network']['bridge']

        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return
        undo_mgr = utils.UndoManager()

        try:
            utils.execute('ip',
                          'link',
                          'add',
                          'name',
                          if_local_name,
                          'type',
                          'veth',
                          'peer',
                          'name',
                          if_remote_name,
                          run_as_root=True)
            linux_net.create_ovs_vif_port(bridge, if_local_name,
                                          network.get_ovs_interfaceid(vif),
                                          vif['address'], instance['uuid'])
            utils.execute('ip',
                          'link',
                          'set',
                          if_local_name,
                          'up',
                          run_as_root=True)
        except Exception:
            LOG.exception("Failed to configure network")
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Пример #17
0
 def plug(self, instance, vif):
     network, mapping = vif
     iface_id = self.get_ovs_interfaceid(mapping)
     dev = self.get_vif_devname(mapping)
     linux_net.create_tap_dev(dev)
     linux_net.create_ovs_vif_port(self.get_bridge_name(network), dev,
                                   iface_id, mapping['mac'],
                                   instance['uuid'])
Пример #18
0
 def plug(self, instance, vif):
     network, mapping = vif
     iface_id = self.get_ovs_interfaceid(mapping)
     dev = self.get_vif_devname(mapping)
     linux_net.create_tap_dev(dev)
     linux_net.create_ovs_vif_port(self.get_bridge_name(network),
                                   dev, iface_id, mapping['mac'],
                                   instance['uuid'])
Пример #19
0
 def plug_vhostuser_ovs(self, instance, vif):
     """Plug a VIF_TYPE_VHOSTUSER into an ovs bridge"""
     iface_id = self.get_ovs_interfaceid(vif)
     port_name = os.path.basename(
         vif['details'][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
     linux_net.create_ovs_vif_port(self.get_bridge_name(vif), port_name,
                                   iface_id, vif['address'], instance.uuid)
     linux_net.ovs_set_vhostuser_port_type(port_name)
Пример #20
0
Файл: vif.py Проект: vasart/nova
    def plug_ovs_ethernet(self, instance, vif):
        super(LibvirtGenericVIFDriver, self).plug(instance, vif)

        iface_id = self.get_ovs_interfaceid(vif)
        dev = self.get_vif_devname(vif)
        linux_net.create_tap_dev(dev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(vif), dev, iface_id,
                                      vif['address'], instance['uuid'])
Пример #21
0
    def plug_ovs_ethernet(self, instance, vif):
        super(LibvirtGenericVIFDriver, self).plug(instance, vif)

        network, mapping = vif
        iface_id = self.get_ovs_interfaceid(mapping)
        dev = self.get_vif_devname(mapping)
        linux_net.create_tap_dev(dev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(network), dev, iface_id, mapping["mac"], instance["uuid"])
Пример #22
0
    def plug_ovs_ethernet(self, instance, vif):
        super(LibvirtGenericVIFDriver, self).plug(instance, vif)

        network = vif["network"]
        iface_id = self.get_ovs_interfaceid(vif)
        dev = self.get_vif_devname(vif)
        linux_net.create_tap_dev(dev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(vif), dev, iface_id, vif["address"], instance["uuid"])
Пример #23
0
    def plug_ovs(self, container, instance, vif):
        iface_id = self._get_ovs_interfaceid(vif)
        dev = self._get_vif_devname(vif)
        linux_net.create_tap_dev(dev)
        linux_net.create_ovs_vif_port(self._get_vif_bridge(vif),
                                      dev, iface_id, vif['address'],
                                      instance['uuid'])

        self.setup_lxc_network(container, instance, vif)
Пример #24
0
 def plug_vhostuser_ovs(self, instance, vif):
     """Plug a VIF_TYPE_VHOSTUSER into an ovs bridge"""
     iface_id = self.get_ovs_interfaceid(vif)
     port_name = os.path.basename(
         vif['details'][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
     linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                   port_name, iface_id, vif['address'],
                                   instance.uuid)
     linux_net.ovs_set_vhostuser_port_type(port_name)
Пример #25
0
    def plug_ovs_ethernet(self, instance, vif):
        super(LibvirtGenericVIFDriver, self).plug(instance, vif)

        network, mapping = vif
        iface_id = self.get_ovs_interfaceid(mapping)
        dev = self.get_vif_devname(mapping)
        linux_net.create_tap_dev(dev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(network), dev,
                                      iface_id, mapping['mac'],
                                      instance['uuid'])
Пример #26
0
 def plug_vhostuser(self, instance, vif):
     ovs_plug = vif['details'].get(
         network_model.VIF_DETAILS_VHOSTUSER_OVS_PLUG, False)
     if ovs_plug:
         iface_id = self.get_ovs_interfaceid(vif)
         port_name = os.path.basename(
             vif['details'][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
         linux_net.create_ovs_vif_port(self.get_bridge_name(vif), port_name,
                                       iface_id, vif['address'],
                                       instance['uuid'])
         linux_net.ovs_set_vhostuser_port_type(port_name)
Пример #27
0
    def plug(self, driver, instance, sdk_ve, vif):
        iface_id = self.get_ovs_interfaceid(vif)
        if_name = vif['devname']

        netdev = self.setup_prl_dev(driver, sdk_ve, vif)

        prl_name = self.get_prl_name(sdk_ve, netdev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(vif), prl_name,
                                      iface_id, vif['address'],
                                      instance['uuid'])
        self.configure_ip(sdk_ve, netdev, vif)
Пример #28
0
 def plug_vhostuser_ovs(self, instance, vif):
     """Plug a VIF_TYPE_VHOSTUSER into an ovs bridge"""
     iface_id = self.get_ovs_interfaceid(vif)
     port_name = os.path.basename(
         vif['details'][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
     mtu = vif['network'].get_meta('mtu')
     linux_net.create_ovs_vif_port(
         self.get_bridge_name(vif),
         port_name, iface_id, vif['address'],
         instance.uuid, mtu,
         interface_type=network_model.OVS_VHOSTUSER_INTERFACE_TYPE)
Пример #29
0
    def plug(self, driver, instance, sdk_ve, vif):
        iface_id = self.get_ovs_interfaceid(vif)
        if_name = vif['devname']

        netdev = self.setup_prl_dev(driver, sdk_ve, vif)

        prl_name = self.get_prl_name(sdk_ve, netdev)
        linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                        prl_name, iface_id, vif['address'],
                                        instance['uuid'])
        self.configure_ip(sdk_ve, netdev, vif)
Пример #30
0
 def plug_vhostuser_ovs(self, instance, vif):
     """Plug a VIF_TYPE_VHOSTUSER into an ovs bridge"""
     iface_id = self.get_ovs_interfaceid(vif)
     port_name = os.path.basename(
         vif['details'][network_model.VIF_DETAILS_VHOSTUSER_SOCKET])
     mtu = vif['network'].get_meta('mtu')
     linux_net.create_ovs_vif_port(
         self.get_bridge_name(vif),
         port_name, iface_id, vif['address'],
         instance.uuid, mtu,
         interface_type=network_model.OVS_VHOSTUSER_INTERFACE_TYPE)
Пример #31
0
    def pre_live_migrate_at_destination(self, vif, vea_vlan_mappings):
        """Performs the pre live migrate on the destination host.

        This method will create the trunk adapter on the destination host,
        set its link state up, and attach it to the integration OVS switch.
        It also updates the vea_vlan_mappings to indicate which unique
        hypervisor VLAN should be used for this VIF for the migration operation
        to complete properly.

        :param vif: The virtual interface that will be migrated.  This may be
                    called network_info in other portions of the code.
        :param vea_vlan_mappings: The VEA VLAN mappings.  Key is the vif
                                  mac address, value is the destination's
                                  target hypervisor VLAN.
        """
        self._cleanup_orphan_adapters(vif,
                                      CONF.powervm.pvm_vswitch_for_novalink_io)
        mgmt_wrap = pvm_par.get_this_partition(self.adapter)
        dev = self.get_trunk_dev_name(vif)

        # Find a specific free VLAN and create the Trunk in a single atomic
        # action.
        cna_w = pvm_cna.crt_trunk_with_free_vlan(
            self.adapter,
            self.host_uuid, [mgmt_wrap.uuid],
            CONF.powervm.pvm_vswitch_for_novalink_io,
            dev_name=dev)[0]

        # Bring the vif up.  This signals to neutron that its ready for vif
        # plugging
        utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)
        linux_net.create_ovs_vif_port(vif['network']['bridge'], dev,
                                      self.get_ovs_interfaceid(vif),
                                      vif['address'], self.instance.uuid)

        # Save this data for the migration command.
        vea_vlan_mappings[vif['address']] = cna_w.pvid
        LOG.info(
            "VIF with mac %(mac)s is going on trunk %(dev)s with PVID "
            "%(pvid)s", {
                'mac': vif['address'],
                'dev': dev,
                'pvid': cna_w.pvid
            },
            instance=self.instance)
Пример #32
0
def _post_plug_wiring_veth_and_bridge(instance, vif):
    config = get_config(vif)
    network = vif.get('network')
    mtu = network.get_meta('mtu') if network else None
    v1_name = get_vif_devname(vif)
    v2_name = get_vif_internal_devname(vif)
    if not linux_net.device_exists(v1_name):
        _create_veth_pair(v1_name, v2_name, mtu)
        if _is_ovs_vif_port(vif):
            # NOTE(jamespage): wire tap device directly to ovs bridge
            linux_net.create_ovs_vif_port(vif['network']['bridge'], v1_name,
                                          vif['id'], vif['address'],
                                          instance.uuid, mtu)
        else:
            # NOTE(jamespage): wire tap device linux bridge
            _add_bridge_port(config['bridge'], v1_name)
    else:
        linux_net._set_device_mtu(v1_name, mtu)
Пример #33
0
    def plug_ovs(self, instance_id, vif):
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        bridge = vif['network']['bridge']
        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return

        try:
            utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type',
                          'veth', 'peer', 'name', if_remote_name,
                          run_as_root=True)
            linux_net.create_ovs_vif_port(bridge, if_local_name,
                                          network.get_ovs_interfaceid(vif),
                                          vif['address'],
                                          instance_id)
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
        except Exception:
            LOG.exception("Failed to configure network")
            msg = _('Failed to setup the network, rolling back')
Пример #34
0
    def plug(self, vif, slot_num):
        """Plugs a virtual interface (network) into a VM.

        Extends the Lio implementation.  Will make sure that the trunk device
        has the appropriate metadata (ex. port id) set on it so that the
        Open vSwitch agent picks it up properly.

        :param vif: The virtual interface to plug into the instance.
        :param slot_num: Which slot number to plug the VIF into.  May be None.
        """
        cna_w = super(PvmOvsVifDriver, self).plug(vif, slot_num)

        # There will only be one trunk wrap, as we have created with just the
        # mgmt lpar.  Next step is to set the device up and connect to the OVS
        dev_name = self.get_trunk_dev_name(vif)
        utils.execute('ip', 'link', 'set', dev_name, 'up', run_as_root=True)
        linux_net.create_ovs_vif_port(vif['network']['bridge'], dev_name,
                                      self.get_ovs_interfaceid(vif),
                                      vif['address'], self.instance.uuid)

        return cna_w
Пример #35
0
    def post_live_migrate_at_destination(self, vif):
        """Performs live migrate cleanup on the destination host.

        This is optional, child classes do not need to implement this.

        :param vif: The virtual interface that was migrated.
        """
        # 1) Find a free vlan to use
        # 2) Update the migrated CNA to use the new vlan that was found
        #    and ensure that the CNA is enabled
        # 3) Create a trunk adapter on the destination of the migration
        #    using the same vlan as the CNA

        mgmt_wrap = pvm_par.get_this_partition(self.adapter)
        dev_name = self.get_trunk_dev_name(vif)
        mac = pvm_util.sanitize_mac_for_api(vif['address'])

        # Get vlan
        vswitch_w = pvm_net.VSwitch.search(
            self.adapter, parent_type=pvm_ms.System.schema_type,
            one_result=True, parent_uuid=self.host_uuid,
            name=CONF.powervm.pvm_vswitch_for_novalink_io)
        cna = pvm_net.CNA.search(
            self.adapter, mac=mac, one_result=True, parent_type=pvm_lpar.LPAR,
            parent_uuid=vm.get_pvm_uuid(self.instance))

        # Assigns a free vlan (which is returned) to the cna_list
        # also enable the cna
        cna = pvm_cna.assign_free_vlan(
            self.adapter, self.host_uuid, vswitch_w, cna)
        # Create a trunk with the vlan_id
        trunk_adpt = pvm_net.CNA.bld(
            self.adapter, cna.pvid, vswitch_w.related_href, trunk_pri=1,
            dev_name=dev_name)
        trunk_adpt.create(parent=mgmt_wrap)

        utils.execute('ip', 'link', 'set', dev_name, 'up', run_as_root=True)
        linux_net.create_ovs_vif_port(vif['network']['bridge'], dev_name,
                                      self.get_ovs_interfaceid(vif),
                                      vif['address'], self.instance.uuid)
Пример #36
0
 def plug_ovs_acc(self, instance, vif):
     """No manual plugging required."""
     # add by bob
     #if CONF.acc.nic_vender == 'netronome' or CONF.acc.nic_vender == 'Netronome':
     bridge = CONF.acc.ovs_bridge
     netro = NetronomeResourceManage(bridge_name=bridge)
     iface_id = self.get_ovs_interfaceid(vif)
     port_id = netro.get_available_port(iface_id)
     port_name = netro.get_port_name(port_id)
     mtu = vif['network'].get_meta('mtu')
     if port_name:
         linux_net.create_ovs_vif_port(bridge,
                                       port_name,
                                       iface_id,
                                       vif['address'],
                                       instance.uuid,
                                       mtu,
                                       virtio_relay=port_id)
         LOG.debug("Success add port:%s on bridge:%s" % (port_name, bridge))
         netro.bind_port(port_id, iface_id, instance.uuid)
     else:
         LOG.debug("Fail add port on bridge:%s " % (bridge))
Пример #37
0
    def plug_ovs(self, instance, vif, container_id):
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        bridge = vif['network']['bridge']
        gateway = network.find_gateway(instance, vif['network'])
        ip = network.find_fixed_ip(instance, vif['network'])

        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return
        undo_mgr = utils.UndoManager()

        try:
            utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type',
                          'veth', 'peer', 'name', if_remote_name,
                          run_as_root=True)
            linux_net.create_ovs_vif_port(bridge, if_local_name,
                                          network.get_ovs_interfaceid(vif),
                                          vif['address'],
                                          instance['uuid'])
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
            utils.execute('ip', 'link', 'set', if_remote_name, 'netns',
                          container_id, run_as_root=True)
            utils.execute('ip', 'netns', 'exec', container_id, 'ip', 'link',
                          'set', if_remote_name, 'address', vif['address'],
                          run_as_root=True)
            utils.execute('ip', 'netns', 'exec', container_id, 'ifconfig',
                          if_remote_name, ip, run_as_root=True)
            utils.execute('ip', 'netns', 'exec', container_id,
                          'ip', 'route', 'replace', 'default', 'via',
                          gateway, 'dev', if_remote_name, run_as_root=True)

        except Exception:
            LOG.exception("Failed to configure network")
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Пример #38
0
    def plug(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge using standard libvirt mechanisms
        """

        network, mapping = vif
        iface_id = self.get_ovs_interfaceid(mapping)
        br_name = self.get_br_name(mapping['vif_uuid'])
        v1_name, v2_name = self.get_veth_pair_names(mapping['vif_uuid'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)

        if not linux_net.device_exists(v2_name):
            linux_net._create_veth_pair(v1_name, v2_name)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            linux_net.create_ovs_vif_port(self.get_bridge_name(network),
                                          v2_name, iface_id, mapping['mac'],
                                          instance['uuid'])
Пример #39
0
    def _plug_bridge_with_port(self, instance, vif, port):
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            utils.execute('brctl', 'addbr', br_name, run_as_root=True)
            utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
            utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
            utils.execute('tee',
                          ('/sys/class/net/%s/bridge/multicast_snooping' %
                           br_name),
                          process_input='0',
                          run_as_root=True,
                          check_exit_code=[0, 1])
            disv6 = '/proc/sys/net/ipv6/conf/%s/disable_ipv6' % br_name
            if os.path.exists(disv6):
                utils.execute('tee',
                              disv6,
                              process_input='1',
                              run_as_root=True,
                              check_exit_code=[0, 1])

        if not linux_net.device_exists(v2_name):
            mtu = vif['network'].get_meta('mtu')
            linux_net._create_veth_pair(v1_name, v2_name, mtu)
            utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
            utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
            if port == 'ovs':
                linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                              v2_name, iface_id,
                                              vif['address'], instance.uuid,
                                              mtu)
            elif port == 'ivs':
                linux_net.create_ivs_vif_port(v2_name, iface_id,
                                              vif['address'], instance.uuid)
Пример #40
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge. and connect the tap port to linux bridge
        """

        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return
        undo_mgr = utils.UndoManager()

        try:
            if not linux_net.device_exists(br_name):
                utils.execute('brctl', 'addbr', br_name, run_as_root=True)
                # Incase of failure undo the Steps
                # Deleting/Undoing the interface will delete all
                # associated resources
                undo_mgr.undo_with(lambda: utils.execute(
                    'brctl', 'delbr', br_name, run_as_root=True))
                # LOG.exception('Throw Test exception with bridgename %s'
                # % br_name)

                utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
                utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
                utils.execute('tee',
                              ('/sys/class/net/%s/bridge/multicast_snooping' %
                               br_name),
                              process_input='0',
                              run_as_root=True,
                              check_exit_code=[0, 1])

            if not linux_net.device_exists(v2_name):
                linux_net._create_veth_pair(v1_name, v2_name)
                undo_mgr.undo_with(lambda: utils.execute(
                    'ip', 'link', 'delete', v1_name, run_as_root=True))

                utils.execute('ip', 'link', 'set', br_name, 'up',
                              run_as_root=True)
                undo_mgr.undo_with(lambda: utils.execute('ip', 'link', 'set',
                                                         br_name, 'down',
                                                         run_as_root=True))

                # Deleting/Undoing the interface will delete all
                # associated resources (remove from the bridge, its
                # pair, etc...)
                utils.execute('brctl', 'addif', br_name, v1_name,
                              run_as_root=True)

                linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                              v2_name,
                                              iface_id, vif['address'],
                                              instance['uuid'])
                undo_mgr.undo_with(
                    lambda: utils.execute('ovs-vsctl', 'del-port',
                                          self.get_bridge_name(vif),
                                          v2_name, run_as_root=True))

            utils.execute('ip', 'link', 'add', 'name', if_local_name, 'type',
                          'veth', 'peer', 'name', if_remote_name,
                          run_as_root=True)
            undo_mgr.undo_with(
                lambda: utils.execute('ip', 'link', 'delete', if_local_name,
                                      run_as_root=True))

            # Deleting/Undoing the interface will delete all
            # associated resources (remove from the bridge, its pair, etc...)
            utils.execute('brctl', 'addif', br_name, if_local_name,
                          run_as_root=True)
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
        except Exception:
            msg = "Failed to configure Network." \
                " Rolling back the network interfaces %s %s %s %s " % (
                    br_name, if_local_name, v1_name, v2_name)
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Пример #41
0
def plug_ovs_hybrid(instance, vif, ovsport_info, vlan_id):
    """Plug using hybrid strategy

    Create a per-VIF linux bridge, then link that bridge to the OVS
    integration bridge via a veth device, setting up the other end
    of the veth device just like a normal OVS port.  Then boot the
    VIF on the linux bridge using standard libvirt mechanisms.
    """

    iface_id = get_ovs_interfaceid(vif)
    br_name = get_br_name(vif['id'])
    v1_name, v2_name = get_veth_pair_names(vif['id'])
    gbr_name = get_gbr_name(vif['id'])
    tap_name, taq_name = get_gveth_pair_names(vif['id'])
    ovs_nicport = ovsport_info['ovs_ethport']
    vlan_tag = str(vlan_id)
    nic_name = ovs_nicport + '.' + vlan_tag

    # add the first gbr to connect to the origin qbr
    if not linux_net.device_exists(gbr_name):
        utils.execute('brctl', 'addbr', gbr_name, run_as_root=True)
        utils.execute('brctl', 'setfd', gbr_name, 0, run_as_root=True)
        utils.execute('brctl', 'stp', gbr_name, 'off', run_as_root=True)
        utils.execute('tee',
                      ('/sys/class/net/%s/bridge/multicast_snooping' %
                       gbr_name),
                      process_input='0',
                      run_as_root=True,
                      check_exit_code=[0, 1])

        if linux_net.device_exists(nic_name):
            # try to delete the exists nic_name in whatever br
            utils.execute('vconfig', 'rem', nic_name, run_as_root=True)

    if not linux_net.device_exists(tap_name):
        linux_net._create_veth_pair(tap_name, taq_name)
        utils.execute(
            'ip',
            'link',
            'set',
            gbr_name,
            'up',
            run_as_root=True)
        utils.execute(
            'brctl',
            'addif',
            gbr_name,
            taq_name,
            run_as_root=True)

    # add the second qbr to connect to the origin ovs br-int
    if not linux_net.device_exists(br_name):
        utils.execute('brctl', 'addbr', br_name, run_as_root=True)
        utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
        utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
        utils.execute('tee',
                      ('/sys/class/net/%s/bridge/multicast_snooping' %
                       br_name),
                      process_input='0',
                      run_as_root=True,
                      check_exit_code=[0, 1])
        utils.execute(
            'brctl',
            'addif',
            br_name,
            tap_name,
            run_as_root=True)

    if not linux_net.device_exists(v2_name):
        linux_net._create_veth_pair(v1_name, v2_name)
        utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
        utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
        linux_net.create_ovs_vif_port(get_bridge_name(vif),
                                      v2_name, iface_id, vif['address'],
                                      instance['uuid'])

    # connect qbrxxxx to nic
    if not linux_net.device_exists(nic_name):
        try:
            # ifup ovs_ethport
            utils.execute('ifconfig', ovs_nicport, 'up', run_as_root=True)

            # add brif
            utils.execute('vconfig', 'add', ovs_nicport, vlan_tag,
                          run_as_root=True)

            # up the if
            utils.execute('ifconfig', nic_name, 'up', run_as_root=True)

            connect_nic_to_br(instance, gbr_name, nic_name)
        except Exception as exc:
            LOG.exception(exc, instance=instance)
        LOG.debug(
            'Connect nic to br finished, vir:%s',
            vif,
            instance=instance)
Пример #42
0
    def plug_ovs_hybrid(self, instance, vif):
        """Plug using hybrid strategy

        Create a per-VIF linux bridge, then link that bridge to the OVS
        integration bridge via a veth device, setting up the other end
        of the veth device just like a normal OVS port.  Then boot the
        VIF on the linux bridge. and connect the tap port to linux bridge
        """

        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        iface_id = self.get_ovs_interfaceid(vif)
        br_name = self.get_br_name(vif['id'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        # Device already exists so return.
        if linux_net.device_exists(if_local_name):
            return
        undo_mgr = utils.UndoManager()

        try:
            if not linux_net.device_exists(br_name):
                utils.execute('brctl', 'addbr', br_name, run_as_root=True)
                # Incase of failure undo the Steps
                # Deleting/Undoing the interface will delete all
                # associated resources
                undo_mgr.undo_with(lambda: utils.execute(
                    'brctl', 'delbr', br_name, run_as_root=True))
                # LOG.exception('Throw Test exception with bridgename %s'
                # % br_name)

                utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
                utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
                utils.execute(
                    'tee',
                    ('/sys/class/net/%s/bridge/multicast_snooping' % br_name),
                    process_input='0',
                    run_as_root=True,
                    check_exit_code=[0, 1])

            if not linux_net.device_exists(v2_name):
                linux_net._create_veth_pair(v1_name, v2_name)
                undo_mgr.undo_with(lambda: utils.execute(
                    'ip', 'link', 'delete', v1_name, run_as_root=True))

                utils.execute('ip',
                              'link',
                              'set',
                              br_name,
                              'up',
                              run_as_root=True)
                undo_mgr.undo_with(lambda: utils.execute(
                    'ip', 'link', 'set', br_name, 'down', run_as_root=True))

                # Deleting/Undoing the interface will delete all
                # associated resources (remove from the bridge, its
                # pair, etc...)
                utils.execute('brctl',
                              'addif',
                              br_name,
                              v1_name,
                              run_as_root=True)

                linux_net.create_ovs_vif_port(self.get_bridge_name(vif),
                                              v2_name, iface_id,
                                              vif['address'], instance['uuid'])
                undo_mgr.undo_with(
                    lambda: utils.execute('ovs-vsctl',
                                          'del-port',
                                          self.get_bridge_name(vif),
                                          v2_name,
                                          run_as_root=True))

            utils.execute('ip',
                          'link',
                          'add',
                          'name',
                          if_local_name,
                          'type',
                          'veth',
                          'peer',
                          'name',
                          if_remote_name,
                          run_as_root=True)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))

            # Deleting/Undoing the interface will delete all
            # associated resources (remove from the bridge, its pair, etc...)
            utils.execute('brctl',
                          'addif',
                          br_name,
                          if_local_name,
                          run_as_root=True)
            utils.execute('ip',
                          'link',
                          'set',
                          if_local_name,
                          'up',
                          run_as_root=True)
        except Exception:
            msg = "Failed to configure Network." \
                " Rolling back the network interfaces %s %s %s %s " % (
                    br_name, if_local_name, v1_name, v2_name)
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Пример #43
0
 def _ovs_vif_port(self, calls):
     with mock.patch.object(utils, 'execute', return_value=('', '')) as ex:
         linux_net.create_ovs_vif_port('fake-bridge', 'fake-dev',
                                       'fake-iface-id', 'fake-mac',
                                       'fake-instance-uuid')
         ex.assert_has_calls(calls)
Пример #44
0
 def _ovs_vif_port(self, calls):
     with mock.patch.object(utils, "execute", return_value=("", "")) as ex:
         linux_net.create_ovs_vif_port("fake-bridge", "fake-dev", "fake-iface-id", "fake-mac", "fake-instance-uuid")
         ex.assert_has_calls(calls)
Пример #45
0
 def _ovs_vif_port(self, calls):
     with mock.patch.object(utils, 'execute', return_value=('', '')) as ex:
         linux_net.create_ovs_vif_port('fake-bridge', 'fake-dev',
                                       'fake-iface-id', 'fake-mac',
                                       'fake-instance-uuid')
         ex.assert_has_calls(calls)
Пример #46
0
def plug_ovs_hybrid(instance, vif, ovsport_info, vlan_id):
    """Plug using hybrid strategy

    Create a per-VIF linux bridge, then link that bridge to the OVS
    integration bridge via a veth device, setting up the other end
    of the veth device just like a normal OVS port.  Then boot the
    VIF on the linux bridge using standard libvirt mechanisms.
    """

    iface_id = get_ovs_interfaceid(vif)
    br_name = get_br_name(vif['id'])
    v1_name, v2_name = get_veth_pair_names(vif['id'])
    gbr_name = get_gbr_name(vif['id'])
    tap_name, taq_name = get_gveth_pair_names(vif['id'])
    ovs_nicport = ovsport_info['ovs_ethport']
    vlan_tag = str(vlan_id)
    nic_name = ovs_nicport + '.' + vlan_tag

    # add the first gbr to connect to the origin qbr
    if not linux_net.device_exists(gbr_name):
        utils.execute('brctl', 'addbr', gbr_name, run_as_root=True)
        utils.execute('brctl', 'setfd', gbr_name, 0, run_as_root=True)
        utils.execute('brctl', 'stp', gbr_name, 'off', run_as_root=True)
        utils.execute(
            'tee', ('/sys/class/net/%s/bridge/multicast_snooping' % gbr_name),
            process_input='0',
            run_as_root=True,
            check_exit_code=[0, 1])

        if linux_net.device_exists(nic_name):
            # try to delete the exists nic_name in whatever br
            utils.execute('vconfig', 'rem', nic_name, run_as_root=True)

    if not linux_net.device_exists(tap_name):
        linux_net._create_veth_pair(tap_name, taq_name)
        utils.execute('ip', 'link', 'set', gbr_name, 'up', run_as_root=True)
        utils.execute('brctl', 'addif', gbr_name, taq_name, run_as_root=True)

    # add the second qbr to connect to the origin ovs br-int
    if not linux_net.device_exists(br_name):
        utils.execute('brctl', 'addbr', br_name, run_as_root=True)
        utils.execute('brctl', 'setfd', br_name, 0, run_as_root=True)
        utils.execute('brctl', 'stp', br_name, 'off', run_as_root=True)
        utils.execute(
            'tee', ('/sys/class/net/%s/bridge/multicast_snooping' % br_name),
            process_input='0',
            run_as_root=True,
            check_exit_code=[0, 1])
        utils.execute('brctl', 'addif', br_name, tap_name, run_as_root=True)

    if not linux_net.device_exists(v2_name):
        linux_net._create_veth_pair(v1_name, v2_name)
        utils.execute('ip', 'link', 'set', br_name, 'up', run_as_root=True)
        utils.execute('brctl', 'addif', br_name, v1_name, run_as_root=True)
        linux_net.create_ovs_vif_port(get_bridge_name(vif), v2_name, iface_id,
                                      vif['address'], instance['uuid'])

    # connect qbrxxxx to nic
    if not linux_net.device_exists(nic_name):
        try:
            # ifup ovs_ethport
            utils.execute('ifconfig', ovs_nicport, 'up', run_as_root=True)

            # add brif
            utils.execute('vconfig',
                          'add',
                          ovs_nicport,
                          vlan_tag,
                          run_as_root=True)

            # up the if
            utils.execute('ifconfig', nic_name, 'up', run_as_root=True)

            connect_nic_to_br(instance, gbr_name, nic_name)
        except Exception as exc:
            LOG.exception(exc, instance=instance)
        LOG.debug('Connect nic to br finished, vir:%s', vif, instance=instance)