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

Posts: 61
4867     1

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
import urllib.request, urllib.parse, urllib.error

username=eval('input("Username: ")')
password=getpass.getpass('Password: ')

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("Return Type not defined\n")
        exit (1)

def execute_job(devices):
    #runURL="/scripts/run?name=1_IOS Fixed Switch Upgrade&$use_http=on&$server=$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



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

Posts: 414
4868     1

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:

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

Posts: 3
4868     1

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


The code below will run job id of 183 against 1 device (device_id 7107)

# @name IPSLA_run
POST https://{{netmri}}/api/3.3/scripts/run HTTP/1.1
Authorization: Basic XXXXXX
Content-Type: application/json

    "id" : 183,
    "device_ids" : [ 7107 ]

Showing results for 
Search instead for 
Do you mean 

Recommended for You