diff options
author | 2015-09-02 17:07:48 -0700 | |
---|---|---|
committer | 2015-10-12 11:03:25 -0700 | |
commit | d01acefc15cebcfc5b7d808d3ed4f41cbaf8d74d (patch) | |
tree | 36611573e6a153f6562d9b28a706d22915547bea /os_net_config/objects.py | |
parent | 62bc734ad540cde0cf47b863db686b328d575d33 (diff) |
Add Linux Bridge capability to os-net-config ifcfg
This patch adds support for Linux Bridges to os-net-config. This is
done completely with ifcfg files, brctl is not used directly.
Hierarchy is preserved, so a Linux Bridge may have a Linux Bond
as a member, which in turn may have multiple interfaces as members.
This changeset has been updated to include a more specific example
for Linux bridge configuration (that doesn't combine bridging and
bonding).
This change depends on the change to add support for Linux Bonds.
Change-Id: I1ddacd514b02af30139a868071d82cde19b1f946
Diffstat (limited to 'os_net_config/objects.py')
-rw-r--r-- | os_net_config/objects.py | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py index 84ef3a1..ad42ce2 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -42,6 +42,8 @@ def object_from_json(json): return OvsBond.from_json(json) elif obj_type == "linux_bond": return LinuxBond.from_json(json) + elif obj_type == "linux_bridge": + return LinuxBridge.from_json(json) def _get_required_field(json, name, object_name): @@ -159,6 +161,7 @@ class _BaseOpts(object): self.dhclient_args = dhclient_args self.dns_servers = dns_servers self.bridge_name = None # internal + self.linux_bridge_name = None # internal self.ovs_port = False # internal self.primary_interface_name = None # internal @@ -332,6 +335,61 @@ class OvsBridge(_BaseOpts): dhclient_args=dhclient_args, dns_servers=dns_servers) +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, + 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(LinuxBridge, 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: + member.linux_bridge_name = name + member.ovs_port = False + if member.primary: + if self.primary_interface_name: + msg = 'Only one primary interface allowed per bridge.' + raise InvalidConfigException(msg) + if member.primary_interface_name: + self.primary_interface_name = member.primary_interface_name + else: + self.primary_interface_name = member.name + + @staticmethod + def from_json(json): + name = _get_required_field(json, 'name', 'LinuxBridge') + (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 LinuxBridge(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.""" @@ -420,8 +478,8 @@ class OvsBond(_BaseOpts): def from_json(json): name = _get_required_field(json, 'name', 'OvsBond') (use_dhcp, use_dhcpv6, addresses, routes, mtu, nic_mapping, - persist_mapping, defroute, - dhclient_args, dns_servers) = _BaseOpts.base_opts_from_json( + persist_mapping, defroute, dhclient_args, + dns_servers) = _BaseOpts.base_opts_from_json( json, include_primary=False) ovs_options = json.get('ovs_options') ovs_extra = json.get('ovs_extra', []) |