def status(ctx, dev, device_type, json): #pylint: disable=unused-argument """ Show device status information """ vmanage_device = Device(ctx.auth, ctx.host) # output = mn.get_control_connections_history(sysip) # vmanage_session = ctx.obj pp = pprint.PrettyPrinter(indent=2) if dev: # Check to see if we were passed in a device IP address or a device name try: system_ip = ipaddress.ip_address(dev) device_dict = vmanage_device.get_device_status(system_ip) except ValueError: device_dict = vmanage_device.get_device_status(dev, key='host-name') if device_dict: pp.pprint(device_dict) else: click.secho(f"Could not find device {dev}", err=True, fg='red') else: device_list = vmanage_device.get_device_status_list() if json: pp.pprint(device_list) else: click.echo( f"{'Hostname':20} {'System IP':15} {'Model':15} {'Site':6} {'Status':9} {'BFD':>3} {'OMP':>3} {'CON':>3} {'Version':8} {'UUID':40} {'Serial'}" ) for device_entry in device_list: if 'bfdSessionsUp' in device_entry: bfd = device_entry['bfdSessionsUp'] else: bfd = '' if 'ompPeers' in device_entry: omp = device_entry['ompPeers'] else: omp = '' if 'controlConnections' in device_entry: control = device_entry['controlConnections'] else: control = '' click.echo( f"{device_entry['host-name']:20} {device_entry['system-ip']:15} {device_entry['device-model']:15} {device_entry['site-id']:6} {device_entry['reachability']:9} {bfd:>3} {omp:>3} {control:>3} {device_entry['version']:8} {device_entry['uuid']:40} {device_entry['board-serial']}" )
#!/usr/bin/env python from vmanage.api.authentication import Authentication from vmanage.api.device import Device import pprint username = '******' password = '******' host = 'XX.XX.XX.XX' auth = Authentication(host=host, user=username, password=password).login() vmanage_device = Device(auth, host) device_status_list = vmanage_device.get_device_status_list() pp = pprint.PrettyPrinter(indent=2) pp.pprint(device_status_list)