aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/impl_ifcfg.py
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config/impl_ifcfg.py')
-rw-r--r--os_net_config/impl_ifcfg.py212
1 files changed, 209 insertions, 3 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index fbd1c3a..d49b57b 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -39,6 +39,10 @@ def ivs_config_path():
return "/etc/sysconfig/ivs"
+def nfvswitch_config_path():
+ return "/etc/sysconfig/nfvswitch"
+
+
def route_config_path(name):
return "/etc/sysconfig/network-scripts/route-%s" % name
@@ -58,12 +62,16 @@ class IfcfgNetConfig(os_net_config.NetConfig):
super(IfcfgNetConfig, self).__init__(noop, root_dir)
self.interface_data = {}
self.ivsinterface_data = {}
+ self.nfvswitch_intiface_data = {}
+ self.nfvswitch_cpus = None
self.vlan_data = {}
self.route_data = {}
self.route6_data = {}
self.bridge_data = {}
self.linuxbridge_data = {}
self.linuxbond_data = {}
+ self.ib_interface_data = {}
+ self.linuxteam_data = {}
self.member_names = {}
self.renamed_interfaces = {}
self.bond_primary_ifaces = {}
@@ -101,16 +109,28 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "PHYSDEV=%s\n" % base_opt.linux_bond_name
elif isinstance(base_opt, objects.IvsInterface):
data += "TYPE=IVSIntPort\n"
+ elif isinstance(base_opt, objects.NfvswitchInternal):
+ data += "TYPE=NFVSWITCHIntPort\n"
+ elif isinstance(base_opt, objects.IbInterface):
+ data += "TYPE=Infiniband\n"
elif re.match('\w+\.\d+$', base_opt.name):
data += "VLAN=yes\n"
if base_opt.linux_bond_name:
data += "MASTER=%s\n" % base_opt.linux_bond_name
data += "SLAVE=yes\n"
+ if base_opt.linux_team_name:
+ data += "TEAM_MASTER=%s\n" % base_opt.linux_team_name
+ if base_opt.primary:
+ data += "TEAM_PORT_CONFIG='{\"prio\": 100}'\n"
if base_opt.ivs_bridge_name:
data += "DEVICETYPE=ivs\n"
data += "IVS_BRIDGE=%s\n" % base_opt.ivs_bridge_name
+ if base_opt.nfvswitch_bridge_name:
+ data += "DEVICETYPE=nfvswitch\n"
+ data += "NFVSWITCH_BRIDGE=%s\n" % base_opt.nfvswitch_bridge_name
if base_opt.ovs_port:
- data += "DEVICETYPE=ovs\n"
+ if not isinstance(base_opt, objects.LinuxTeam):
+ data += "DEVICETYPE=ovs\n"
if base_opt.bridge_name:
if isinstance(base_opt, objects.Vlan):
data += "TYPE=OVSIntPort\n"
@@ -177,6 +197,19 @@ class IfcfgNetConfig(os_net_config.NetConfig):
self.member_names[base_opt.name] = members
if base_opt.bonding_options:
data += "BONDING_OPTS=\"%s\"\n" % base_opt.bonding_options
+ elif isinstance(base_opt, objects.LinuxTeam):
+ if base_opt.primary_interface_name:
+ primary_name = base_opt.primary_interface_name
+ primary_mac = utils.interface_mac(primary_name)
+ data += "MACADDR=\"%s\"\n" % primary_mac
+ if base_opt.use_dhcp:
+ data += "BOOTPROTO=dhcp\n"
+ if base_opt.members:
+ members = [member.name for member in base_opt.members]
+ self.member_names[base_opt.name] = members
+ data += "DEVICETYPE=Team\n"
+ if base_opt.bonding_options:
+ data += "TEAM_CONFIG='%s'\n" % base_opt.bonding_options
elif isinstance(base_opt, objects.OvsTunnel):
ovs_extra.extend(base_opt.ovs_extra)
data += "DEVICETYPE=ovs\n"
@@ -311,6 +344,19 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if ivs_interface.routes:
self._add_routes(ivs_interface.name, ivs_interface.routes)
+ def add_nfvswitch_internal(self, nfvswitch_internal):
+ """Add a nfvswitch_internal interface object to the net config object.
+
+ :param nfvswitch_internal: The nfvswitch_internal object to add.
+ """
+ iface_name = nfvswitch_internal.name
+ logger.info('adding nfvswitch_internal interface: %s' % iface_name)
+ data = self._add_common(nfvswitch_internal)
+ logger.debug('nfvswitch_internal interface data: %s' % data)
+ self.nfvswitch_intiface_data[iface_name] = data
+ if nfvswitch_internal.routes:
+ self._add_routes(iface_name, nfvswitch_internal.routes)
+
def add_bridge(self, bridge):
"""Add an OvsBridge object to the net config object.
@@ -347,6 +393,16 @@ class IfcfgNetConfig(os_net_config.NetConfig):
"""
pass
+ def add_nfvswitch_bridge(self, bridge):
+ """Add a NFVSwitchBridge object to the net config object.
+
+ NFVSwitch can only support one virtual switch per node,
+ using "nfvswitch" as its name. As long as the nfvswitch service
+ is running, the nfvswitch virtual switch will be available.
+ :param bridge: The NfvswitchBridge object to add.
+ """
+ self.nfvswitch_cpus = bridge.cpus
+
def add_bond(self, bond):
"""Add an OvsBond object to the net config object.
@@ -371,6 +427,18 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if bond.routes:
self._add_routes(bond.name, bond.routes)
+ def add_linux_team(self, team):
+ """Add a LinuxTeam object to the net config object.
+
+ :param team: The LinuxTeam object to add.
+ """
+ logger.info('adding linux team: %s' % team.name)
+ data = self._add_common(team)
+ logger.debug('team data: %s' % data)
+ self.linuxteam_data[team.name] = data
+ if team.routes:
+ self._add_routes(team.name, team.routes)
+
def add_ovs_tunnel(self, tunnel):
"""Add a OvsTunnel object to the net config object.
@@ -391,6 +459,23 @@ class IfcfgNetConfig(os_net_config.NetConfig):
logger.debug('ovs patch port data: %s' % data)
self.interface_data[ovs_patch_port.name] = data
+ def add_ib_interface(self, ib_interface):
+ """Add an InfiniBand interface object to the net config object.
+
+ :param ib_interface: The InfiniBand interface object to add.
+ """
+ logger.info('adding ib_interface: %s' % ib_interface.name)
+ data = self._add_common(ib_interface)
+ logger.debug('ib_interface data: %s' % data)
+ self.ib_interface_data[ib_interface.name] = data
+ if ib_interface.routes:
+ self._add_routes(ib_interface.name, ib_interface.routes)
+
+ if ib_interface.renamed:
+ logger.info("InfiniBand interface %s being renamed to %s"
+ % (ib_interface.hwname, ib_interface.name))
+ self.renamed_interfaces[ib_interface.hwname] = ib_interface.name
+
def generate_ivs_config(self, ivs_uplinks, ivs_interfaces):
"""Generate configuration content for ivs."""
@@ -411,6 +496,29 @@ class IfcfgNetConfig(os_net_config.NetConfig):
% (uplink_str, intf_str))
return data
+ def generate_nfvswitch_config(self, nfvswitch_ifaces,
+ nfvswitch_internal_ifaces):
+ """Generate configuration content for nfvswitch."""
+
+ cpu_str = ""
+ if self.nfvswitch_cpus:
+ cpu_str = " -c " + self.nfvswitch_cpus
+
+ ifaces = []
+ for iface in nfvswitch_ifaces:
+ ifaces.append(' -u ')
+ ifaces.append(iface)
+ iface_str = ''.join(ifaces)
+
+ ifaces = []
+ for iface in nfvswitch_internal_ifaces:
+ ifaces.append(' -m ')
+ ifaces.append(iface)
+ internal_str = ''.join(ifaces)
+
+ data = ("SETUP_ARGS=\"%s%s%s\"" % (cpu_str, iface_str, internal_str))
+ return data
+
def apply(self, cleanup=False, activate=True):
"""Apply the network configuration.
@@ -431,10 +539,13 @@ class IfcfgNetConfig(os_net_config.NetConfig):
restart_vlans = []
restart_bridges = []
restart_linux_bonds = []
+ restart_linux_teams = []
update_files = {}
all_file_names = []
ivs_uplinks = [] # ivs physical uplinks
ivs_interfaces = [] # ivs internal ports
+ nfvswitch_interfaces = [] # nfvswitch physical interfaces
+ nfvswitch_internal_ifaces = [] # nfvswitch internal/management ports
for interface_name, iface_data in self.interface_data.iteritems():
route_data = self.route_data.get(interface_name, '')
@@ -447,6 +558,8 @@ class IfcfgNetConfig(os_net_config.NetConfig):
all_file_names.append(route6_path)
if "IVS_BRIDGE" in iface_data:
ivs_uplinks.append(interface_name)
+ if "NFVSWITCH_BRIDGE" in iface_data:
+ nfvswitch_interfaces.append(interface_name)
all_file_names.append(route6_path)
if (utils.diff(interface_path, iface_data) or
utils.diff(route_path, route_data) or
@@ -481,6 +594,27 @@ class IfcfgNetConfig(os_net_config.NetConfig):
logger.info('No changes required for ivs interface: %s' %
interface_name)
+ for iface_name, iface_data in self.nfvswitch_intiface_data.iteritems():
+ route_data = self.route_data.get(iface_name, '')
+ route6_data = self.route6_data.get(iface_name, '')
+ iface_path = self.root_dir + ifcfg_config_path(iface_name)
+ route_path = self.root_dir + route_config_path(iface_name)
+ route6_path = self.root_dir + route6_config_path(iface_name)
+ all_file_names.append(iface_path)
+ all_file_names.append(route_path)
+ all_file_names.append(route6_path)
+ nfvswitch_internal_ifaces.append(iface_name)
+ if (utils.diff(iface_path, iface_data) or
+ utils.diff(route_path, route_data)):
+ restart_interfaces.append(iface_name)
+ restart_interfaces.extend(self.child_members(iface_name))
+ update_files[iface_path] = iface_data
+ update_files[route_path] = route_data
+ update_files[route6_path] = route6_data
+ else:
+ logger.info('No changes required for nfvswitch interface: %s' %
+ iface_name)
+
for vlan_name, vlan_data in self.vlan_data.iteritems():
route_data = self.route_data.get(vlan_name, '')
route6_data = self.route6_data.get(vlan_name, '')
@@ -541,6 +675,27 @@ class IfcfgNetConfig(os_net_config.NetConfig):
else:
logger.info('No changes required for bridge: %s' % bridge_name)
+ for team_name, team_data in self.linuxteam_data.iteritems():
+ route_data = self.route_data.get(team_name, '')
+ route6_data = self.route6_data.get(team_name, '')
+ team_path = self.root_dir + bridge_config_path(team_name)
+ team_route_path = self.root_dir + route_config_path(team_name)
+ team_route6_path = self.root_dir + route6_config_path(team_name)
+ all_file_names.append(team_path)
+ all_file_names.append(team_route_path)
+ all_file_names.append(team_route6_path)
+ if (utils.diff(team_path, team_data) or
+ utils.diff(team_route_path, route_data) or
+ utils.diff(team_route6_path, route6_data)):
+ restart_linux_teams.append(team_name)
+ restart_interfaces.extend(self.child_members(team_name))
+ update_files[team_path] = team_data
+ update_files[team_route_path] = route_data
+ update_files[team_route6_path] = route6_data
+ else:
+ logger.info('No changes required for linux team: %s' %
+ team_name)
+
for bond_name, bond_data in self.linuxbond_data.iteritems():
route_data = self.route_data.get(bond_name, '')
route6_data = self.route6_data.get(bond_name, '')
@@ -562,6 +717,32 @@ class IfcfgNetConfig(os_net_config.NetConfig):
logger.info('No changes required for linux bond: %s' %
bond_name)
+ # Infiniband interfaces are handled similarly to Ethernet interfaces
+ for interface_name, iface_data in self.ib_interface_data.iteritems():
+ route_data = self.route_data.get(interface_name, '')
+ route6_data = self.route6_data.get(interface_name, '')
+ interface_path = self.root_dir + ifcfg_config_path(interface_name)
+ route_path = self.root_dir + route_config_path(interface_name)
+ route6_path = self.root_dir + route6_config_path(interface_name)
+ all_file_names.append(interface_path)
+ all_file_names.append(route_path)
+ all_file_names.append(route6_path)
+ # TODO(dsneddon) determine if InfiniBand can be used with IVS
+ if "IVS_BRIDGE" in iface_data:
+ ivs_uplinks.append(interface_name)
+ all_file_names.append(route6_path)
+ if (utils.diff(interface_path, iface_data) or
+ utils.diff(route_path, route_data) or
+ utils.diff(route6_path, route6_data)):
+ restart_interfaces.append(interface_name)
+ restart_interfaces.extend(self.child_members(interface_name))
+ update_files[interface_path] = iface_data
+ update_files[route_path] = route_data
+ update_files[route6_path] = route6_data
+ else:
+ logger.info('No changes required for InfiniBand iface: %s' %
+ interface_name)
+
if cleanup:
for ifcfg_file in glob.iglob(cleanup_pattern()):
if ifcfg_file not in all_file_names:
@@ -582,6 +763,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
for linux_bond in restart_linux_bonds:
self.ifdown(linux_bond)
+ for linux_team in restart_linux_teams:
+ self.ifdown(linux_team)
+
for bridge in restart_bridges:
self.ifdown(bridge, iftype='bridge')
@@ -596,9 +780,15 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data = self.generate_ivs_config(ivs_uplinks, ivs_interfaces)
self.write_config(location, data)
+ if nfvswitch_interfaces or nfvswitch_internal_ifaces:
+ location = nfvswitch_config_path()
+ data = self.generate_nfvswitch_config(nfvswitch_interfaces,
+ nfvswitch_internal_ifaces)
+ self.write_config(location, data)
+
if activate:
- for linux_bond in restart_linux_bonds:
- self.ifup(linux_bond)
+ for linux_team in restart_linux_teams:
+ self.ifup(linux_team)
for bridge in restart_bridges:
self.ifup(bridge, iftype='bridge')
@@ -606,6 +796,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
for interface in restart_interfaces:
self.ifup(interface)
+ for linux_bond in restart_linux_bonds:
+ self.ifup(linux_bond)
+
for bond in self.bond_primary_ifaces:
self.ovs_appctl('bond/set-active-slave', bond,
self.bond_primary_ifaces[bond])
@@ -623,6 +816,19 @@ class IfcfgNetConfig(os_net_config.NetConfig):
self.execute(msg, '/usr/bin/systemctl',
'restart', 'ivs')
+ if nfvswitch_interfaces or nfvswitch_internal_ifaces:
+ logger.info("Attach to nfvswitch with "
+ "interfaces: %s, "
+ "internal interfaces: %s" %
+ (nfvswitch_interfaces, nfvswitch_internal_ifaces))
+ for nfvswitch_interface in nfvswitch_interfaces:
+ self.ifup(nfvswitch_interface)
+ for nfvswitch_internal in nfvswitch_internal_ifaces:
+ self.ifup(nfvswitch_internal)
+ msg = "Restart nfvswitch"
+ self.execute(msg, '/usr/bin/systemctl',
+ 'restart', 'nfvswitch')
+
for vlan in restart_vlans:
self.ifup(vlan)