Ejemplo n.º 1
0
def main():
    """ Oversee the sequence of tasks as per the documentation of this script. """
    print(cleandoc(__doc__))
    print()

    print('Select an appropriate device from those available.')
    print_table(inventory_config)
    print()
    for device_config in inventory_config:
        try:
            http_session = connect(**device_config)
            try:
                print('Connected to', session_device_url(http_session))
                print()
                demonstrate(http_session)
                return EX_OK if print_command_reference(
                    http_session, command) else EX_TEMPFAIL
            finally:
                disconnect(http_session)
        except IOError:
            log(WARN, 'Unable to connect to Nexus device %s',
                str(device_config))
            continue

    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL
def main():
    """ Print documentation; Print configuration of each device."""
    print(cleandoc(__doc__))
    print()
    
    print('Loaded from:', getfile(config_module))
    print()
    
    if not inventory_config:
        print("There are no network devices configured.")
        return EX_TEMPFAIL

    print('Configured devices.')
    print_table(inventory_config)
    print()
    
    exit_code = EX_OK
    for device_config in inventory_config:
        try:
            http_session = connect(**device_config)
            print('Connected to', session_device_url(http_session))
            disconnect(http_session)
        except IOError:
            log(WARN, 'Unable to connect to Nexus device %s', str(device_config))
            exit_code = EX_TEMPFAIL
            continue
    return exit_code
def main():
    """ Print documentation; Print configuration of each device."""
    print(cleandoc(__doc__))
    print()

    print('Loaded from:', getfile(config_module))
    print()

    if not inventory_config:
        print("There are no network devices configured.")
        return EX_TEMPFAIL

    print('Configured devices.')
    print_table(inventory_config)
    print()

    exit_code = EX_OK
    for device_config in inventory_config:
        try:
            http_session = connect(**device_config)
            print('Connected to', session_device_url(http_session))
            disconnect(http_session)
        except IOError:
            log(WARN, 'Unable to connect to Nexus device %s',
                str(device_config))
            exit_code = EX_TEMPFAIL
            continue
    return exit_code
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]
        
        for table in output.values():
            display_table = []
            for row in table.values():
                for acl in row:
                    acl_name = acl['acl_name']
                    for entries in acl['TABLE_seqno'].values():
                        if isinstance(entries,dict):
                            entries=[entries]
                        for entry in entries:
                            ordered_entry = OrderedDict()
                            ordered_entry['acl-name'] = acl_name
                            ordered_entry['seqno'] = entry['seqno']
                            keys = [k for k in entry.keys() if k != 'seqno']
                            for key in sorted(keys):
                                ordered_entry[key] = entry[key]
                            display_table.append(ordered_entry)
            print_table(display_table)
        print()
    return True
Ejemplo n.º 5
0
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    #     print("Execute command '%s' on network device %s" % (command, device_url(**device_config)))
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        print_table(response[c])
        print()
    return True
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
#     print("Execute command '%s' on network device %s" % (command, device_url(**device_config)))
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        print_table(response[c])
        print()
    return True
Ejemplo n.º 7
0
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]
        table_intf = output['TABLE_intf']
        rows_intf = table_intf['ROW_intf']
        if not isinstance(rows_intf, list):
            rows_intf = [rows_intf]
        print_table(rows_intf)
        print()
    return True
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print("Output for command:", c)
        output = response[c]
        table_intf = output["TABLE_intf"]
        rows_intf = table_intf["ROW_intf"]
        if not isinstance(rows_intf, list):
            rows_intf = [rows_intf]
        print_table(rows_intf)
        print()
    return True
