09-14-2018 09:51 AM
Contantly clicking through the system gets tedious when testing your job code. Especially, when you use the same handful of devices to test on.
To speed things up, I created a small Python script that you can run on the CLI to kick off your job.
It's not perfect code. Just a quick script I cobbled together to help me out.
I haven't seen anyone post similar on the forums here, so I thought I would pass it along and maybe it will be useful to you as well.
To change the job, just edit the 'runURL' line.
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- __author__ = 'dschrock' """ Simple script to launch NetMRI jobs """ import getpass import json import requests requests.packages.urllib3.disable_warnings() import urllib.request, urllib.parse, urllib.error username=eval('input("Username: ")') password=getpass.getpass('Password: ') netmri="https://netmri.domain.com/api/3.0" debug="1" def api_query(path,rType): if debug == "1": print(("Sending "+netmri+path)) r=requests.get(netmri+path, verify=False, auth=(username, password)) if rType is "json": return r.json() elif rType is "text": print((r.text)) else: print("Return Type not defined\n") exit (1) def execute_job(devices): #runURL="/scripts/run?name=1_IOS Fixed Switch Upgrade&$use_http=on&$server=192.168.1.2&$new_image_name=c3560e-universalk9-mz.152-4.E6.bin&$new_image_size=26945536&$new_image_md5=4d485474740ec55fb7853ca866e5c0c4&$reload_now=on&$enable_changes=on&device_ids="+devices runURL="/scripts/run?name=Z_SetRealModel&device_ids="+devices api_query(runURL,"text") idList="2158417436111019091,5774691743709807187,695410963182700250,8196177485339937641" execute_job(idList)
09-14-2018 10:09 AM
I cheat - I put in a CLI command that will error out until I know my script is running and click the last run Job from the script and RERUN job
I use VS Code for my editor, and it has a great plug-in called REST Client to allow you to execute http commands from inside VS Code