diff options
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) |