Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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
Example #8
0
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
Example #9
0
def step_impl(context):
    context.o0201 = Facts(
        hostname='spine02',
        domain='dh.local',
        version='8.1.0.0',
        build=NOT_SET,
        serial='SDNIPM624B36',
        base_mac='00:51:00:02:00:00',
        memory=2087444480,
        vendor='Extreme Networks',
        model='8284XSQ',
        interfaces_lst=[
            'mgmt', '1/1', '1/2', '1/3', '1/4', '1/5', '1/6', '1/7', '1/8',
            '1/9', '1/10', '1/11', '1/12', '1/13', '1/14', '1/15', '1/16',
            '1/17', '1/18', '1/19', '1/20', '1/21', '1/22', '1/23', '1/24',
            '1/25', '1/26', '1/27', '1/28', '1/29', '1/30', '1/31', '1/32',
            '1/33', '1/34', '1/35', '1/36', '1/37', '1/38', '1/39', '1/40',
            '1/41', '1/42', '2/1', '2/2', '2/3', '2/4', '2/5', '2/6', '2/7',
            '2/8', '2/9', '2/10', '2/11', '2/12', '2/13', '2/14', '2/15',
            '2/16', '2/17', '2/18', '2/19', '2/20', '2/21', '2/22', '2/23',
            '2/24', '2/25', '2/26', '2/27', '2/28', '2/29', '2/30', '2/31',
            '2/32', '2/33', '2/34', '2/35', '2/36', '2/37', '2/38', '2/39',
            '2/40', '2/41', '2/42', 'Default'
        ],
        options={})
Example #10
0
def step_impl(context):
    context.o0701 = Facts(hostname='leaf02',
                          domain='dh.local',
                          version='9.3(3)',
                          build=NOT_SET,
                          serial='9QXOX90PJ62',
                          base_mac=NOT_SET,
                          memory='16409064',
                          vendor='Cisco Systems, Inc.',
                          model='Nexus9000',
                          interfaces_lst=[],
                          options={})
Example #11
0
def step_impl(context):
    context.o0601 = Facts(hostname='leaf03',
                          domain=NOT_SET,
                          version=NOT_SET,
                          build=NOT_SET,
                          serial='9QXOX90PJ62',
                          base_mac=NOT_SET,
                          memory=NOT_SET,
                          vendor='Cisco',
                          model='Nexus9000 C9300v Chassis',
                          interfaces_lst=[],
                          options={})
Example #12
0
def step_impl(context):
    context.o0501 = Facts(hostname='leaf04',
                          domain='dh.local',
                          version='18.3R1.9',
                          build=NOT_SET,
                          serial='VM5E983D143E',
                          base_mac=NOT_SET,
                          memory=2052008,
                          vendor='Juniper',
                          model='VMX',
                          interfaces_lst=[],
                          options={})
Example #13
0
def step_impl(context):
    context.o0101 = Facts(hostname='cumulus',
                          domain=NOT_SET,
                          version='3.7.5',
                          build='Cumulus Linux 3.7.5',
                          serial='50:00:00:01:00:00',
                          base_mac='50:00:00:01:00:00',
                          memory=951264,
                          vendor='Cumulus Networks',
                          model='VX',
                          interfaces_lst=[
                              'swp5', 'swp7', 'swp2', 'swp3', 'swp1', 'swp6',
                              'swp4', 'eth0'
                          ],
                          options={})
Example #14
0
def step_impl(context):
    context.o0301 = Facts(hostname='leaf05',
                          domain='dh.local',
                          version='16.8.1',
                          build='fc3',
                          serial='9YEI1T9ZCIY',
                          base_mac=NOT_SET,
                          memory='8113376',
                          vendor='Cisco',
                          model='CSR1000V',
                          interfaces_lst=[
                              'GigabitEthernet1', 'GigabitEthernet2',
                              'GigabitEthernet3'
                          ],
                          options={})
Example #15
0
def step_impl(context):
    context.o0001 = Facts(hostname='leaf03',
                          domain='dh.local',
                          version='4.24.0F',
                          build='da8d6269-c25f-4a12-930b-c3c42c12c38a',
                          serial='',
                          base_mac='50:00:00:d7:ee:0b',
                          memory=2014424,
                          vendor='Arista',
                          model='vEOS',
                          interfaces_lst=[
                              'Management1', 'Ethernet8', 'Ethernet2',
                              'Ethernet3', 'Ethernet1', 'Ethernet6',
                              'Ethernet7', 'Ethernet4', 'Ethernet5'
                          ],
                          options={})
Example #16
0
def _compare_facts(host_keys,
                   hostname: str,
                   groups: list,
                   facts_host_data: Facts,
                   test=False,
                   options={},
                   task=Task) -> bool:
    if ('own_vars' in options.keys() and options.get('own_vars') is not None
            and 'enable' in options.get('own_vars').keys()
            and options.get('own_vars').get('enable') is True):
        raise NetestsOverideTruthVarsKeyUnsupported()
    else:
        if test:
            facts_yaml_data = open_file(
                path="tests/features/src/facts_tests.yml").get(hostname)
        else:
            facts_yaml_data = select_host_vars(hostname=hostname,
                                               groups=groups,
                                               protocol="facts")

        if (FACTS_DATA_HOST_KEY in host_keys and facts_yaml_data is not None):
            verity_facts = Facts(
                hostname=hostname,
                domain=facts_yaml_data.get('domain', NOT_SET),
                version=facts_yaml_data.get('version', NOT_SET),
                build=facts_yaml_data.get('build', NOT_SET),
                serial=facts_yaml_data.get('serial', NOT_SET),
                base_mac=facts_yaml_data.get('serial', NOT_SET),
                memory=facts_yaml_data.get('memory', NOT_SET),
                vendor=facts_yaml_data.get('vendor', NOT_SET),
                model=facts_yaml_data.get('model', NOT_SET),
                interfaces_lst=facts_yaml_data.get('interfaces', list()),
                options=facts_host_data.options)

        else:
            print(f"{HEADER} Key {FACTS_DATA_HOST_KEY} is missing"
                  f"for {hostname} or no Facts data has been found.")
            return False

    if verbose_mode(user_value=os.environ.get("NETESTS_VERBOSE", NOT_SET),
                    needed_value=LEVEL2):
        print(f"{HEADER} Return value for host {hostname}"
              f"is {verity_facts == facts_host_data}")

    return verity_facts == facts_host_data
Example #17
0
def step_impl(context):
    context.o0401 = Facts(
        hostname='spine03',
        domain='dh.local',
        version='6.5.3',
        build=NOT_SET,
        serial=NOT_SET,
        base_mac=NOT_SET,
        memory=NOT_SET,
        vendor='Cisco',
        model='IOS-XRv 9000',
        interfaces_lst=[
            'Bundle-Ether1', 'Bundle-Ether1.1234', 'Bundle-Ether1.4321',
            'Loopback100', 'Loopback200', 'MgmtEth0/RP0/CPU0/0',
            'GigabitEthernet0/0/0/0', 'GigabitEthernet0/0/0/1',
            'GigabitEthernet0/0/0/2', 'GigabitEthernet0/0/0/3',
            'GigabitEthernet0/0/0/4', 'GigabitEthernet0/0/0/5',
            'GigabitEthernet0/0/0/6'
        ],
        options={})
Example #18
0
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
Example #19
0
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
Example #20
0
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