Ejemplo n.º 9
0
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]

        table_vrf = output['TABLE_vrf']
        display_table = []
        rows_vrf = table_vrf['ROW_vrf']
        if not isinstance(rows_vrf, list):
            rows_vrf = [rows_vrf]
        for row_vrf in rows_vrf:
            display_vrf = OrderedDict()
            keys = [k for k in row_vrf if not k.startswith('TABLE')]
            for k in sorted(keys):
                display_vrf[k] = row_vrf[k]
            table_addrf = row_vrf['TABLE_addrf']
            rows_addrf = table_addrf['ROW_addrf']
            if not isinstance(rows_addrf, list):
                rows_addrf = [rows_addrf]
            for row_addrf in rows_addrf:
                display_addrf = OrderedDict(display_vrf)
                keys = [k for k in row_addrf if not k.startswith('TABLE')]
                for k in sorted(keys):
                    display_addrf[k] = row_addrf[k]
                table_prefix = row_addrf['TABLE_prefix']
                rows_prefix = table_prefix['ROW_prefix']
                if not isinstance(rows_prefix, list):
                    rows_prefix = [rows_prefix]
                for row_prefix in rows_prefix:
                    display_prefix = OrderedDict(display_addrf)
                    keys = [k for k in row_prefix if not k.startswith('TABLE')]
                    for k in sorted(keys):
                        display_prefix[k] = row_prefix[k]
                    table_path = row_prefix['TABLE_path']
                    rows_path = table_path['ROW_path']
                    if not isinstance(rows_path, list):
                        rows_path = [rows_path]
                    for row_path in rows_path:
                        display_path = OrderedDict(display_prefix)
                        keys = [k for k in row_path if not k.startswith('TABLE')]
                        for k in sorted(keys):
                            display_path[k] = row_path[k]
                        display_table.append(display_path)
        print_table(display_table)
        print()
    return True
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]
        
        table_intf =output['TABLE_intf']
        rows = [row.values() for row in table_intf]
        rows=list(chain(*rows))
        print_table(rows)
        print()

        table_vrf =output['TABLE_vrf']
        rows = [row.values() for row in table_vrf]
        rows=list(chain(*rows))
        print_table(rows)
        print()
    return True
Ejemplo n.º 11
0
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]

        table_cdp = output['TABLE_cdp_neighbor_brief_info']
        display_table = []
        rows_cdp = table_cdp['ROW_cdp_neighbor_brief_info']
        if not isinstance(rows_cdp, list):
            rows_cdp = [rows_cdp]
        for row_cdp in rows_cdp:
            display_cdp = OrderedDict()
            keys = [k for k in row_cdp if not k.startswith('TABLE')]
            for k in sorted(keys):
                display_cdp[k] = row_cdp[k]
            display_table.append(display_cdp)
        print_table(display_table)
        print()
    return True
def demonstrate(session):
    """ Execute a command, print the output, return 'true' if successful. """
    response = cli_show(session, command)
    for c in response:
        print('Output for command:', c)
        output = response[c]

        table_cdp = output['TABLE_cdp_neighbor_brief_info']
        display_table = []
        rows_cdp=table_cdp['ROW_cdp_neighbor_brief_info']
        if not isinstance(rows_cdp, list):
            rows_cdp = [rows_cdp]
        for row_cdp in rows_cdp:
            display_cdp = OrderedDict()
            keys = [k for k in row_cdp if not k.startswith('TABLE')]
            for k in sorted(keys):
                display_cdp[k] = row_cdp[k]
            display_table.append(display_cdp)
        print_table(display_table)
        print()
    return True
def main():
    """ Oversee the sequence of tasks as per the documentation of this script. """
    print(cleandoc(__doc__))
    print()
    
    print('Select an appropriate device from those available.')
    print_table(inventory_config)
    print()
    for device_config in inventory_config:
        try:
            http_session = connect(**device_config)
            try:
                print('Connected to', session_device_url(http_session))
                print()
                demonstrate(http_session)
                return EX_OK if print_command_reference(http_session, command) else EX_TEMPFAIL        
            finally:
                disconnect(http_session)
        except IOError:
            log(WARN, 'Unable to connect to Nexus device %s', str(device_config))
            continue
    
    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL