def main(): # Simple command line arguments for help and version parser = argparse.ArgumentParser(description='Retrieve a list of PnP files ' 'available in Cisco Business Dashboard.') parser.add_argument('--version', action='version', version='%(prog)s 1.0') args = parser.parse_args() # Create a properly formatted JWT using token = cbdauth.getToken(keyid=environment.keyid, secret=environment.secret, clientid=environment.clientid, appname=environment.appname) # Get image list imagedata = doAPIQuery('https://%s:%s/api/v2/pnp/images' % (environment.dashboard, environment.port), token, environment.verify_cbd_cert) # Iterate through the response and print in a nice-ish table print('='*48,'PnP Images','='*49) print("| {:25} | {:64} | {:10} |".format('File ID','Filename','Size')) print('|','-'*25,'+','-'*64,'+','-'*10,'|') for image in imagedata['data']: print("| {id:25} | {file-name:64} | {file-size:10} |".format(**image)) print('+','-'*25,'+','-'*64,'+','-'*10,'+','\n') # Get config list configdata = doAPIQuery('https://%s:%s/api/v2/pnp/configs' % (environment.dashboard, environment.port), token, environment.verify_cbd_cert) # Iterate through the response and print in a nice-ish table print('='*48,'PnP Configs','='*48) print("| {:25} | {:64} | {:10} |".format('File ID','Filename','Size')) print('|','-'*25,'+','-'*64,'+','-'*10,'|') for config in configdata['data']: print("| {id:25} | {file-name:64} | {file-size:10} |".format(**config)) print('+','-'*25,'+','-'*64,'+','-'*10,'+','\n')
action='append', help='The nodeId for the device to reboot. Multiple ' 'IDs may be specified.') args = parser.parse_args() if (args.device is None): print("At least one device must be specified.") else: # Create a dictionary of the request details, ready for conversion to # a JSON payload later action = {'node-ids': args.device} # Create a properly formatted JWT using environment data token = cbdauth.getToken(keyid=environment.keyid, secret=environment.secret, clientid=environment.clientid, appname=environment.appname) try: # Build and send the API request. The reboot operation API path is # /api/v2/nodes/operations/reboot. Include the action details dictionary # as a JSON payload response = requests.post( 'https://%s:%s/api/v2/nodes/operations/reboot' % (environment.dashboard, environment.port), headers={'Authorization': "Bearer %s" % token}, json=action, verify=environment.verify_cbd_cert) except requests.exceptions.RequestException as e: # Generally this will be a connection error or timeout. HTTP errors are