diff options
Diffstat (limited to 'os_net_config/impl_ifcfg.py')
-rw-r--r-- | os_net_config/impl_ifcfg.py | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py index b964819..0deb61e 100644 --- a/os_net_config/impl_ifcfg.py +++ b/os_net_config/impl_ifcfg.py @@ -50,7 +50,10 @@ class IfcfgNetConfig(os_net_config.NetConfig): self.interface_data = {} self.route_data = {} self.bridge_data = {} + self.linuxbridge_data = {} + self.linuxbond_data = {} self.member_names = {} + self.bond_slaves = {} self.renamed_interfaces = {} self.bond_primary_ifaces = {} logger.info('Ifcfg net config provider created.') @@ -62,7 +65,7 @@ class IfcfgNetConfig(os_net_config.NetConfig): children.add(member) children.update(self.child_members(member)) except KeyError: - children.add(name) + pass return children def _add_common(self, base_opt): @@ -90,6 +93,8 @@ class IfcfgNetConfig(os_net_config.NetConfig): else: data += "TYPE=OVSPort\n" data += "OVS_BRIDGE=%s\n" % base_opt.bridge_name + if base_opt.linux_bridge_name: + data += "BRIDGE=%s\n" % base_opt.linux_bridge_name if isinstance(base_opt, objects.OvsBridge): data += "DEVICETYPE=ovs\n" data += "TYPE=OVSBridge\n" @@ -122,7 +127,36 @@ class IfcfgNetConfig(os_net_config.NetConfig): if base_opt.ovs_options: data += "OVS_OPTIONS=\"%s\"\n" % base_opt.ovs_options ovs_extra.extend(base_opt.ovs_extra) + elif isinstance(base_opt, objects.LinuxBridge): + data += "TYPE=Bridge\n" + data += "DELAY=0\n" + 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 + 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 + elif isinstance(base_opt, objects.LinuxBond): + 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 + for member in members: + self.bond_slaves[member] = base_opt.name + if base_opt.bonding_options: + data += "BONDING_OPTS=\"%s\"\n" % base_opt.bonding_options else: + if base_opt.name in self.bond_slaves: + data += "MASTER=%s\n" % self.bond_slaves[base_opt.name] + data += "SLAVE=yes\n" if base_opt.use_dhcp: data += "BOOTPROTO=dhcp\n" elif not base_opt.addresses: @@ -162,6 +196,12 @@ class IfcfgNetConfig(os_net_config.NetConfig): data += "DEFROUTE=no\n" if base_opt.dhclient_args: data += "DHCLIENTARGS=%s\n" % base_opt.dhclient_args + if base_opt.dns_servers: + data += "DNS1=%s\n" % base_opt.dns_servers[0] + if len(base_opt.dns_servers) == 2: + data += "DNS2=%s\n" % base_opt.dns_servers[1] + elif len(base_opt.dns_servers) > 2: + logger.warning('ifcfg format supports a max of 2 dns servers.') return data def _add_routes(self, interface_name, routes=[]): @@ -220,6 +260,18 @@ class IfcfgNetConfig(os_net_config.NetConfig): if bridge.routes: self._add_routes(bridge.name, bridge.routes) + def add_linux_bridge(self, bridge): + """Add a LinuxBridge object to the net config object. + + :param bridge: The LinuxBridge object to add. + """ + logger.info('adding linux bridge: %s' % bridge.name) + data = self._add_common(bridge) + logger.debug('bridge data: %s' % data) + self.linuxbridge_data[bridge.name] = data + if bridge.routes: + self._add_routes(bridge.name, bridge.routes) + def add_bond(self, bond): """Add an OvsBond object to the net config object. @@ -232,6 +284,19 @@ class IfcfgNetConfig(os_net_config.NetConfig): if bond.routes: self._add_routes(bond.name, bond.routes) + def add_linux_bond(self, bond): + """Add a LinuxBond object to the net config object. + + :param bond: The LinuxBond object to add. + """ + logger.info('adding linux bond: %s' % bond.name) + data = self._add_common(bond) + logger.debug('bond data: %s' % data) + self.interface_data[bond.name] = data + self.linuxbond_data[bond.name] = data + if bond.routes: + self._add_routes(bond.name, bond.routes) + def apply(self, cleanup=False, activate=True): """Apply the network configuration. @@ -282,6 +347,35 @@ class IfcfgNetConfig(os_net_config.NetConfig): update_files[bridge_route_path] = route_data 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, '') + bridge_path = self.root_dir + bridge_config_path(bridge_name) + bridge_route_path = self.root_dir + route_config_path(bridge_name) + all_file_names.append(bridge_path) + all_file_names.append(bridge_route_path) + if (utils.diff(bridge_path, bridge_data) or + utils.diff(bridge_route_path, route_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 + 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, '') + bond_path = self.root_dir + bridge_config_path(bond_name) + bond_route_path = self.root_dir + route_config_path(bond_name) + all_file_names.append(bond_path) + all_file_names.append(bond_route_path) + if (utils.diff(bond_path, bond_data) or + utils.diff(bond_route_path, route_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 + logger.info('No changes required for linux bond: %s' % + bond_name) + if cleanup: for ifcfg_file in glob.iglob(cleanup_pattern()): if ifcfg_file not in all_file_names: |