Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
    def unplug_vhostuser(self, instance, vif):
        """UnPlug using hybrid strategy

        Unhook port from EVS, unhook port from ebr-pcy bridge, delete
        bridge, and delete ovs port.
        """

        ebr_int_name = 'ebr-int'
        vm_ebr_pcy_name = self.get_vm_pcy_ebr_name(vif['id'])
        vm_pcy_tap_name = self.get_vm_pcy_tap_name(vif['id'])
        pcy_patch_port_name, int_patch_port_name = self.get_ebr_veth_pair_names(vif['id'])

        try:
            #anomaly of evs or hugemem which leads to ifconfig ebr-int not found
            if not linux_net.device_exists(ebr_int_name):
                LOG.error("evs intergragation bridge %s doesnot exist !" % ebr_int_name)
                raise Exception

            if linux_net.device_exists(vm_ebr_pcy_name):
                linux_net.delete_evs_port(vm_ebr_pcy_name, vm_pcy_tap_name)
                linux_net.delete_evs_port(vm_ebr_pcy_name, pcy_patch_port_name)
                
                #delete flows of patch_port in ebr-int
                integ_ebr_port_ofport = linux_net.get_evs_port_ofport(int_patch_port_name)
                linux_net.delete_evs_flows(ebr_int_name, integ_ebr_port_ofport)
                
                linux_net.delete_evs_port(ebr_int_name, int_patch_port_name)
                linux_net.delete_evs_bridge(vm_ebr_pcy_name)

        except processutils.ProcessExecutionError:
            LOG.error("detach virtio port failed when excute unplug_vhostuser!")
Beispiel #4
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)
Beispiel #5
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"]
            )
Beispiel #6
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'])
Beispiel #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)
            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"])
Beispiel #8
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)
Beispiel #9
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)
Beispiel #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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #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)

        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'])
Beispiel #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)

        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'])
