Reply

Python helper script- An easy way launch jobs while testing code.

Guru
Posts: 61
4772     0

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)

 

Highlighted

Re: Python helper script- An easy way launch jobs while testing code.

Adviser
Posts: 410
4772     0

I cheat Smiley Happy - 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 Smiley Happy

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Showing results for 
Search instead for 
Do you mean 

Recommended for You