aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/os-net-config/samples/ivs.json37
-rw-r--r--etc/os-net-config/samples/ivs.yaml24
-rw-r--r--os_net_config/__init__.py13
-rw-r--r--os_net_config/impl_eni.py2
-rw-r--r--os_net_config/impl_ifcfg.py178
-rw-r--r--os_net_config/objects.py110
-rw-r--r--os_net_config/tests/test_impl_eni.py6
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py100
-rw-r--r--os_net_config/tests/test_objects.py55
-rw-r--r--os_net_config/utils.py8
-rw-r--r--tox.ini4
11 files changed, 502 insertions, 35 deletions
diff --git a/etc/os-net-config/samples/ivs.json b/etc/os-net-config/samples/ivs.json
new file mode 100644
index 0000000..746e1c0
--- /dev/null
+++ b/etc/os-net-config/samples/ivs.json
@@ -0,0 +1,37 @@
+{
+ "network_config": [
+ {
+ "type": "ivs_bridge",
+ "members": [
+ {
+ "type": "interface",
+ "name": "nic2",
+ },
+ {
+ "type": "interface",
+ "name": "nic3"
+ },
+ {
+ "type": "ivs_interface",
+ "name": "api",
+ "addresses": [
+ {
+ "ip_netmask": "172.16.2.7/24"
+ }
+ ],
+ "vlan_id": 201
+ },
+ {
+ "type": "ivs_interface",
+ "name": "storage",
+ "addresses": [
+ {
+ "ip_netmask": "172.16.1.6/24"
+ }
+ ],
+ "vlan_id": 202
+ }
+ ]
+ }
+ ]
+}
diff --git a/etc/os-net-config/samples/ivs.yaml b/etc/os-net-config/samples/ivs.yaml
new file mode 100644
index 0000000..9813316
--- /dev/null
+++ b/etc/os-net-config/samples/ivs.yaml
@@ -0,0 +1,24 @@
+network_config:
+ -
+ type: ivs_bridge
+ members:
+ -
+ type: interface
+ name: nic2
+ -
+ type: interface
+ name: nic3
+ -
+ type: ivs_interface
+ name: api
+ vlan_id: 201
+ addresses:
+ -
+ ip_netmask: 172.16.2.7/24
+ -
+ type: ivs_interface
+ name: storage
+ vlan_id: 202
+ addresses:
+ -
+ ip_netmask: 172.16.1.6/24
diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py
index 42131bb..f52eb59 100644
--- a/os_net_config/__init__.py
+++ b/os_net_config/__init__.py
@@ -48,6 +48,8 @@ class NetConfig(object):
self.add_interface(obj)
elif isinstance(obj, objects.Vlan):
self.add_vlan(obj)
+ elif isinstance(obj, objects.IvsInterface):
+ self.add_ivs_interface(obj)
elif isinstance(obj, objects.OvsBridge):
self.add_bridge(obj)
for member in obj.members:
@@ -56,6 +58,10 @@ class NetConfig(object):
self.add_linux_bridge(obj)
for member in obj.members:
self.add_object(member)
+ elif isinstance(obj, objects.IvsBridge):
+ self.add_ivs_bridge(obj)
+ for member in obj.members:
+ self.add_object(member)
elif isinstance(obj, objects.OvsBond):
self.add_bond(obj)
for member in obj.members:
@@ -93,6 +99,13 @@ class NetConfig(object):
"""
raise NotImplemented("add_linux_bridge is not implemented.")
+ def add_ivs_bridge(self, bridge):
+ """Add a IvsBridge object to the net config object.
+
+ :param bridge: The IvsBridge object to add.
+ """
+ raise NotImplemented("add_ivs_bridge is not implemented.")
+
def add_bond(self, bond):
"""Add an OvsBond object to the net config object.
diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py
index 68d91ef..ae60099 100644
--- a/os_net_config/impl_eni.py
+++ b/os_net_config/impl_eni.py
@@ -130,7 +130,7 @@ class ENINetConfig(os_net_config.NetConfig):
data += "auto %s\n" % interface.name
data += _iface
data += address_data
- if interface.mtu != 1500:
+ if interface.mtu:
data += " mtu %i\n" % interface.mtu
if interface.hwaddr:
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 70f5065..0fe6ae1 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -35,10 +35,18 @@ def bridge_config_path(name):
return ifcfg_config_path(name)
+def ivs_config_path():
+ return "/etc/sysconfig/ivs"
+
+
def route_config_path(name):
return "/etc/sysconfig/network-scripts/route-%s" % name
+def route6_config_path(name):
+ return "/etc/sysconfig/network-scripts/route6-%s" % name
+
+
def cleanup_pattern():
return "/etc/sysconfig/network-scripts/ifcfg-*"
@@ -49,7 +57,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
def __init__(self, noop=False, root_dir=''):
super(IfcfgNetConfig, self).__init__(noop, root_dir)
self.interface_data = {}
+ self.ivsinterface_data = {}
self.route_data = {}
+ self.route6_data = {}
self.bridge_data = {}
self.linuxbridge_data = {}
self.linuxbond_data = {}
@@ -84,8 +94,16 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "VLAN=yes\n"
if base_opt.device:
data += "PHYSDEV=%s\n" % base_opt.device
+ else:
+ if base_opt.linux_bond_name:
+ data += "PHYSDEV=%s\n" % base_opt.linux_bond_name
+ elif isinstance(base_opt, objects.IvsInterface):
+ data += "TYPE=IVSIntPort\n"
elif re.match('\w+\.\d+$', base_opt.name):
data += "VLAN=yes\n"
+ if base_opt.ivs_bridge_name:
+ data += "DEVICETYPE=ivs\n"
+ data += "IVS_BRIDGE=%s\n" % base_opt.ivs_bridge_name
if base_opt.ovs_port:
data += "DEVICETYPE=ovs\n"
if base_opt.bridge_name:
@@ -153,7 +171,8 @@ class IfcfgNetConfig(os_net_config.NetConfig):
members = [member.name for member in base_opt.members]
self.member_names[base_opt.name] = members
for member in members:
- self.bond_slaves[member] = base_opt.name
+ if isinstance(member, objects.Interface):
+ self.bond_slaves[member] = base_opt.name
if base_opt.bonding_options:
data += "BONDING_OPTS=\"%s\"\n" % base_opt.bonding_options
else:
@@ -164,11 +183,11 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "BOOTPROTO=dhcp\n"
elif not base_opt.addresses:
data += "BOOTPROTO=none\n"
- if base_opt.mtu != 1500:
+ if base_opt.mtu:
data += "MTU=%i\n" % base_opt.mtu
if base_opt.use_dhcpv6 or base_opt.v6_addresses():
data += "IPV6INIT=yes\n"
- if base_opt.mtu != 1500:
+ if base_opt.mtu:
data += "IPV6_MTU=%i\n" % base_opt.mtu
if base_opt.use_dhcpv6:
data += "DHCPV6C=yes\n"
@@ -211,16 +230,31 @@ class IfcfgNetConfig(os_net_config.NetConfig):
logger.info('adding custom route for interface: %s' % interface_name)
data = ""
first_line = ""
+ data6 = ""
+ first_line6 = ""
for route in routes:
- if route.default:
- first_line = "default via %s dev %s\n" % (route.next_hop,
- interface_name)
+ if ":" not in route.next_hop:
+ # Route is an IPv4 route
+ if route.default:
+ first_line = "default via %s dev %s\n" % (route.next_hop,
+ interface_name)
+ else:
+ data += "%s via %s dev %s\n" % (route.ip_netmask,
+ route.next_hop,
+ interface_name)
else:
- data += "%s via %s dev %s\n" % (route.ip_netmask,
- route.next_hop,
- interface_name)
+ # Route is an IPv6 route
+ if route.default:
+ first_line6 = "default via %s dev %s\n" % (route.next_hop,
+ interface_name)
+ else:
+ data6 += "%s via %s dev %s\n" % (route.ip_netmask,
+ route.next_hop,
+ interface_name)
self.route_data[interface_name] = first_line + data
+ self.route6_data[interface_name] = first_line6 + data6
logger.debug('route data: %s' % self.route_data[interface_name])
+ logger.debug('ipv6 route data: %s' % self.route6_data[interface_name])
def add_interface(self, interface):
"""Add an Interface object to the net config object.
@@ -251,6 +285,18 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if vlan.routes:
self._add_routes(vlan.name, vlan.routes)
+ def add_ivs_interface(self, ivs_interface):
+ """Add a ivs_interface object to the net config object.
+
+ :param ivs_interface: The ivs_interface object to add.
+ """
+ logger.info('adding ivs_interface: %s' % ivs_interface.name)
+ data = self._add_common(ivs_interface)
+ logger.debug('ivs_interface data: %s' % data)
+ self.ivsinterface_data[ivs_interface.name] = data
+ if ivs_interface.routes:
+ self._add_routes(ivs_interface.name, ivs_interface.routes)
+
def add_bridge(self, bridge):
"""Add an OvsBridge object to the net config object.
@@ -275,6 +321,18 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if bridge.routes:
self._add_routes(bridge.name, bridge.routes)
+ def add_ivs_bridge(self, bridge):
+ """Add a IvsBridge object to the net config object.
+
+ IVS can only support one virtual switch per node,
+ using "ivs" as its name. As long as the ivs service
+ is running, the ivs virtual switch will be there.
+ It is impossible to add multiple ivs virtual switches
+ per node.
+ :param bridge: The IvsBridge object to add.
+ """
+ pass
+
def add_bond(self, bond):
"""Add an OvsBond object to the net config object.
@@ -300,6 +358,26 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if bond.routes:
self._add_routes(bond.name, bond.routes)
+ def generate_ivs_config(self, ivs_uplinks, ivs_interfaces):
+ """Generate configuration content for ivs."""
+
+ intfs = []
+ for intf in ivs_uplinks:
+ intfs.append(' -u ')
+ intfs.append(intf)
+ uplink_str = ''.join(intfs)
+
+ intfs = []
+ for intf in ivs_interfaces:
+ intfs.append(' --internal-port=')
+ intfs.append(intf)
+ intf_str = ''.join(intfs)
+
+ data = ("DAEMON_ARGS=\"--hitless --certificate /etc/ivs "
+ "--inband-vlan 4092%s%s\""
+ % (uplink_str, intf_str))
+ return data
+
def apply(self, cleanup=False, activate=True):
"""Apply the network configuration.
@@ -320,62 +398,106 @@ class IfcfgNetConfig(os_net_config.NetConfig):
restart_bridges = []
update_files = {}
all_file_names = []
+ ivs_uplinks = [] # ivs physical uplinks
+ ivs_interfaces = [] # ivs internal ports
for interface_name, iface_data in self.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)
+ 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)):
+ 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 interface: %s' %
interface_name)
+ for interface_name, iface_data in self.ivsinterface_data.iteritems():
+ route_data = self.route_data.get(interface_name, '')
+ interface_path = self.root_dir + ifcfg_config_path(interface_name)
+ route_path = self.root_dir + route_config_path(interface_name)
+ all_file_names.append(interface_path)
+ all_file_names.append(route_path)
+ ivs_interfaces.append(interface_name)
+ if (utils.diff(interface_path, iface_data) or
+ utils.diff(route_path, route_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
+ logger.info('No changes required for ivs interface: %s' %
+ interface_name)
+
for bridge_name, bridge_data in self.bridge_data.iteritems():
route_data = self.route_data.get(bridge_name, '')
+ route6_data = self.route6_data.get(bridge_name, '')
bridge_path = self.root_dir + bridge_config_path(bridge_name)
- bridge_route_path = self.root_dir + route_config_path(bridge_name)
+ br_route_path = self.root_dir + route_config_path(bridge_name)
+ br_route6_path = self.root_dir + route6_config_path(bridge_name)
all_file_names.append(bridge_path)
- all_file_names.append(bridge_route_path)
+ all_file_names.append(br_route_path)
+ all_file_names.append(br_route6_path)
if (utils.diff(bridge_path, bridge_data) or
- utils.diff(bridge_route_path, route_data)):
+ utils.diff(br_route_path, route_data) or
+ utils.diff(br_route6_path, route6_data)):
restart_bridges.append(bridge_name)
restart_interfaces.extend(self.child_members(bridge_name))
update_files[bridge_path] = bridge_data
- update_files[bridge_route_path] = route_data
+ update_files[br_route_path] = route_data
+ update_files[br_route6_path] = route6_data
+ else:
logger.info('No changes required for bridge: %s' % bridge_name)
for bridge_name, bridge_data in self.linuxbridge_data.iteritems():
route_data = self.route_data.get(bridge_name, '')
+ route6_data = self.route6_data.get(bridge_name, '')
bridge_path = self.root_dir + bridge_config_path(bridge_name)
- bridge_route_path = self.root_dir + route_config_path(bridge_name)
+ br_route_path = self.root_dir + route_config_path(bridge_name)
+ br_route6_path = self.root_dir + route6_config_path(bridge_name)
all_file_names.append(bridge_path)
- all_file_names.append(bridge_route_path)
+ all_file_names.append(br_route_path)
+ all_file_names.append(br_route6_path)
if (utils.diff(bridge_path, bridge_data) or
- utils.diff(bridge_route_path, route_data)):
+ utils.diff(br_route_path, route_data) or
+ utils.diff(br_route6_path, route6_data)):
restart_bridges.append(bridge_name)
restart_interfaces.extend(self.child_members(bridge_name))
update_files[bridge_path] = bridge_data
- update_files[bridge_route_path] = route_data
+ update_files[br_route_path] = route_data
+ update_files[br_route6_path] = route6_data
+ else:
logger.info('No changes required for bridge: %s' % bridge_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, '')
bond_path = self.root_dir + bridge_config_path(bond_name)
bond_route_path = self.root_dir + route_config_path(bond_name)
+ bond_route6_path = self.root_dir + route6_config_path(bond_name)
all_file_names.append(bond_path)
all_file_names.append(bond_route_path)
+ all_file_names.append(bond_route6_path)
if (utils.diff(bond_path, bond_data) or
- utils.diff(bond_route_path, route_data)):
+ utils.diff(bond_route_path, route_data) or
+ utils.diff(bond_route6_path, route6_data)):
restart_interfaces.append(bond_name)
restart_interfaces.extend(self.child_members(bond_name))
update_files[bond_path] = bond_data
update_files[bond_route_path] = route_data
+ update_files[bond_route6_path] = route6_data
+ else:
logger.info('No changes required for linux bond: %s' %
bond_name)
@@ -402,6 +524,11 @@ class IfcfgNetConfig(os_net_config.NetConfig):
for location, data in update_files.iteritems():
self.write_config(location, data)
+ if ivs_uplinks or ivs_interfaces:
+ location = ivs_config_path()
+ data = self.generate_ivs_config(ivs_uplinks, ivs_interfaces)
+ self.write_config(location, data)
+
if activate:
for bridge in restart_bridges:
self.ifup(bridge, iftype='bridge')
@@ -413,4 +540,17 @@ class IfcfgNetConfig(os_net_config.NetConfig):
self.ovs_appctl('bond/set-active-slave', bond,
self.bond_primary_ifaces[bond])
+ if ivs_uplinks or ivs_interfaces:
+ logger.info("Attach to ivs with "
+ "uplinks: %s, "
+ "interfaces: %s" %
+ (ivs_uplinks, ivs_interfaces))
+ for ivs_uplink in ivs_uplinks:
+ self.ifup(ivs_uplink)
+ for ivs_interface in ivs_interfaces:
+ self.ifup(ivs_interface)
+ msg = "Restart ivs"
+ self.execute(msg, '/usr/bin/systemctl',
+ 'restart', 'ivs')
+
return update_files
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index dd8489e..4f3e0d5 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -44,6 +44,10 @@ def object_from_json(json):
return LinuxBond.from_json(json)
elif obj_type == "linux_bridge":
return LinuxBridge.from_json(json)
+ elif obj_type == "ivs_bridge":
+ return IvsBridge.from_json(json)
+ elif obj_type == "ivs_interface":
+ return IvsInterface.from_json(json)
def _get_required_field(json, name, object_name):
@@ -134,7 +138,7 @@ class _BaseOpts(object):
"""Base abstraction for logical port options."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, primary=False, nic_mapping=None,
+ routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
dns_servers=None):
addresses = addresses or []
@@ -166,6 +170,8 @@ class _BaseOpts(object):
self.dns_servers = dns_servers
self.bridge_name = None # internal
self.linux_bridge_name = None # internal
+ self.ivs_bridge_name = None # internal
+ self.linux_bond_name = None # internal
self.ovs_port = False # internal
self.primary_interface_name = None # internal
@@ -192,7 +198,7 @@ class _BaseOpts(object):
False)))
defroute = strutils.bool_from_string(str(json.get('defroute',
True)))
- mtu = json.get('mtu', 1500)
+ mtu = json.get('mtu', None)
dhclient_args = json.get('dhclient_args')
dns_servers = json.get('dns_servers')
primary = strutils.bool_from_string(str(json.get('primary', False)))
@@ -236,7 +242,7 @@ class Interface(_BaseOpts):
"""Base class for network interfaces."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, primary=False, nic_mapping=None,
+ routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
dns_servers=None):
addresses = addresses or []
@@ -262,7 +268,7 @@ class Vlan(_BaseOpts):
"""
def __init__(self, device, vlan_id, use_dhcp=False, use_dhcpv6=False,
- addresses=None, routes=None, mtu=1500, primary=False,
+ addresses=None, routes=None, mtu=None, primary=False,
nic_mapping=None, persist_mapping=False, defroute=True,
dhclient_args=None, dns_servers=None):
addresses = addresses or []
@@ -290,11 +296,37 @@ class Vlan(_BaseOpts):
return Vlan(device, vlan_id, *opts)
+class IvsInterface(_BaseOpts):
+ """Base class for ivs interfaces."""
+
+ def __init__(self, vlan_id, name='ivs', use_dhcp=False, use_dhcpv6=False,
+ addresses=None, routes=None, mtu=1500, primary=False,
+ nic_mapping=None, persist_mapping=False, defroute=True,
+ dhclient_args=None, dns_servers=None):
+ addresses = addresses or []
+ routes = routes or []
+ dns_servers = dns_servers or []
+ name_vlan = '%s%i' % (name, vlan_id)
+ super(IvsInterface, self).__init__(name_vlan, use_dhcp, use_dhcpv6,
+ addresses, routes, mtu, primary,
+ nic_mapping, persist_mapping,
+ defroute, dhclient_args,
+ dns_servers)
+ self.vlan_id = int(vlan_id)
+
+ @staticmethod
+ def from_json(json):
+ name = json.get('name')
+ vlan_id = _get_required_field(json, 'vlan_id', 'IvsInterface')
+ opts = _BaseOpts.base_opts_from_json(json)
+ return IvsInterface(vlan_id, name, *opts)
+
+
class OvsBridge(_BaseOpts):
"""Base class for OVS bridges."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, members=None, ovs_options=None,
+ routes=None, mtu=None, members=None, ovs_options=None,
ovs_extra=None, nic_mapping=None, persist_mapping=False,
defroute=True, dhclient_args=None, dns_servers=None):
addresses = addresses or []
@@ -354,7 +386,7 @@ class LinuxBridge(_BaseOpts):
"""Base class for Linux bridges."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, members=None, nic_mapping=None,
+ routes=None, mtu=None, members=None, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
dns_servers=None):
addresses = addresses or []
@@ -405,11 +437,72 @@ class LinuxBridge(_BaseOpts):
dns_servers=dns_servers)
+class IvsBridge(_BaseOpts):
+ """Base class for IVS bridges.
+
+ Indigo Virtual Switch (IVS) is a virtual switch for Linux.
+ It is compatible with the KVM hypervisor and leveraging the
+ Open vSwitch kernel module for packet forwarding. There are
+ three major differences between IVS and OVS:
+ 1. Each node can have at most one ivs, no name required.
+ 2. Bond is not allowed to attach to an ivs. It is the SDN
+ controller's job to dynamically form bonds on ivs.
+ 3. IP address can only be statically assigned.
+ """
+
+ def __init__(self, name='ivs', use_dhcp=False, use_dhcpv6=False,
+ addresses=None, routes=None, mtu=1500, members=None,
+ nic_mapping=None, persist_mapping=False, defroute=True,
+ dhclient_args=None, dns_servers=None):
+ addresses = addresses or []
+ routes = routes or []
+ members = members or []
+ dns_servers = dns_servers or []
+ super(IvsBridge, self).__init__(name, use_dhcp, use_dhcpv6,
+ addresses, routes, mtu, False,
+ nic_mapping, persist_mapping,
+ defroute, dhclient_args, dns_servers)
+ self.members = members
+ for member in self.members:
+ if isinstance(member, OvsBond) or isinstance(member, LinuxBond):
+ msg = 'IVS does not support bond interfaces.'
+ raise InvalidConfigException(msg)
+ member.ivs_bridge_name = name
+ member.ovs_port = False
+ self.primary_interface_name = None # ivs doesn't use primary intf
+
+ @staticmethod
+ def from_json(json):
+ name = 'ivs'
+ (use_dhcp, use_dhcpv6, addresses, routes, mtu, nic_mapping,
+ persist_mapping, defroute, dhclient_args,
+ dns_servers) = _BaseOpts.base_opts_from_json(
+ json, include_primary=False)
+ members = []
+
+ # members
+ members_json = json.get('members')
+ if members_json:
+ if isinstance(members_json, list):
+ for member in members_json:
+ members.append(object_from_json(member))
+ else:
+ msg = 'Members must be a list.'
+ raise InvalidConfigException(msg)
+
+ return IvsBridge(name, use_dhcp=use_dhcp, use_dhcpv6=use_dhcpv6,
+ addresses=addresses, routes=routes, mtu=mtu,
+ members=members, nic_mapping=nic_mapping,
+ persist_mapping=persist_mapping, defroute=defroute,
+ dhclient_args=dhclient_args,
+ dns_servers=dns_servers)
+
+
class LinuxBond(_BaseOpts):
"""Base class for Linux bonds."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, primary=False, members=None,
+ routes=None, mtu=None, primary=False, members=None,
bonding_options=None, nic_mapping=None, persist_mapping=False,
defroute=True, dhclient_args=None, dns_servers=None):
addresses = addresses or []
@@ -423,6 +516,7 @@ class LinuxBond(_BaseOpts):
self.members = members
self.bonding_options = bonding_options
for member in self.members:
+ member.linux_bond_name = name
if member.primary:
if self.primary_interface_name:
msg = 'Only one primary interface allowed per bond.'
@@ -464,7 +558,7 @@ class OvsBond(_BaseOpts):
"""Base class for OVS bonds."""
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
- routes=None, mtu=1500, primary=False, members=None,
+ routes=None, mtu=None, primary=False, members=None,
ovs_options=None, ovs_extra=None, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
dns_servers=None):
diff --git a/os_net_config/tests/test_impl_eni.py b/os_net_config/tests/test_impl_eni.py
index e0e009d..7f909ff 100644
--- a/os_net_config/tests/test_impl_eni.py
+++ b/os_net_config/tests/test_impl_eni.py
@@ -221,6 +221,12 @@ class TestENINetConfig(base.TestCase):
self.provider.add_vlan(vlan)
self.assertEqual(_VLAN_NO_IP, self.get_interface_config('vlan5'))
+ def test_vlan_mtu_1500(self):
+ vlan = objects.Vlan('eth0', 5, mtu=1500)
+ self.provider.add_vlan(vlan)
+ expected = _VLAN_NO_IP + ' mtu 1500\n'
+ self.assertEqual(expected, self.get_interface_config('vlan5'))
+
def test_vlan_ovs_bridge_int_port(self):
vlan = objects.Vlan('eth0', 5)
bridge = objects.OvsBridge('br0', use_dhcp=True,
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index c914ea2..3500e4c 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -39,6 +39,14 @@ IPADDR=192.168.1.2
NETMASK=255.255.255.0
"""
+_V4_V6_IFCFG = _BASE_IFCFG + """IPV6INIT=yes
+BOOTPROTO=static
+IPADDR=192.168.1.2
+NETMASK=255.255.255.0
+IPV6_AUTOCONF=no
+IPV6ADDR=2001:abc:a::/64
+"""
+
_IFCFG_VLAN = """# This file is autogenerated by os-net-config
DEVICE=em1.120
ONBOOT=yes
@@ -75,6 +83,11 @@ _ROUTES = """default via 192.168.1.1 dev em1
172.19.0.0/24 via 192.168.1.1 dev em1
"""
+_ROUTES_V6 = """default via 2001:db8::1 dev em1
+2001:db8:dead:beef:cafe::/56 via fd00:fd00:2000::1 dev em1
+"""
+
+
_OVS_INTERFACE = _BASE_IFCFG + """DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=br-ctlplane
@@ -165,6 +178,11 @@ OVS_OPTIONS="tag=5"
BOOTPROTO=none
"""
+_VLAN_LINUX_BRIDGE = _BASE_VLAN_OVS + """VLAN=yes
+BRIDGE=br-ctlplane
+BOOTPROTO=none
+"""
+
_OVS_BOND_DHCP = """# This file is autogenerated by os-net-config
DEVICE=bond0
@@ -187,6 +205,34 @@ BOOTPROTO=dhcp
"""
+_IVS_UPLINK = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+DEVICETYPE=ivs
+IVS_BRIDGE=ivs
+BOOTPROTO=none
+"""
+
+_IVS_INTERFACE = """# This file is autogenerated by os-net-config
+DEVICE=storage5
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+TYPE=IVSIntPort
+DEVICETYPE=ivs
+IVS_BRIDGE=ivs
+MTU=1500
+BOOTPROTO=static
+IPADDR=172.16.2.7
+NETMASK=255.255.255.0
+"""
+
+_IVS_CONFIG = ('DAEMON_ARGS=\"--hitless --certificate /etc/ivs '
+ '--inband-vlan 4092 -u em1 --internal-port=storage5\"')
+
+
class TestIfcfgNetConfig(base.TestCase):
def setUp(self):
@@ -203,6 +249,9 @@ class TestIfcfgNetConfig(base.TestCase):
def get_route_config(self, name='em1'):
return self.provider.route_data.get(name, '')
+ def get_route6_config(self, name='em1'):
+ return self.provider.route6_data.get(name, '')
+
def test_add_base_interface(self):
interface = objects.Interface('em1')
self.provider.add_interface(interface)
@@ -276,6 +325,20 @@ class TestIfcfgNetConfig(base.TestCase):
self.assertEqual(_V4_IFCFG, self.get_interface_config())
self.assertEqual(_ROUTES, self.get_route_config())
+ def test_network_with_ipv6_routes(self):
+ route1 = objects.Route('192.168.1.1', default=True)
+ route2 = objects.Route('192.168.1.1', '172.19.0.0/24')
+ route3 = objects.Route('2001:db8::1', default=True)
+ route4 = objects.Route('fd00:fd00:2000::1',
+ '2001:db8:dead:beef:cafe::/56')
+ v4_addr = objects.Address('192.168.1.2/24')
+ v6_addr = objects.Address('2001:abc:a::/64')
+ interface = objects.Interface('em1', addresses=[v4_addr, v6_addr],
+ routes=[route1, route2, route3, route4])
+ self.provider.add_interface(interface)
+ self.assertEqual(_V4_V6_IFCFG, self.get_interface_config())
+ self.assertEqual(_ROUTES_V6, self.get_route6_config())
+
def test_network_ovs_bridge_with_dhcp(self):
interface = objects.Interface('em1')
bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True,
@@ -348,6 +411,22 @@ class TestIfcfgNetConfig(base.TestCase):
self.assertEqual(_OVS_BRIDGE_DHCP_OVS_EXTRA,
self.provider.bridge_data['br-ctlplane'])
+ def test_network_ivs_with_uplink_and_interface(self):
+ interface = objects.Interface('em1')
+ v4_addr = objects.Address('172.16.2.7/24')
+ ivs_interface = objects.IvsInterface(vlan_id=5,
+ name='storage',
+ addresses=[v4_addr])
+ bridge = objects.IvsBridge(members=[interface, ivs_interface])
+ self.provider.add_interface(interface)
+ self.provider.add_ivs_interface(ivs_interface)
+ self.provider.add_bridge(bridge)
+ self.assertEqual(_IVS_UPLINK, self.get_interface_config())
+ self.assertEqual(_IVS_INTERFACE,
+ self.provider.ivsinterface_data[ivs_interface.name])
+ data = self.provider.generate_ivs_config(['em1'], ['storage5'])
+ self.assertEqual(_IVS_CONFIG, data)
+
def test_add_vlan(self):
vlan = objects.Vlan('em1', 5)
self.provider.add_vlan(vlan)
@@ -359,6 +438,12 @@ class TestIfcfgNetConfig(base.TestCase):
self.provider.add_vlan(vlan)
self.assertEqual(_VLAN_OVS, self.get_interface_config('vlan5'))
+ def test_add_vlan_mtu_1500(self):
+ vlan = objects.Vlan('em1', 5, mtu=1500)
+ self.provider.add_vlan(vlan)
+ expected = _VLAN_NO_IP + 'MTU=1500\n'
+ self.assertEqual(expected, self.get_interface_config('vlan5'))
+
def test_add_ovs_bridge_with_vlan(self):
vlan = objects.Vlan('em1', 5)
bridge = objects.OvsBridge('br-ctlplane', use_dhcp=True,
@@ -367,6 +452,15 @@ class TestIfcfgNetConfig(base.TestCase):
self.provider.add_bridge(bridge)
self.assertEqual(_VLAN_OVS_BRIDGE, self.get_interface_config('vlan5'))
+ def test_add_linux_bridge_with_vlan(self):
+ vlan = objects.Vlan(None, 5)
+ bridge = objects.LinuxBridge('br-ctlplane', use_dhcp=True,
+ members=[vlan])
+ self.provider.add_vlan(vlan)
+ self.provider.add_bridge(bridge)
+ self.assertEqual(_VLAN_LINUX_BRIDGE,
+ self.get_interface_config('vlan5'))
+
def test_ovs_bond(self):
interface1 = objects.Interface('em1')
interface2 = objects.Interface('em2')
@@ -468,6 +562,7 @@ class TestIfcfgNetConfigApply(base.TestCase):
super(TestIfcfgNetConfigApply, self).setUp()
self.temp_ifcfg_file = tempfile.NamedTemporaryFile()
self.temp_route_file = tempfile.NamedTemporaryFile()
+ self.temp_route6_file = tempfile.NamedTemporaryFile()
self.temp_bridge_file = tempfile.NamedTemporaryFile()
self.temp_cleanup_file = tempfile.NamedTemporaryFile(delete=False)
self.ifup_interface_names = []
@@ -481,6 +576,10 @@ class TestIfcfgNetConfigApply(base.TestCase):
return self.temp_route_file.name
self.stubs.Set(impl_ifcfg, 'route_config_path', test_routes_path)
+ def test_routes6_path(name):
+ return self.temp_route6_file.name
+ self.stubs.Set(impl_ifcfg, 'route6_config_path', test_routes6_path)
+
def test_bridge_path(name):
return self.temp_bridge_file.name
self.stubs.Set(impl_ifcfg, 'bridge_config_path', test_bridge_path)
@@ -502,6 +601,7 @@ class TestIfcfgNetConfigApply(base.TestCase):
def tearDown(self):
self.temp_ifcfg_file.close()
self.temp_route_file.close()
+ self.temp_route6_file.close()
self.temp_bridge_file.close()
if os.path.exists(self.temp_cleanup_file.name):
self.temp_cleanup_file.close()
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index f01612d..b49c393 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -343,6 +343,61 @@ class TestLinuxBridge(base.TestCase):
self.assertEqual("br-foo", interface2.linux_bridge_name)
+class TestIvsBridge(base.TestCase):
+
+ def test_interface_from_json(self):
+ data = """{
+"type": "ivs_bridge",
+"members": [{
+ "type": "interface",
+ "name": "nic2"
+}]
+}
+"""
+ bridge = objects.object_from_json(json.loads(data))
+ self.assertEqual("ivs", bridge.name)
+ interface1 = bridge.members[0]
+ self.assertEqual("nic2", interface1.name)
+ self.assertEqual(False, interface1.ovs_port)
+ self.assertEqual("ivs", interface1.ivs_bridge_name)
+
+ def test_ivs_interface_from_json(self):
+ data = """{
+"type": "ivs_bridge",
+"members": [{
+ "type": "ivs_interface",
+ "name": "storage",
+ "vlan_id": 202
+}]
+}
+"""
+ bridge = objects.object_from_json(json.loads(data))
+ self.assertEqual("ivs", bridge.name)
+ interface1 = bridge.members[0]
+ self.assertEqual("storage202", interface1.name)
+ self.assertEqual(False, interface1.ovs_port)
+ self.assertEqual("ivs", interface1.ivs_bridge_name)
+
+ def test_bond_interface_from_json(self):
+ data = """{
+"type": "ivs_bridge",
+"members": [{
+ "type": "linux_bond",
+ "name": "bond1",
+ "members": [
+ {"type": "interface", "name": "nic2"},
+ {"type": "interface", "name": "nic3"}
+ ]
+}]
+}
+"""
+ err = self.assertRaises(objects.InvalidConfigException,
+ objects.IvsBridge.from_json,
+ json.loads(data))
+ expected = 'IVS does not support bond interfaces.'
+ self.assertIn(expected, err)
+
+
class TestBond(base.TestCase):
def test_from_json_dhcp(self):
diff --git a/os_net_config/utils.py b/os_net_config/utils.py
index ab7f3b3..4109081 100644
--- a/os_net_config/utils.py
+++ b/os_net_config/utils.py
@@ -55,10 +55,8 @@ def _is_active_nic(interface_name):
if interface_name == 'lo':
return False
- addr_assign_type = None
- with open(_SYS_CLASS_NET + '/%s/addr_assign_type' % interface_name,
- 'r') as f:
- addr_assign_type = int(f.read().rstrip())
+ device_dir = _SYS_CLASS_NET + '/%s/device' % interface_name
+ has_device_dir = os.path.isdir(device_dir)
carrier = None
with open(_SYS_CLASS_NET + '/%s/carrier' % interface_name, 'r') as f:
@@ -68,7 +66,7 @@ def _is_active_nic(interface_name):
with open(_SYS_CLASS_NET + '/%s/address' % interface_name, 'r') as f:
address = f.read().rstrip()
- if addr_assign_type == 0 and carrier == 1 and address:
+ if has_device_dir and carrier == 1 and address:
return True
else:
return False
diff --git a/tox.ini b/tox.ini
index 53aa727..5b6ac5d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
[tox]
minversion = 1.6
-envlist = py26,py27,py33,pypy,pep8
+envlist = py27,py33,pypy,pep8
skipsdist = True
[testenv]
@@ -31,4 +31,4 @@ commands = python setup.py build_sphinx
show-source = True
ignore = E123,E125,H803
builtins = _
-exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build \ No newline at end of file
+exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build