diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 0d444c69d1e0..44e147632f36 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -1770,32 +1770,6 @@ class NeutronLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver): iptables_manager = IptablesManager() -def set_vf_interface_vlan(pci_addr, mac_addr, vlan=0): - pf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr, - pf_interface=True) - vf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr) - vf_num = pci_utils.get_vf_num_by_pci_address(pci_addr) - - # Set the VF's mac address and vlan - exit_code = [0, 2, 254] - port_state = 'up' if vlan > 0 else 'down' - utils.execute('ip', 'link', 'set', pf_ifname, - 'vf', vf_num, - 'mac', mac_addr, - 'vlan', vlan, - run_as_root=True, - check_exit_code=exit_code) - # Bring up/down the VF's interface - # TODO(edand): The mac is assigned as a workaround for the following issue - # https://bugzilla.redhat.com/show_bug.cgi?id=1372944 - # once resolved it will be removed - utils.execute('ip', 'link', 'set', vf_ifname, - 'address', mac_addr, - port_state, - run_as_root=True, - check_exit_code=exit_code) - - def set_vf_trusted(pci_addr, trusted): """Configures the VF to be trusted or not diff --git a/nova/network/linux_utils.py b/nova/network/linux_utils.py index 8498b8010f82..15ca3b91293a 100644 --- a/nova/network/linux_utils.py +++ b/nova/network/linux_utils.py @@ -23,6 +23,7 @@ from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import excutils +from nova.pci import utils as pci_utils from nova import utils @@ -93,3 +94,29 @@ def create_tap_dev(dev, mac_address=None, multiqueue=False): run_as_root=True, check_exit_code=[0, 2, 254]) utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True, check_exit_code=[0, 2, 254]) + + +def set_vf_interface_vlan(pci_addr, mac_addr, vlan=0): + pf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr, + pf_interface=True) + vf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr) + vf_num = pci_utils.get_vf_num_by_pci_address(pci_addr) + + # Set the VF's mac address and vlan + exit_code = [0, 2, 254] + port_state = 'up' if vlan > 0 else 'down' + utils.execute('ip', 'link', 'set', pf_ifname, + 'vf', vf_num, + 'mac', mac_addr, + 'vlan', vlan, + run_as_root=True, + check_exit_code=exit_code) + # Bring up/down the VF's interface + # TODO(edand): The mac is assigned as a workaround for the following issue + # https://bugzilla.redhat.com/show_bug.cgi?id=1372944 + # once resolved it will be removed + utils.execute('ip', 'link', 'set', vf_ifname, + 'address', mac_addr, + port_state, + run_as_root=True, + check_exit_code=exit_code) diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index 9903f07aef93..efd9309426e5 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -618,7 +618,7 @@ class LibvirtGenericVIFDriver(object): # TODO(vladikr): This code can be removed once the minimum version of # Libvirt is incleased above 1.3.5, as vlan will be set by libvirt if vif['vnic_type'] == network_model.VNIC_TYPE_MACVTAP: - linux_net.set_vf_interface_vlan( + linux_net_utils.set_vf_interface_vlan( vif['profile']['pci_slot'], mac_addr=vif['address'], vlan=vif['details'][network_model.VIF_DETAILS_VLAN]) @@ -788,8 +788,8 @@ class LibvirtGenericVIFDriver(object): # The ip utility doesn't accept the MAC 00:00:00:00:00:00. # Therefore, keep the MAC unchanged. Later operations on # the same VF will not be affected by the existing MAC. - linux_net.set_vf_interface_vlan(vif['profile']['pci_slot'], - mac_addr=vif['address']) + linux_net_utils.set_vf_interface_vlan(vif['profile']['pci_slot'], + mac_addr=vif['address']) def unplug_hostdev_physical(self, instance, vif): pass