Beispiel #15
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'])
Beispiel #16
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)
Beispiel #17
0
    def unplug_ovs_hybrid(
            self, instance, vif, ovsport_info, portgroup_instance_mapping):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """

        # now dirver use the configed nic eth0.100 instead
        ovs_nicport = ovsport_info['ovs_ethport']
        vlan_tag = str(portgroup_instance_mapping.vlan)
        nic_name = ovs_nicport + '.' + vlan_tag

        # remove the eth1 vlan config
        try:
            # try to delete the exists nic_name in whatever br
            utils.execute('vconfig', 'rem', nic_name, run_as_root=True)
        except Exception as exc:
            LOG.exception(exc, instance=instance)

        try:
            br_name = self.get_br_name(vif['id'])
            v1_name, v2_name = self.get_veth_pair_names(vif['id'])
            gbr_name = self.get_gbr_name(vif['id'])
            tap_name, taq_name = self.get_gveth_pair_names(vif['id'])

            if linux_net.device_exists(br_name):
                utils.execute('brctl', 'delif', br_name, v1_name,
                              run_as_root=True)
                utils.execute('brctl', 'delif', br_name, tap_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', br_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name,
                              run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif),
                                          v2_name)

            if linux_net.device_exists(gbr_name):
                utils.execute('brctl', 'delif', gbr_name, taq_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', gbr_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', gbr_name,
                              run_as_root=True)

            # delete veth peer
            linux_net.delete_net_dev(v1_name)
            linux_net.delete_net_dev(v2_name)
            linux_net.delete_net_dev(tap_name)
            linux_net.delete_net_dev(taq_name)
        except Exception as exc:
            LOG.exception(exc, instance=instance)
Beispiel #18
0
    def plug_iovisor(self, instance, vif):
        """Plug docker vif into IOvisor

        Creates a port on IOvisor and onboards the interface
        """
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]

        iface_id = vif['id']
        net_id = vif['network']['id']
        tenant_id = instance['project_id']

        # 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)
            utils.execute('ifc_ctl', 'gateway', 'add_port', if_local_name,
                          run_as_root=True)
            utils.execute('ifc_ctl', 'gateway', 'ifup', if_local_name,
                          'access_vm',
                          vif['network']['label'] + "_" + iface_id,
                          vif['address'], 'pgtag2=%s' % net_id,
                          'pgtag1=%s' % tenant_id, run_as_root=True)
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)

        except Exception:
            LOG.exception("Failed to configure network on IOvisor")
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Beispiel #19
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        if not linux_net.device_exists(dev):
            # Older version of the command 'ip' from the iproute2 package
            # don't have support for the tuntap option (lp:882568).  If it
            # turns out we're on an old version we work around this by using
            # tunctl.
            try:
                # First, try with 'ip'
                utils.execute('ip', 'tuntap', 'add', dev, 'mode', 'tap',
                          run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute('tunctl', '-b', '-t', dev, run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)

        self.create_ovs_vif_port(dev, iface_id, mapping['mac'],
                                 instance['uuid'])

        conf = vconfig.LibvirtConfigGuestInterface()

        if CONF.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"
        conf.net_type = "ethernet"
        conf.target_dev = dev
        conf.script = ""
        conf.mac_addr = mapping['mac']

        return conf
Beispiel #20
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        if not linux_net.device_exists(dev):
            # Older version of the command 'ip' from the iproute2 package
            # don't have support for the tuntap option (lp:882568).  If it
            # turns out we're on an old version we work around this by using
            # tunctl.
            try:
                # First, try with 'ip'
                utils.execute('ip',
                              'tuntap',
                              'add',
                              dev,
                              'mode',
                              'tap',
                              run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute('tunctl', '-b', '-t', dev, run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)

        self.create_ovs_vif_port(dev, iface_id, mapping['mac'],
                                 instance['uuid'])
Beispiel #21
0
    def plug_bridge(self, instance, vif):
        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)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            # NOTE(samalba): Deleting the interface will delete all
            # associated resources (remove from the bridge, its pair, etc...)
            utils.execute('brctl', 'addif', bridge, if_local_name,
                          run_as_root=True)
            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)
Beispiel #22
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
Beispiel #23
0
    def plug(self, instance, vif):
        vif_type = vif['type']

        LOG.debug('Plug vif_type=%(vif_type)s instance=%(instance)s '
                  'vif=%(vif)s',
                  {'vif_type': vif_type, 'instance': instance,
                   'vif': vif})

        if_local_name = 'veth%s' % vif['id'][:8]
        if_remote_name = 'ns%s' % vif['id'][:8]

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

        try:
            utils.execute('ip', 'link', 'add', 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))

            utils.execute('ip', 'link', 'set', if_remote_name, 'address',
                          vif['address'], 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)
Beispiel #24
0
    def plug_iovisor(self, instance, vif):
        """Plug docker vif into IOvisor

        Creates a port on IOvisor and onboards the interface
        """
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]

        iface_id = vif['id']
        net_id = vif['network']['id']
        tenant_id = instance['project_id']

        # 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)
            utils.execute('ifc_ctl', 'gateway', 'add_port', if_local_name,
                          run_as_root=True)
            utils.execute('ifc_ctl', 'gateway', 'ifup', if_local_name,
                          'access_vm',
                          vif['network']['label'] + "_" + iface_id,
                          vif['address'], 'pgtag2=%s' % net_id,
                          'pgtag1=%s' % tenant_id, run_as_root=True)
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)

        except Exception:
            LOG.exception("Failed to configure network on IOvisor")
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
Beispiel #25
0
    def unplug_ovs_hybrid(self, instance, vif):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """
        super(LibvirtGenericVIFDriver,
              self).unplug(instance, vif)

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

            if linux_net.device_exists(br_name):
                utils.execute('brctl', 'delif', br_name, v1_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', br_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name,
                              run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif),
                                          v2_name)
        except processutils.ProcessExecutionError:
            LOG.exception(_("Failed while unplugging vif"), instance=instance)
Beispiel #26
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)
Beispiel #27
0
    def plug_midonet(self, instance, vif):
        """Plug into MidoNet's network port

        This accomplishes binding of the vif to a MidoNet virtual port
        """
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        port_id = network.get_ovs_interfaceid(vif)

        # 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)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
            utils.execute('mm-ctl', '--bind-port', port_id, if_local_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)
    def plug(self, instance, vif):
        vif_type = vif['type']

        LOG.debug('Plug vif_type=%(vif_type)s instance=%(instance)s '
                  'vif=%(vif)s',
                  {'vif_type': vif_type, 'instance': instance,
                   'vif': vif})

        if_local_name = 'veth%s' % vif['id'][:8]
        if_remote_name = 'ns%s' % vif['id'][:8]

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

        try:
            utils.execute('ip', 'link', 'add', 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))

            utils.execute('ip', 'link', 'set', if_remote_name, 'address',
                          vif['address'], 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)
