diff options
author | Dan Prince <dprince@redhat.com> | 2014-06-11 13:52:12 -0400 |
---|---|---|
committer | Dan Prince <dprince@redhat.com> | 2014-06-11 13:52:12 -0400 |
commit | 9110ad5fd4fa829a070d79da1f926758b15d5f10 (patch) | |
tree | 6ee2ed2e10d36a5e790ea26a0f999372322923fe /os_net_config/impl_ifcfg.py | |
parent | 86230e11d10a9a605f1eaaf9ab3619875224eb3d (diff) |
Add OvsBridge configuration support
Adds new object for OvsBridge. Also update the ifcfg network
config class to support adding bridges.
As part of the change both the bridge and interface classes
extend a _BaseOpts base class.
Diffstat (limited to 'os_net_config/impl_ifcfg.py')
-rw-r--r-- | os_net_config/impl_ifcfg.py | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index c4ea5dd..b4da7bc 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -23,6 +23,11 @@ def ifcfg_config_path(name): return "/etc/sysconfig/network-scripts/ifcfg-%s" % name +#NOTE(dprince): added here for testability +def bridge_config_path(name): + return ifcfg_config_path(name) + + def route_config_path(name): return "/etc/sysconfig/network-scripts/route-%s" % name @@ -33,21 +38,32 @@ class IfcfgNetConfig(os_net_config.NetConfig): def __init__(self): self.interfaces = {} self.routes = {} + self.bridges = {} - def addInterface(self, interface): + def _addCommon(self, interface): data = "DEVICE=%s\n" % interface.name data += "ONBOOT=yes\n" data += "HOTPLUG=no\n" - if interface.type == 'ovs': + if interface.type == 'ovs_port': data += "DEVICETYPE=ovs\n" - if interface.bridge: + if interface.bridge_name: data += "TYPE=OVSPort\n" - data += "OVS_BRIDGE=%s\n" % interface.bridge + data += "OVS_BRIDGE=%s\n" % interface.bridge_name + if interface.type == 'ovs_bridge': + data += "DEVICETYPE=ovs\n" + data += "TYPE=OVSBridge\n" + if interface.use_dhcp: + data += "OVSBOOTPROTO=dhcp\n" + if interface.members: + members = [member.name for member in interface.members] + data += ("OVSDHCPINTERFACES=%s\n" % " ".join(members)) + else: + if interface.use_dhcp: + data += "BOOTPROTO=dhcp\n" + elif not interface.addresses: data += "BOOTPROTO=none\n" if interface.mtu != 1500: data += "MTU=%i\n" % interface.mtu - if interface.use_dhcp: - data += "BOOTPROTO=dhcp\n" if interface.use_dhcpv6 or interface.v6_addresses(): data += "IPV6INIT=yes\n" if interface.mtu != 1500: @@ -69,11 +85,25 @@ class IfcfgNetConfig(os_net_config.NetConfig): data += "IPV6_AUTOCONF=no\n" data += "IPV6ADDR=%s\n" % first_v6.ip + return data + + def addInterface(self, interface): + data = self._addCommon(interface) + self.interfaces[interface.name] = data if interface.routes: - self.addRoutes(interface.name, interface.routes) + self._addRoutes(interface.name, interface.routes) - def addRoutes(self, interface_name, routes=[]): + def addBridge(self, bridge): + data = self._addCommon(bridge) + + self.bridges[bridge.name] = data + if bridge.routes: + self._addRoutes(bridge.name, bridge.routes) + if bridge.routes: + self._addRoutes(bridge.name, bridge.routes) + + def _addRoutes(self, interface_name, routes=[]): data = "" first_line = "" for route in routes: @@ -88,7 +118,9 @@ class IfcfgNetConfig(os_net_config.NetConfig): def apply(self): restart_interfaces = [] + restart_bridges = [] update_files = {} + for interface_name, iface_data in self.interfaces.iteritems(): route_data = self.routes.get(interface_name) if (utils.diff(ifcfg_config_path(interface_name), iface_data) or @@ -97,11 +129,27 @@ class IfcfgNetConfig(os_net_config.NetConfig): update_files[ifcfg_config_path(interface_name)] = iface_data update_files[route_config_path(interface_name)] = route_data + for bridge_name, bridge_data in self.bridges.iteritems(): + route_data = self.routes.get(bridge_name) + if (utils.diff(ifcfg_config_path(bridge_name), bridge_data) or + utils.diff(route_config_path(bridge_name), route_data)): + restart_bridges.append(bridge_name) + update_files[bridge_config_path(bridge_name)] = bridge_data + update_files[route_config_path(bridge_name)] = route_data + for interface in restart_interfaces: - processutils.execute('/sbin/ifdown', interface) + processutils.execute('/sbin/ifdown', interface, + check_exit_code=False) + + for bridge in restart_bridges: + processutils.execute('/sbin/ifdown', bridge, + check_exit_code=False) for location, data in update_files.iteritems(): utils.write_config(location, data) + for bridge in restart_bridges: + processutils.execute('/sbin/ifup', bridge) + for interface in restart_interfaces: processutils.execute('/sbin/ifup', interface) |