Esempio n. 1
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"]
            )
Esempio n. 2
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS port.  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'])
        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)
            nova.privsep.libvirt.disable_multicast_snooping(br_name)
            nova.privsep.libvirt.disable_ipv6(br_name)

        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)
            linux_net.create_ivs_vif_port(v2_name, iface_id,
                                          vif['address'], instance.uuid)
Esempio n. 3
0
    def plug(self, driver, instance, sdk_ve, vif):
        iface_id = self.get_ovs_interfaceid(vif)
        if_name = vif['devname']
        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)

        netdev = self.setup_prl_dev(driver, sdk_ve, vif)
        prl_name = self.get_prl_name(sdk_ve, netdev)
        if_name = prl_name

        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)
            pcs_create_ovs_vif_port(self.get_bridge_name(vif), v2_name,
                                    iface_id, prl_name, vif['address'],
                                    instance['uuid'])

        if if_name not in get_bridge_ifaces(br_name):
            utils.execute('brctl', 'addif', br_name, if_name, run_as_root=True)

        self.configure_ip(sdk_ve, netdev, vif)

        if sdk_ve.get_vm_type() == pc.PVT_VM and \
                if_name not in get_bridge_ifaces(br_name):
            # FIXME: dispatcher removes interface from bridge after
            # changing configuration
            utils.execute('brctl', 'addif', br_name, if_name, run_as_root=True)
Esempio n. 4
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 = mapping['vif_uuid']
        br_name = self.get_br_name(iface_id)
        v1_name, v2_name = self.get_veth_pair_names(iface_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)
            self.create_ovs_vif_port(v2_name, iface_id, mapping['mac'],
                                     instance['uuid'])

        network['bridge'] = br_name
        return self._get_configurations(instance, network, mapping)
Esempio n. 5
0
    def plug(self, driver, instance, sdk_ve, vif):
        iface_id = self.get_ovs_interfaceid(vif)
        if_name = vif['devname']
        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)

        netdev = self.setup_prl_dev(driver, sdk_ve, vif)
        prl_name = self.get_prl_name(sdk_ve, netdev)
        if_name = prl_name

        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)
            pcs_create_ovs_vif_port(self.get_bridge_name(vif), v2_name,
                                    iface_id, prl_name, vif['address'],
                                    instance['uuid'])

        if if_name not in get_bridge_ifaces(br_name):
            utils.execute('brctl', 'addif', br_name, if_name, run_as_root=True)

        self.configure_ip(sdk_ve, netdev, vif)

        if sdk_ve.get_vm_type() == pc.PVT_VM and \
                if_name not in get_bridge_ifaces(br_name):
            # FIXME: dispatcher removes interface from bridge after
            # changing configuration
            utils.execute('brctl', 'addif', br_name, if_name, run_as_root=True)
Esempio n. 6
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS port.  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'])
        v1_name, v2_name = self.get_veth_pair_names(vif['id'])

        if not linux_net.device_exists(br_name):
            nova.privsep.libvirt.add_bridge(br_name)
            nova.privsep.libvirt.zero_bridge_forward_delay(br_name)
            nova.privsep.libvirt.disable_bridge_stp(br_name)
            nova.privsep.libvirt.disable_multicast_snooping(br_name)
            nova.privsep.libvirt.disable_ipv6(br_name)

        if not linux_net.device_exists(v2_name):
            mtu = vif['network'].get_meta('mtu')
            linux_net._create_veth_pair(v1_name, v2_name, mtu)
            nova.privsep.libvirt.toggle_interface(br_name, 'up')
            nova.privsep.libvirt.bridge_add_interface(br_name, v1_name)
            linux_net.create_ivs_vif_port(v2_name, iface_id, vif['address'],
                                          instance.uuid)
Esempio n. 7
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS 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_ivs_vif_port(v2_name, iface_id, vif['address'],
                                          instance['uuid'])
Esempio n. 8
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'])
Esempio n. 9
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS 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_ivs_vif_port(v2_name, iface_id, vif['address'],
                                          instance['uuid'])
Esempio n. 10
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)
Esempio n. 11
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'])
Esempio n. 12
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)
Esempio n. 13
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 = mapping['vif_uuid']
        br_name = self.get_br_name(iface_id)
        v1_name, v2_name = self.get_veth_pair_names(iface_id)

        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)
            self.create_ovs_vif_port(v2_name, iface_id, mapping['mac'],
                                     instance['uuid'])

        network['bridge'] = br_name
        return self._get_configurations(instance, network, mapping)
Esempio n. 14
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS 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_ivs_vif_port(v2_name, iface_id, vif["address"], instance["uuid"])
Esempio n. 15
0
File: vif.py Progetto: isyippee/nova
    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)
Esempio n. 16
0
    def plug_ivs_hybrid(self, instance, vif):
        """Plug using hybrid strategy (same as OVS)

        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 IVS port.  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'])
        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)
            linux_net.create_ivs_vif_port(v2_name, iface_id, vif['address'],
                                          instance.uuid)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
0
 def _create_veth_pair(self, calls):
     with mock.patch.object(utils, 'execute', return_value=('', '')) as ex:
         linux_net._create_veth_pair('fake-dev1', 'fake-dev2')
         ex.assert_has_calls(calls)
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
0
 def _create_veth_pair(self, calls):
     with mock.patch.object(utils, "execute", return_value=("", "")) as ex:
         linux_net._create_veth_pair("fake-dev1", "fake-dev2")
         ex.assert_has_calls(calls)
Esempio n. 23
0
 def _create_veth_pair(self, calls):
     with mock.patch.object(utils, 'execute', return_value=('', '')) as ex:
         linux_net._create_veth_pair('fake-dev1', 'fake-dev2')
         ex.assert_has_calls(calls)
Esempio n. 24
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)