def update_device_management_conf(self): """ Updates the management interfaces configuration for nodes in the lab topology. For each node it will call the platform specific method to update Loopback interface address from provided subnet using the next available address for each device. """ try: for nodenum, nodedef in enumerate(self.lab_conf["nodes"]): try: ip = netaddr.IPNetwork( self._cmlnetkitconfig.mgmt_range[nodenum]) except netaddr.AddrFormatError as e: raise ValueError("%s" % e) except IndexError as e: raise IndexError( "mgmt-range: Not enough management addresses provided") ip.prefixlen = self._cmlnetkitconfig.mgmt_prefixlen # We find the method to call using the self._node_types_fm dictionary try: node_config = self._get_node_config( self._get_node_index_by_label(nodedef.get("label"))) node_parsed_config = CiscoConfParse( node_config.split('\n')) self._node_types_fn["update_node_management_conf_" + self._get_node_type( self._get_node_index_by_label( nodedef.get("label")))]( node_parsed_config, ip.ip.__str__(), ip.netmask.__str__()) node_parsed_config.atomic() node_new_config = '\n'.join( [i for i in node_parsed_config.ioscfg[0:]]) self._set_node_config( self._get_node_index_by_label(nodedef.get("label")), node_new_config) self.lab_conf_changed = True except TypeError as e: raise TypeError(e) # No key found in self._node_types_fn except KeyError as e: # For other than known and specified in self._node_types_fn node types do nothing just ignore continue # raise KeyError(e) # Exception from CiscoConfParse constructor except ValueError as e: raise ValueError(e) except IndexError as e: raise IndexError( "mgmt-range: Not enough management addresses provided")
def update_device_peer_interfaces_conf(self): """ Updates the addresses on interfaces if directly connected devices. """ subnets = list( netaddr.IPNetwork(self._cmlnetkitconfig.peer_subnet).subnet(30)) try: for linknum, link in enumerate(self.lab_conf["links"]): iface_a_name = self._get_interface_name_by_id( self._get_node_index_by_id(link["n1"]), link["i1"]) iface_b_name = self._get_interface_name_by_id( self._get_node_index_by_id(link["n2"]), link["i2"]) # We need to ignore connections to 'external_connector' and 'iosvl2' objects if self._get_node_type( self._get_node_index_by_id(link['n1']) ) in self._node_types_ignored or self._get_node_type( self._get_node_index_by_id( link['n2'])) in self._node_types_ignored: continue if self._get_node_type(self._get_node_index_by_id( link["n1"])) in self._node_types_supported: node_a_config = self._get_node_config( self._get_node_index_by_id(link["n1"])) node_a_parsed_config = CiscoConfParse( node_a_config.split('\n')) self._node_types_fn[ "update_node_peer_interface_conf_" + self._get_node_type( self._get_node_index_by_id(link["n1"]))]( node_a_parsed_config, iface_a_name, subnets[linknum][1].__str__(), subnets[linknum].netmask.__str__()) node_a_parsed_config.atomic() node_a_new_config = '\n'.join( [i for i in node_a_parsed_config.ioscfg[0:]]) self._set_node_config( self._get_node_index_by_id(link["n1"]), node_a_new_config) self.lab_conf_changed = True if self._get_node_type(self._get_node_index_by_id( link["n2"])) in self._node_types_supported: node_b_config = self._get_node_config( self._get_node_index_by_id(link["n2"])) node_b_parsed_config = CiscoConfParse( node_b_config.split('\n')) self._node_types_fn[ "update_node_peer_interface_conf_" + self._get_node_type( self._get_node_index_by_id(link["n2"]))]( node_b_parsed_config, iface_b_name, subnets[linknum][2].__str__(), subnets[linknum].netmask.__str__()) node_b_parsed_config.atomic() node_b_new_config = '\n'.join( [i for i in node_b_parsed_config.ioscfg[0:]]) self._set_node_config( self._get_node_index_by_id(link["n2"]), node_b_new_config) self.lab_conf_changed = True except IndexError as e: raise IndexError("peer-range: Not enough IP addresses provided")