Move set_vf_interface_vlan to the new utility module.

Continued moving of methods which aren't unique to nova-net out of
linux_net.

Change-Id: Ie3a7155d4d27f5d856755e385e012d9b5bf3d061
blueprint: remove-nova-network
This commit is contained in:
Michael Still 2018-03-30 08:38:32 +11:00 committed by Matt Riedemann
parent f9a0c1917c
commit 724c42419e
3 changed files with 30 additions and 29 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,7 +788,7 @@ 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'],
linux_net_utils.set_vf_interface_vlan(vif['profile']['pci_slot'],
mac_addr=vif['address'])
def unplug_hostdev_physical(self, instance, vif):