From 7c6ab1be6f893b5591059cca4d39258d75c52b14 Mon Sep 17 00:00:00 2001 From: Logan Lipke Date: Fri, 10 Apr 2020 11:03:51 -0700 Subject: [PATCH] Added module to more easily create generic endpoints, and set their flags/cmds --- py-json/create_genlink.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 py-json/create_genlink.py diff --git a/py-json/create_genlink.py b/py-json/create_genlink.py new file mode 100755 index 00000000..59177b44 --- /dev/null +++ b/py-json/create_genlink.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +import os +import time +import sys +import json +import pprint +from LANforge import LFRequest +from LANforge import LFUtils + +if sys.version_info[0] != 3: + print("This script requires Python 3") + exit() + + +def jsonReq(mgrURL,reqURL,postData,debug=False): + lf_r = LFRequest.LFRequest(mgrURL + reqURL) + lf_r.addPostData(postData) + + if debug: + json_response = lf_r.jsonPost(True) + LFUtils.debug_printer.pprint(json_response) + sys.exit(1) + else: + lf_r.jsonPost() + +def createGenEndp(alias, shelf, rsrc, port, type): + mgrURL = "http://localhost:8080/" + reqURL = "cli-json/add_gen_endp" + data = { + "alias":alias, + "shelf":shelf, + "resource":rsrc, + "port":port, + "type":type + } + jsonReq(mgrURL,reqURL,data) + +def setFlags(endpName, flagName,val): + mgrURL = "http://localhost:8080/" + reqURL = "cli-json/set_endp_flag" + data = { + "name":endpName, + "flag":flagName, + "val":val + } + jsonReq(mgrURL,reqURL,data) + +def setCmd(endpName,cmd): + mgrURL = "http://localhost:8080/" + reqURL = "cli-json/set_gen_cmd" + data = { + "name":endpName, + "command":cmd + } + jsonReq(mgrURL,reqURL,data) +