nm ovs: Support ovs internal interface
Support the creation of an ovs internal interface at the nm provider level. Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
parent
476e729b5b
commit
6f9b4801cf
@ -97,6 +97,12 @@ def create_port_setting(options):
|
||||
return port_setting
|
||||
|
||||
|
||||
def create_interface_setting():
|
||||
interface_setting = nmclient.NM.SettingOvsInterface.new()
|
||||
interface_setting.props.type = 'internal'
|
||||
return interface_setting
|
||||
|
||||
|
||||
def translate_bridge_options(iface_state):
|
||||
br_opts = {}
|
||||
bridge_state = iface_state.get('bridge', {}).get('options', {})
|
||||
@ -165,8 +171,16 @@ def _get_bridge_port_info(port_profile, devices_info):
|
||||
port_slave_names = [c.get_interface_name() for c in port_slave_profiles]
|
||||
|
||||
if port_slave_names:
|
||||
port_info['name'] = port_slave_names[0]
|
||||
port_info['type'] = OBPortType.SYSTEM
|
||||
iface_slave_name = port_slave_names[0]
|
||||
iface_device = device.get_device_by_name(iface_slave_name)
|
||||
|
||||
if is_ovs_interface_type_id(iface_device.props.device_type):
|
||||
port_type = OBPortType.INTERNAL
|
||||
else:
|
||||
port_type = OBPortType.SYSTEM
|
||||
|
||||
port_info['name'] = iface_slave_name
|
||||
port_info['type'] = port_type
|
||||
if vlan_mode:
|
||||
port_info['vlan-mode'] = vlan_mode
|
||||
port_info['access-tag'] = port_setting.props.tag
|
||||
|
@ -35,6 +35,7 @@ class Constants(object):
|
||||
LINUX_BRIDGE = 'linux-bridge'
|
||||
OVS_BRIDGE = 'ovs-bridge'
|
||||
OVS_PORT = 'ovs-port'
|
||||
OVS_INTERFACE = 'ovs-interface'
|
||||
VLAN = 'vlan'
|
||||
|
||||
VIRT_IFACE_TYPES = (
|
||||
@ -42,6 +43,7 @@ class Constants(object):
|
||||
LINUX_BRIDGE,
|
||||
OVS_BRIDGE,
|
||||
OVS_PORT,
|
||||
OVS_INTERFACE,
|
||||
VLAN
|
||||
)
|
||||
|
||||
|
@ -86,6 +86,23 @@ def test_bridge_with_system_port(eth1_up, bridge_default_config):
|
||||
assert not _get_bridge_current_state()
|
||||
|
||||
|
||||
def test_bridge_with_internal_interface(eth1_up, bridge_default_config):
|
||||
bridge_desired_state = bridge_default_config
|
||||
|
||||
ovs_port = {
|
||||
OB.PORT_NAME: 'ovs0',
|
||||
OB.PORT_TYPE: OBPortType.INTERNAL,
|
||||
}
|
||||
|
||||
bridge_desired_state[OB.CONFIG_SUBTREE][OB.PORT_SUBTREE].append(ovs_port)
|
||||
|
||||
with _bridge_interface(bridge_desired_state):
|
||||
bridge_current_state = _get_bridge_current_state()
|
||||
assert bridge_desired_state == bridge_current_state
|
||||
|
||||
assert not _get_bridge_current_state()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _bridge_interface(state):
|
||||
try:
|
||||
@ -124,7 +141,19 @@ def _attach_port_to_bridge(port_state):
|
||||
port_profile_name = nm.ovs.PORT_PROFILE_PREFIX + port_state[OB.PORT_NAME]
|
||||
|
||||
_create_proxy_port(port_profile_name, port_state)
|
||||
_connect_interface(port_profile_name, port_state)
|
||||
if port_state[OB.PORT_TYPE] == OBPortType.SYSTEM:
|
||||
_connect_interface(port_profile_name, port_state)
|
||||
elif port_state[OB.PORT_TYPE] == OBPortType.INTERNAL:
|
||||
iface_name = port_state[OB.PORT_NAME]
|
||||
_create_internal_interface(iface_name, master_name=port_profile_name)
|
||||
|
||||
|
||||
def _create_internal_interface(iface_name, master_name):
|
||||
iface_settings = _create_internal_iface_setting(iface_name,
|
||||
master_name)
|
||||
iface_con_profile = nm.connection.create_profile(iface_settings)
|
||||
nm.connection.add_profile(iface_con_profile, save_to_disk=False)
|
||||
nm.device.activate(connection_id=iface_name)
|
||||
|
||||
|
||||
def _connect_interface(port_profile_name, port_state):
|
||||
@ -173,6 +202,26 @@ def _create_port_setting(port_state, port_profile_name):
|
||||
return iface_con_setting, bridge_port_setting
|
||||
|
||||
|
||||
def _create_internal_iface_setting(iface_name, master_name):
|
||||
iface_con_setting = nm.connection.create_setting(
|
||||
con_name=iface_name,
|
||||
iface_name=iface_name,
|
||||
iface_type=nm.ovs.INTERNAL_INTERFACE_TYPE
|
||||
)
|
||||
nm.connection.set_master_setting(iface_con_setting,
|
||||
master_name,
|
||||
nm.ovs.PORT_TYPE)
|
||||
bridge_internal_iface_setting = nm.ovs.create_interface_setting()
|
||||
ipv4_setting = nm.ipv4.create_setting({}, None)
|
||||
ipv6_setting = nm.ipv6.create_setting({}, None)
|
||||
return (
|
||||
iface_con_setting,
|
||||
bridge_internal_iface_setting,
|
||||
ipv4_setting,
|
||||
ipv6_setting
|
||||
)
|
||||
|
||||
|
||||
def _delete_iface(devname):
|
||||
nmdev = nm.device.get_device_by_name(devname)
|
||||
with mainloop():
|
||||
|
Loading…
x
Reference in New Issue
Block a user