Beispiel #29
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)
Beispiel #30
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)
Beispiel #31
0
    def plug_midonet(self, instance, vif):
        """Plug into MidoNet's network port

        This accomplishes binding of the vif to a MidoNet virtual port
        """
        LOG.info('2222')
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        port_id = network.get_ovs_interfaceid(vif)

        # 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)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            utils.execute('ip', 'link', 'set', if_local_name, 'up',
                          run_as_root=True)
            utils.execute('mm-ctl', '--bind-port', port_id, if_local_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)
Beispiel #32
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)
Beispiel #33
0
    def unplug_ovs_hybrid(self, instance, vif):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """
        super(LibvirtGenericVIFDriver,
              self).unplug(instance, vif)

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

            if linux_net.device_exists(br_name):
                utils.execute('brctl', 'delif', br_name, v1_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', br_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name,
                              run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif),
                                          v2_name)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while unplugging vif"),
                          instance=instance)
Beispiel #34
0
    def plug_bridge(self, instance_id, vif):
        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_id, vif['network'])

        vlan = vif.get('vlan')
        if vlan is not None:
            iface = (CONF.vlan_interface
                     or vif['network'].get_meta('bridge_interface'))
            linux_net.LinuxBridgeInterfaceDriver.ensure_vlan_bridge(
                vlan, bridge, iface, net_attrs=vif, mtu=vif.get('mtu'))
            iface = 'vlan%s' % vlan
        else:
            iface = (CONF.flat_interface
                     or vif['network'].get_meta('bridge_interface'))
            LOG.debug('Ensuring bridge for %s - %s' % (iface, bridge))
            linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(bridge,
                                                               iface,
                                                               net_attrs=vif,
                                                               gateway=gateway)

        # 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)
            utils.execute('ip',
                          'link',
                          'set',
                          if_local_name,
                          'address',
                          self._fe_random_mac(),
                          run_as_root=True)
            utils.execute('brctl',
                          'addif',
                          bridge,
                          if_local_name,
                          run_as_root=True)
            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')
Beispiel #35
0
    def attach(self, instance, vif, container_id):
        vif_type = vif['type']
        if_local_name = 'tap%s' % vif['id'][:11]
        if_remote_name = 'ns%s' % vif['id'][:11]
        gateways = network.find_gateways(instance, vif['network'])
        ips = network.find_fixed_ips(instance, vif['network'])

        LOG.debug('attach vif_type=%(vif_type)s instance=%(instance)s '
                  'vif=%(vif)s',
                  {'vif_type': vif_type, 'instance': instance,
                   'vif': vif})

        if not linux_net.device_exists(if_local_name):
            br_name = vif['network']['bridge']
            if (vif_type == network_model.VIF_TYPE_OVS
                    and self.ovs_hybrid_required(vif)):
                br_name = self.get_br_name(vif['id'])
            self._create_veth_pair(if_local_name, if_remote_name, br_name)

        try:
            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)
            for ip in ips:
                utils.execute('ip', 'netns', 'exec', container_id, 'ip',
                              'addr', 'add', ip, 'dev', if_remote_name,
                              run_as_root=True)
            utils.execute('ip', 'netns', 'exec', container_id, 'ip', 'link',
                          'set', if_remote_name, 'up', run_as_root=True)

            # Setup MTU on if_remote_name is required if it is a non
            # default value
            mtu = None
            if vif.get('mtu') is not None:
                mtu = vif.get('mtu')
            if mtu is not None:
                utils.execute('ip', 'netns', 'exec', container_id, 'ip',
                              'link', 'set', if_remote_name, 'mtu', mtu,
                              run_as_root=True)

            for gateway in gateways:
                utils.execute('ip', 'netns', 'exec', container_id,
                              'ip', 'route', 'replace', 'default', 'via',
                              gateway, 'dev', if_remote_name, run_as_root=True)

            # Disable TSO, for now no config option
            utils.execute('ip', 'netns', 'exec', container_id, 'ethtool',
                          '--offload', if_remote_name, 'tso', 'off',
                          run_as_root=True)

        except Exception:
            LOG.exception("Failed to attach vif")
Beispiel #36
0
    def plug_vhostuser(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)
        ebr_int_name = EBR_INT
        vm_ebr_pcy_name = self.get_vm_pcy_ebr_name(vif['id'])
        vm_pcy_tap_name = self.get_vm_pcy_tap_name(vif['id'])
        pcy_patch_port_name, int_patch_port_name = self.get_ebr_veth_pair_names(vif['id'])

        numa_id =None
        physnet = vif['details'].get(PHYSICAL_NETWORK,None)
        if physnet != None:
            numa_id = utils.get_numa_id_by_physical_network(physnet)

        try:
            if not linux_net.device_exists(ebr_int_name):
                LOG.error("evs intergragation bridge %s doesnot exist !" % ebr_int_name)
                raise Exception

            if not linux_net.device_exists(vm_ebr_pcy_name):
                linux_net.create_evs_dpdk_br(vm_ebr_pcy_name)
                linux_net.create_evs_patch_port(ebr_int_name, int_patch_port_name, pcy_patch_port_name)
                linux_net.create_evs_patch_port(vm_ebr_pcy_name, pcy_patch_port_name, int_patch_port_name)

            if numa_id != None and numa_id != -1:
                linux_net.create_evs_virtio_port_bind_numa(vm_ebr_pcy_name,
                                       vm_pcy_tap_name, numa_id, iface_id,
                                      vif['address'], instance['uuid'],
                                       internal=False)
            else:
                linux_net.create_evs_virtio_port(vm_ebr_pcy_name,
                                 vm_pcy_tap_name, iface_id,
                                  vif['address'], instance['uuid'],
                                 internal=False)

        except processutils.ProcessExecutionError,e:
            LOG.error("create ebr-pcy bridge or attatch virtio port failed! error is %s "%e)
Beispiel #37
0
    def unplug(self, instance, vif):
        try:
            br_name = self._get_br_name(vif['id'])
            v1_name, v2_name = self._get_veth_pair_names(vif['id'])

            if linux_net.device_exists(br_name):
                utils.execute('brctl', 'delif', br_name, v1_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', br_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name,
                              run_as_root=True)

            linux_net.delete_ovs_vif_port(self._get_bridge_name(vif),
                                          v2_name)
            if linux_net.device_exists(v2_name):
                utils.execute('ip', 'link', 'set', v2_name, 'down',
                              run_as_root=True)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while unplugging vif"),
                          instance=instance)
Beispiel #38
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

        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)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while plugging vif"), instance=instance)
Beispiel #39
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

        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)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while plugging vif"), instance=instance)
Beispiel #40
0
 def plug_tap(self, instance, vif):
     """Plug a VIF_TYPE_TAP virtual interface."""
     v1_name = get_vif_devname(vif)
     v2_name = get_vif_internal_devname(vif)
     network = vif.get('network')
     mtu = network.get_meta('mtu') if network else None
     # NOTE(jamespage): For nova-lxd this is really a veth pair
     #                  so that a) security rules get applied on the host
     #                  and b) that the container can still be wired.
     if not linux_net.device_exists(v1_name):
         _create_veth_pair(v1_name, v2_name, mtu)
     else:
         linux_net._set_device_mtu(v1_name, mtu)
Beispiel #41
0
    def plug_bridge(self, instance, vif):
        LOG.info('5555')
        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'])

        vlan = vif.get('vlan')
        if vlan is not None:
            iface = (CONF.vlan_interface or
                     vif['network'].get_meta('bridge_interface'))
            linux_net.LinuxBridgeInterfaceDriver.ensure_vlan_bridge(
                vlan,
                bridge,
                iface,
                net_attrs=vif,
                mtu=vif.get('mtu'))
            iface = 'vlan%s' % vlan
        else:
            iface = (CONF.flat_interface or
                     vif['network'].get_meta('bridge_interface'))
            LOG.debug('Ensuring bridge for %s - %s' % (iface, bridge))
            linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(
                bridge,
                iface,
                net_attrs=vif,
                gateway=gateway)

        # 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)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            # NOTE(samalba): Deleting the interface will delete all
            # associated resources (remove from the bridge, its pair, etc...)
            utils.execute('ip', 'link', 'set', if_local_name, 'address',
                          self._fe_random_mac(), run_as_root=True)
            utils.execute('brctl', 'addif', bridge, if_local_name,
                          run_as_root=True)
            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)
Beispiel #42
0
    def plug_bridge(self, instance, vif):
        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'])

        net = vif['network']
        if net.get_meta('should_create_vlan', False):
            vlan = net.get_meta('vlan'),
            iface = (CONF.vlan_interface or
                     vif['network'].get_meta('bridge_interface'))
            linux_net.LinuxBridgeInterfaceDriver.ensure_vlan_bridge(
                vlan,
                bridge,
                iface,
                net_attrs=vif,
                mtu=vif.get('mtu'))
            iface = 'vlan%s' % vlan
        else:
            iface = (CONF.flat_interface or
                     vif['network'].get_meta('bridge_interface'))
            LOG.debug('Ensuring bridge for %s - %s' % (iface, bridge))
            linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(
                bridge,
                iface,
                net_attrs=vif,
                gateway=gateway)

        # 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)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            # NOTE(samalba): Deleting the interface will delete all
            # associated resources (remove from the bridge, its pair, etc...)
            utils.execute('ip', 'link', 'set', if_local_name, 'address',
                          self._fe_random_mac(), run_as_root=True)
            utils.execute('brctl', 'addif', bridge, if_local_name,
                          run_as_root=True)
            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)
Beispiel #43
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)
Beispiel #44
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)
Beispiel #45
0
    def unplug(self, instance, vif):
        vif_type = vif['type']
        if_local_name = 'veth%s' % vif['id'][:8]

        LOG.debug('Unplug vif_type=%(vif_type)s instance=%(instance)s '
                  'vif=%(vif)s',
                  {'vif_type': vif_type, 'instance': instance,
                   'vif': vif})

        try:
            self._vrouter_client.delete_port(vif['id'])
            if linux_net.device_exists(if_local_name):
                utils.execute('ip', 'link', 'delete', if_local_name,
                              run_as_root=True)
        except Exception:
            LOG.exception("Delete port failed", instance=instance)
    def unplug(self, instance, vif):
        vif_type = vif['type']
        if_local_name = 'veth%s' % vif['id'][:8]

        LOG.debug('Unplug vif_type=%(vif_type)s instance=%(instance)s '
                  'vif=%(vif)s',
                  {'vif_type': vif_type, 'instance': instance,
                   'vif': vif})

        try:
            self._vrouter_client.delete_port(vif['id'])
            if linux_net.device_exists(if_local_name):
                utils.execute('ip', 'link', 'delete', if_local_name,
                              run_as_root=True)
        except Exception:
            LOG.exception(_("Delete port failed"), instance=instance)
Beispiel #47
0
    def setup_prl_dev(self, driver, sdk_ve, vif):
        """Sets up device in VE, so that one end will be inside
        VE with given MAC. Another end - in host with specified
        device name.
        """
        if_name = vif['devname']

        netdev = self.get_prl_dev(driver, sdk_ve, vif['address'])
        if not netdev:
            netdev = self.create_prl_dev(driver, sdk_ve, vif)
        prl_name = self.get_prl_name(sdk_ve, netdev)

        if not linux_net.device_exists(if_name):
            utils.execute('ip', 'link', 'set', prl_name,
                          'up', run_as_root=True)
        return netdev
Beispiel #48
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)
Beispiel #49
0
    def unplug_ovs_hybrid(self, instance, vif):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete both veth devices.
        """
        try:
            br_name = self.get_br_name(vif["id"])
            v1_name, v2_name = self.get_veth_pair_names(vif["id"])

            if linux_net.device_exists(br_name):
                utils.execute("brctl", "delif", br_name, v1_name, run_as_root=True)
                utils.execute("ip", "link", "set", br_name, "down", run_as_root=True)
                utils.execute("brctl", "delbr", br_name, run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif), v2_name)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while unplugging vif"), instance=instance)
