def _get_interface_obj_children(self, intf): """Get a interface's children on this hosting device. :return: List of the interfaces' objects """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_children("^interface " + intf) LOG.debug("Interface children on hosting device: %s", itfcs_raw) return itfcs_raw
def _get_interfaces_objs(self): """Get a list of interfaces on this hosting device. :return: List of the interfaces' objects """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_children("^interface \w+\d+") LOG.debug("Interfaces on hosting device: %s", itfcs_raw) return itfcs_raw
def _get_interface_ip(self, interface_name): """Get the ip address for an interface. :param interface_name: interface_name as a string :return: ip address of interface as a string """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) children = parse.find_children("^interface %s" % interface_name) for line in children: if 'ip address' in line: ip_address = line.strip().split(' ')[2] LOG.debug("IP Address:%s", ip_address) return ip_address LOG.warning("Cannot find interface: %s", interface_name) return None
def _get_interface_ip(self, interface_name): """Get the ip address for an interface. :param interface_name: interface_name as a string :return: ip address of interface as a string """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) children = parse.find_children("^interface %s" % interface_name) for line in children: if "ip address" in line: ip_address = line.strip().split(" ")[2] LOG.debug("IP Address:%s", ip_address) return ip_address LOG.warning(_LW("Cannot find interface: %s"), interface_name) return None
def _check_acl(self, acl_no, network, netmask): """Check a ACL config exists in the running config. :param acl_no: access control list (ACL) number :param network: network which this ACL permits :param netmask: netmask of the network :return: """ exp_cfg_lines = ["ip access-list standard " + str(acl_no), " permit " + str(network) + " " + str(netmask)] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) acls_raw = parse.find_children(exp_cfg_lines[0]) if acls_raw: if exp_cfg_lines[1] in acls_raw: return True LOG.error(_LE("Mismatch in ACL configuration for %s"), acl_no) return False LOG.debug("%s is not present in config", acl_no) return False
def _check_acl(self, acl_no, network, netmask): """Check a ACL config exists in the running config. :param acl_no: access control list (ACL) number :param network: network which this ACL permits :param netmask: netmask of the network :return: """ exp_cfg_lines = ['ip access-list standard ' + str(acl_no), ' permit ' + str(network) + ' ' + str(netmask)] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) acls_raw = parse.find_children(exp_cfg_lines[0]) if acls_raw: if exp_cfg_lines[1] in acls_raw: return True LOG.error("Mismatch in ACL configuration for %s", acl_no) return False LOG.debug("%s is not present in config", acl_no) return False
def _get_interface_cfg(self, interface): ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) return parse.find_children('interface ' + interface)
def _get_interface_cfg(self, interface): ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) return parse.find_children("interface " + interface)