예제 #1
0
def table(ctx, device, json):
    """
    Show Interfaces
    """
    vmanage_device = Device(ctx.auth, ctx.host)

    # Check to see if we were passed in a device IP address or a device name
    try:
        ip = ipaddress.ip_address(device)
        system_ip = ip
    except ValueError:
        device_dict = vmanage_device.get_device_status(device, key='host-name')
        if 'system-ip' in device_dict:
            system_ip = device_dict['system-ip']
        else:
            system_ip = None

    if not json:
        click.echo(
            "VPNID  PREFIX               NEXT HOP              PROTOCOL      ")
        click.echo(
            "----------------------------------------------------------------")

    routes = vmanage_device.get_device_data('ip/routetable', system_ip)
    for rte in routes:
        if json:
            pp = pprint.PrettyPrinter(indent=2)
            pp.pprint(rte)
        else:
            if 'nexthop-addr' not in rte:
                rte['nexthop-addr'] = ''
            click.echo(
                f"{rte['vpn-id']:5}  {rte['prefix']:<20} {rte['nexthop-addr']:<20}  {rte['protocol']:8}"
            )
예제 #2
0
def list_interface(ctx, device, json):
    """
    Show Interfaces
    """
    vmanage_device = Device(ctx.auth, ctx.host)

    if device:
        # Check to see if we were passed in a device IP address or a device name
        try:
            ipaddress.ip_address(device)
            system_ip = device
        except ValueError:
            device_dict = vmanage_device.get_device_status(device,
                                                           key='host-name')
            if 'system-ip' in device_dict:
                system_ip = device_dict['system-ip']
        device_list = [system_ip]

    if not json:
        click.echo(
            "IFNAME            VPNID  IP ADDR          MAC ADDR                  OPER STATE            DESC"
        )
        click.echo(
            "----------------------------------------------------------------------------------------------------------------------"
        )

    for dev in device_list:
        interfaces = vmanage_device.get_device_data('interface', dev)
        for iface in interfaces:
            if json:
                pp = pprint.PrettyPrinter(indent=2)
                pp.pprint(iface)
            else:
                if 'hwaddr' not in iface:
                    iface['hwaddr'] = ''
                if 'desc' not in iface:
                    iface['desc'] = ''
                if 'ip-address' not in iface:
                    iface['ip-address'] = ''
                click.echo(
                    f"{iface['ifname']:17} {iface['vpn-id']:6} {iface['ip-address']:16} {iface['hwaddr']:25} {iface['if-oper-status']:17} {iface['desc']:17}"
                )