Beispiel #50
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping["vif_uuid"]
        dev = self.get_dev_name(iface_id)
        if not linux_net.device_exists(dev):
            # Older version of the command 'ip' from the iproute2 package
            # don't have support for the tuntap option (lp:882568).  If it
            # turns out we're on an old version we work around this by using
            # tunctl.
            try:
                # First, try with 'ip'
                utils.execute("ip", "tuntap", "add", dev, "mode", "tap", run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute("tunctl", "-b", "-t", dev, run_as_root=True)
            utils.execute("ip", "link", "set", dev, "up", run_as_root=True)

        self.create_ovs_vif_port(network["bridge"], dev, iface_id, mapping["mac"], instance["uuid"])
Beispiel #51
0
    def plug_bridge(self, instance_id, vif):
        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_id, vif['network'])

        vlan = vif.get('vlan')
        if vlan is not None:
            iface = (CONF.vlan_interface or
                     vif['network'].get_meta('bridge_interface'))
            linux_net.LinuxBridgeInterfaceDriver.ensure_vlan_bridge(
                vlan,
                bridge,
                iface,
                net_attrs=vif,
                mtu=vif.get('mtu'))
            iface = 'vlan%s' % vlan
        else:
            iface = (CONF.flat_interface or
                     vif['network'].get_meta('bridge_interface'))
            LOG.debug('Ensuring bridge for %s - %s' % (iface, bridge))
            linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(
                bridge,
                iface,
                net_attrs=vif,
                gateway=gateway)

        # 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)
            utils.execute('ip', 'link', 'set', if_local_name, 'address',
                          self._fe_random_mac(), run_as_root=True)
            utils.execute('brctl', 'addif', bridge, if_local_name,
                          run_as_root=True)
            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')
Beispiel #52
0
    def setup_prl_dev(self, driver, sdk_ve, vif):
        """Sets up device in VE, so that one end will be inside
        VE with given MAC. Another end - in host with specified
        device name.
        """
        if_name = vif['devname']

        netdev = self.get_prl_dev(driver, sdk_ve, vif['address'])
        if not netdev:
            netdev = self.create_prl_dev(driver, sdk_ve, vif)
        prl_name = self.get_prl_name(sdk_ve, netdev)

        if not linux_net.device_exists(if_name):
            utils.execute('ip',
                          'link',
                          'set',
                          prl_name,
                          'up',
                          run_as_root=True)
        return netdev
Beispiel #53
0
    def unplug_ovs(self, instance, vif):
        try:
            br_name = self.get_br_name(vif['id'])
            v1_name, v2_name = self.get_veth_pair_names(vif['id'])

            if linux_net.device_exists(br_name):
                utils.execute('brctl',
                              'delif',
                              br_name,
                              v1_name,
                              run_as_root=True)
                utils.execute('ip',
                              'link',
                              'set',
                              br_name,
                              'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name, run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif), v2_name)
        except processutils.ProcessExecutionError:
            LOG.exception(_("Failed while unplugging vif"), instance=instance)
Beispiel #54
0
    def unplug_ovs_hybrid(self, instance, vif):
        """UnPlug using hybrid strategy

        Unhook port from OVS, unhook port from bridge, delete
        bridge, and delete ovs port.
        """

        try:
            br_name = self.get_br_name(vif['id'])
            vm_port_name = self.get_vm_ovs_port_name(vif['id'])

            if linux_net.device_exists(br_name):
                utils.execute('brctl', 'delif', br_name, vm_port_name,
                              run_as_root=True)
                utils.execute('ip', 'link', 'set', br_name, 'down',
                              run_as_root=True)
                utils.execute('brctl', 'delbr', br_name,
                              run_as_root=True)

            linux_net.delete_ovs_vif_port(self.get_bridge_name(vif),
                                          vm_port_name)
        except processutils.ProcessExecutionError:
            LOG.exception(_LE("Failed while unplugging vif"),
                          instance=instance)
Beispiel #55
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        if not linux_net.device_exists(dev):
            # Older version of the command 'ip' from the iproute2 package
            # don't have support for the tuntap option (lp:882568).  If it
            # turns out we're on an old version we work around this by using
            # tunctl.
            try:
                # First, try with 'ip'
                utils.execute('ip',
                              'tuntap',
                              'add',
                              dev,
                              'mode',
                              'tap',
                              run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute('tunctl', '-b', '-t', dev, run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)

        self.create_ovs_vif_port(dev, iface_id, mapping['mac'],
                                 instance['uuid'])

        conf = vconfig.LibvirtConfigGuestInterface()

        if CONF.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"
        conf.net_type = "ethernet"
        conf.target_dev = dev
        conf.script = ""
        conf.mac_addr = mapping['mac']

        return conf