def _napalm_facts_converter(hostname: str, platform: str, cmd_output: json, options={}) -> Facts: if cmd_output is None: return Facts() i = len(f"{str(cmd_output.get('facts').get('hostname'))}.") facts = Facts( hostname=cmd_output.get('facts').get('hostname') if cmd_output.get("facts").get("hostname", NOT_SET) != '' else NOT_SET, domain=cmd_output.get("facts").get("fqdn", NOT_SET)[i:] if cmd_output.get("facts").get("fqdn", NOT_SET) != '' else NOT_SET, version=cmd_output.get("facts").get("os_version", NOT_SET) if cmd_output.get("facts").get("os_version", NOT_SET) != '' else NOT_SET, serial=cmd_output.get("facts").get("serial_number", NOT_SET) if cmd_output.get("facts").get("serial_number", NOT_SET) != '' else NOT_SET, base_mac=NOT_SET, memory=NOT_SET, vendor=cmd_output.get("facts").get("vendor", NOT_SET) if cmd_output.get("facts").get("vendor", NOT_SET) != '' else NOT_SET, model=cmd_output.get("facts").get("model", NOT_SET) if cmd_output.get("facts").get("model", NOT_SET) != '' else NOT_SET, interfaces_lst=cmd_output.get('facts').get('interface_list') if cmd_output.get("facts").get("interface_list", NOT_SET) != '' else [], options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _iosxr_facts_netconf_converter(hostname: str, cmd_output, options={}) -> Facts: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() print(type(cmd_output)) print(cmd_output) hostname = NOT_SET domain = NOT_SET version = NOT_SET serial = NOT_SET model = NOT_SET interfaces_lst = list() facts = Facts(hostname=hostname, domain=domain, version=version, build=NOT_SET, serial=serial, base_mac=NOT_SET, memory=NOT_SET, vendor="Cisco", model=model, interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _juniper_facts_netconf_converter(hostname: str(), cmd_output, options={}) -> Facts: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() PP.pprint(cmd_output.get(FACTS_SYS_DICT_KEY)) print(ElementTree.tostring(cmd_output.get(FACTS_INT_DICT_KEY))) interfaces_lst = list() for i in format_xml_output(cmd_output.get(FACTS_INT_DICT_KEY)).get( 'interface-information').get('physical-interface'): interfaces_lst.append(i.get('name')) facts = Facts( hostname=cmd_output.get(FACTS_SYS_DICT_KEY).get('hostname', NOT_SET), domain=cmd_output.get(FACTS_SYS_DICT_KEY).get('domain', NOT_SET), build=NOT_SET, version=cmd_output.get(FACTS_SYS_DICT_KEY).get('version', NOT_SET), serial=cmd_output.get(FACTS_SYS_DICT_KEY).get('serialnumber', NOT_SET), base_mac=NOT_SET, memory=NOT_SET, vendor="Juniper", model=cmd_output.get(FACTS_SYS_DICT_KEY).get('model', NOT_SET).upper(), interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _ios_facts_api_converter(hostname: str, cmd_output, options={}) -> Facts: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() print(type(cmd_output)) PP.pprint(json.loads(cmd_output)) hostname = NOT_SET domain = NOT_SET version = NOT_SET model = NOT_SET serial = NOT_SET interfaces_lst = list() if not isinstance(cmd_output, dict): cmd_output = json.loads(cmd_output) if (isinstance(cmd_output, dict) and 'Cisco-IOS-XE-native:native' in cmd_output.keys()): hostname = cmd_output.get('Cisco-IOS-XE-native:native') \ .get('hostname') domain = cmd_output.get('Cisco-IOS-XE-native:native') \ .get('ip') \ .get('domain') \ .get('name') version = cmd_output.get('Cisco-IOS-XE-native:native') \ .get('version') serial = cmd_output.get('Cisco-IOS-XE-native:native') \ .get('license') \ .get('udi') \ .get('sn') model = cmd_output.get('Cisco-IOS-XE-native:native') \ .get('license') \ .get('udi') \ .get('pid') for t in cmd_output.get('Cisco-IOS-XE-native:native') \ .get('interface').keys(): for i in cmd_output.get('Cisco-IOS-XE-native:native') \ .get('interface') \ .get(t): interfaces_lst.append(f"{t}{i.get('name')}") facts = Facts(hostname=hostname, domain=domain, version=version, build=NOT_SET, serial=serial, base_mac=NOT_SET, memory=NOT_SET, vendor="Cisco", model=model, interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _ios_facts_ssh_converter( hostname: str, cmd_output, options={} ) -> Facts: interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_INT_DICT_KEY] = parse_textfsm( content=cmd_output.get(FACTS_INT_DICT_KEY), template_file='cisco_ios_show_ip_int_brief.textfsm' ) for i in cmd_output.get(FACTS_INT_DICT_KEY): interfaces_lst.append(i[0]) hostname = NOT_SET version = NOT_SET model = NOT_SET serial = NOT_SET build = NOT_SET memory = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_SYS_DICT_KEY] = parse_textfsm( content=cmd_output.get(FACTS_SYS_DICT_KEY), template_file='cisco_ios_show_version.textfsm' ) for i in cmd_output.get(FACTS_SYS_DICT_KEY): hostname = i[2] if i[2] != "" else NOT_SET version = i[0] if i[0] != "" else NOT_SET model = i[10] if i[10] != "" else NOT_SET serial = i[7][0] if i[7][0] != "" else NOT_SET build = i[11] if i[11] != "" else NOT_SET memory = i[12] if i[12] != "" else NOT_SET facts = Facts( hostname=hostname, domain=NOT_SET, version=version, build=build, serial=serial, base_mac=NOT_SET, memory=memory, vendor="Cisco", model=model, interfaces_lst=interfaces_lst, options=options ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() PP.pprint(facts.to_json()) return facts
def _juniper_facts_api_converter(hostname: str(), cmd_output, options={}) -> Facts: interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): for i in format_xml_output(cmd_output.get(FACTS_INT_DICT_KEY)).get( 'interface-information').get('physical-interface'): interfaces_lst.append(i.get('name')) hostname = NOT_SET version = NOT_SET model = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): i = format_xml_output(cmd_output.get(FACTS_SYS_DICT_KEY)) hostname = i.get('software-information') \ .get('host-name', NOT_SET) version = i.get('software-information') \ .get('junos-version', NOT_SET) model = i.get('software-information') \ .get('product-name', NOT_SET).upper() serial = NOT_SET if FACTS_SERIAL_DICT_KEY in cmd_output.keys(): i = format_xml_output(cmd_output.get(FACTS_SERIAL_DICT_KEY)) serial = i.get('chassis-inventory') \ .get('chassis') \ .get('serial-number', NOT_SET) memory = NOT_SET if FACTS_MEMORY_DICT_KEY in cmd_output.keys(): i = format_xml_output(cmd_output.get(FACTS_MEMORY_DICT_KEY)) memory = i.get('system-memory-information') \ .get('system-memory-summary-information') \ .get('system-memory-total', NOT_SET) facts = Facts( hostname=hostname, domain=NOT_SET, version=version, build=NOT_SET, serial=serial, base_mac=NOT_SET, memory=memory, vendor="Juniper", model=model, interfaces_lst=interfaces_lst, options=options, ) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _extreme_vsp_facts_api_converter( hostname: str, cmd_output, options={} ) -> Facts: hostname = NOT_SET domain = NOT_SET memory = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): hostname = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get('openconfig-system:system') \ .get('config') \ .get('hostname', NOT_SET) domain = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get('openconfig-system:system') \ .get('config') \ .get('domain-name', NOT_SET) memory = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get('openconfig-system:system') \ .get('memory') \ .get('state') \ .get('physical', NOT_SET) interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): for i in cmd_output.get(FACTS_INT_DICT_KEY) \ .get('openconfig-interfaces:interfaces') \ .get('interface'): interfaces_lst.append(i.get('name')) facts = Facts( hostname=hostname, domain=domain, version=NOT_SET, build=NOT_SET, serial=NOT_SET, base_mac=NOT_SET, memory=memory, vendor="Extreme Networks", model=NOT_SET, interfaces_lst=interfaces_lst, options=options ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() PP.pprint(facts.to_json()) return facts
def _extreme_vsp_facts_ssh_converter(hostname: str(), cmd_output, options={}) -> Facts: interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_INT_DICT_KEY] = parse_textfsm( content=cmd_output[FACTS_INT_DICT_KEY], template_file="extrme_vsp_show_int_gi_name.textfsm") for i in cmd_output.get(FACTS_INT_DICT_KEY): interfaces_lst.append(i[0]) hostname = NOT_SET version = NOT_SET model = NOT_SET serial = NOT_SET base_mac = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_SYS_DICT_KEY] = parse_textfsm( content=cmd_output[FACTS_SYS_DICT_KEY], template_file="extreme_vsp_show_tech.textfsm") for v in cmd_output.get(FACTS_SYS_DICT_KEY): hostname = v[1] if v[1] != "" else NOT_SET version = v[0] if v[0] != "" else NOT_SET model = v[2] if v[2] != "" else NOT_SET # vendor = v[3] if v[3] != "" else NOT_SET serial = v[4] if v[4] != "" else NOT_SET base_mac = v[5] if v[5] != "" else NOT_SET domain = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_DOMAIN_DICT_KEY] = parse_textfsm( content=cmd_output[FACTS_DOMAIN_DICT_KEY], template_file="extreme_vsp_show_sys_dns.textfsm") for v in cmd_output.get(FACTS_DOMAIN_DICT_KEY): domain = v[0] if v[0] != "" else NOT_SET facts = Facts(hostname=hostname, domain=domain, version=version, build=NOT_SET, serial=serial, base_mac=base_mac, memory=NOT_SET, vendor="Extreme Networks", model=model, interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _arista_facts_api_converter( hostname: str(), cmd_output, options={} ) -> Facts: interfaces_lst = list() if 'result' in cmd_output.keys(): if not isinstance(cmd_output.get('result')[1], dict): cmd_output.get('result')[1] = json.loads( cmd_output.get('result')[1] ) for interface_name in cmd_output.get('result')[1] \ .get('interfaceStatuses'): if "Eth" in interface_name or "Mana" in interface_name: interfaces_lst.append(interface_name) version = NOT_SET serial = NOT_SET base_mac = NOT_SET memory = NOT_SET model = NOT_SET build = NOT_SET if 'result' in cmd_output.keys(): if not isinstance(cmd_output.get('result')[1], dict): cmd_output.get('result')[0] = json.loads( cmd_output.get('result')[0] ) memory = cmd_output.get('result')[0].get('memTotal') model = cmd_output.get('result')[0].get('modelName') version = cmd_output.get('result')[0].get('version') serial = cmd_output.get('result')[0].get('serialNumber') base_mac = cmd_output.get('result')[0].get('systemMacAddress') build = cmd_output.get('result')[0].get('internalBuildId') if 'result' in cmd_output.keys(): if not isinstance(cmd_output.get('result')[2], dict): cmd_output.get('result')[2] = json.loads( cmd_output.get('result')[2] ) hostname = cmd_output.get('result')[2].get('hostname') if "." in cmd_output.get('result')[2].get('fqdn'): i = cmd_output.get('result')[2] \ .get('fqdn', NOT_SET).find('.') domain = cmd_output.get('result')[2] \ .get("fqdn")[i+1:] else: domain = cmd_output.get('result')[2].get("fqdn") facts = Facts( hostname=hostname, domain=domain, version=version, build=build, serial=serial, base_mac=base_mac, memory=memory, vendor="Arista", model=model, interfaces_lst=interfaces_lst, options=options ) if verbose_mode( user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1 ): printline() PP.pprint(facts.to_json()) return facts
def _cumulus_facts_api_converter(hostname: str, cmd_output, options={}) -> Facts: hostname = NOT_SET version = NOT_SET serial = NOT_SET base_mac = NOT_SET memory = NOT_SET vendor = NOT_SET model = NOT_SET build = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_SYS_DICT_KEY] = json.loads( cmd_output.get(FACTS_SYS_DICT_KEY)) if '\\n' in cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET): i = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET).find("\n") hostname = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET)[:(i-1)] elif '\n' in cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET): i = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET).find("\n") hostname = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET)[:i] else: hostname = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("hostname", NOT_SET) version = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("os-version", NOT_SET) build = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("build", NOT_SET) serial = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("eeprom") \ .get("tlv") \ .get("Serial Number") \ .get("value", NOT_SET) base_mac = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("eeprom") \ .get("tlv") \ .get("Base MAC Address") \ .get("value", NOT_SET) memory = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("memory", NOT_SET) vendor = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("eeprom") \ .get("tlv") \ .get("Vendor Name") \ .get("value", NOT_SET) model = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("platform") \ .get("model", NOT_SET) interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): cmd_output[FACTS_INT_DICT_KEY] = json.loads( cmd_output.get(FACTS_INT_DICT_KEY)) for interface_name in cmd_output.get(FACTS_INT_DICT_KEY).keys(): if "swp" in interface_name or "eth" in interface_name: interfaces_lst.append(interface_name) facts = Facts(hostname=hostname, domain=NOT_SET, version=version, build=build, serial=serial, base_mac=base_mac, memory=memory, vendor=vendor, model=model, interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts
def _nxos_facts_ssh_converter(hostname: str(), cmd_output, options={}) -> Facts: if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL5): printline() print(type(cmd_output)) PP.pprint(json.loads(cmd_output)) interfaces_lst = list() if FACTS_INT_DICT_KEY in cmd_output.keys(): for i in cmd_output.get(FACTS_INT_DICT_KEY) \ .get('TABLE_interface') \ .get('ROW_interface'): interfaces_lst.append(i.get('interface')) hostname = NOT_SET version = NOT_SET serial = NOT_SET memory = NOT_SET vendor = NOT_SET model = NOT_SET if FACTS_SYS_DICT_KEY in cmd_output.keys(): hostname = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("host_name", NOT_SET) version = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("kickstart_ver_str", NOT_SET) serial = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("proc_board_id", NOT_SET) memory = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("memory", NOT_SET) vendor = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("manufacturer", NOT_SET) model = cmd_output.get(FACTS_SYS_DICT_KEY) \ .get("chassis_id", NOT_SET) domain = NOT_SET if FACTS_DOMAIN_DICT_KEY in cmd_output.keys(): if "." in cmd_output.get(FACTS_DOMAIN_DICT_KEY) \ .get('hostname', NOT_SET): i = cmd_output.get(FACTS_DOMAIN_DICT_KEY) \ .get('hostname', NOT_SET).find('.') domain = cmd_output.get(FACTS_DOMAIN_DICT_KEY) \ .get("hostname")[i+1:] else: domain = cmd_output.get(FACTS_DOMAIN_DICT_KEY) \ .get("hostname") facts = Facts(hostname=hostname, domain=domain, version=version, build=NOT_SET, serial=serial, base_mac=NOT_SET, memory=memory, vendor="Cisco" if True else vendor, model=model, interfaces_lst=interfaces_lst, options=options) if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET), needed_value=LEVEL1): printline() PP.pprint(facts.to_json()) return facts