From 79447e967db309ae9f4d0b26005884a760d6b3cf Mon Sep 17 00:00:00 2001 From: Logan Lipke Date: Wed, 27 May 2020 14:17:14 -0700 Subject: [PATCH] Added info grabbing for ports --- Realm.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/Realm.py b/Realm.py index 7f4004cf..67ccd945 100755 --- a/Realm.py +++ b/Realm.py @@ -7,7 +7,7 @@ import json import pprint from LANforge import LFRequest from LANforge import LFUtils - +import re def jsonPost(mgrURL, reqURL, data, debug=False): lf_r = LFRequest.LFRequest(mgrURL + reqURL) @@ -15,11 +15,6 @@ def jsonPost(mgrURL, reqURL, data, debug=False): json_response = lf_r.jsonPost(debug) LFUtils.debug_printer.pprint(json_response) sys.exit(1) - -def getJsonReq(mgrURL, reqURL): - lf_r = LFRequest.LFRequest(mgrURL + reqURL) - json_response = lf_r.getAsJson(debugOn) - return json_response class Realm: @@ -28,18 +23,68 @@ class Realm: self.mgrURL = mgrURL def cxList(self): - print("Not yet Implemented") + #Returns json response from webpage of all layer 3 cross connects + lf_r = LFRequest.LFRequest(self.mgrURL + "/cx") + response = lf_r.getAsJson(True) + return response def stationList(self): + #Returns list of all stations with "sta" in their name + list = [] lf_r = LFRequest.LFRequest(self.mgrURL + "/port/list?fields=_links,alias") - response = lf_r.getAsJson(False) - print(response) + response = lf_r.getAsJson(True) + + for x in range(len(response['interfaces'])): + for k,v in response['interfaces'][x].items(): + if "sta" in v['alias']: + list.append(response['interfaces'][x]) + + return list def vapList(self): - print("Not yet Implemented") + #Returns list of all VAPs with "vap" in their name + list = [] + lf_r = LFRequest.LFRequest(self.mgrURL + "/port/list?fields=_links,alias") + response = lf_r.getAsJson(True) + + for x in range(len(response['interfaces'])): + for k,v in response['interfaces'][x].items(): + if "vap" in v['alias']: + list.append(response['interfaces'][x]) + + return list + def findPortsLike(self, pattern=""): - print("Not yet Implemented") + #Searches for ports that match a given pattern and returns a list of names + list = [] + lf_r = LFRequest.LFRequest(self.mgrURL + "/port/list?fields=_links,alias") + response = lf_r.getAsJson(True) + for x in range(len(response['interfaces'])): + for k,v in response['interfaces'][x].items(): + if v['alias'] != "NA": + list.append(v['alias']) + + matchedList = [] + + for name in list: + if (pattern.index("+") > 0): + match1 = re.search(r"^[^+]+[+]$", name) + if match1: + print(match1) + matchedList.append(name) + elif (pattern.index("*") > 0): + match2 = re.search(r"^[^\*]+[\*]$", name) + if match2: + print(match2) + matchedList.append(name) + if (pattern.index("[") > 0): + match3 = re.search(r"^[\[]+\[\d+\.\.\d+\]$", name) + if match3: + print(match3) + matchedList.append(name) + + return matchedList class CxProfile: @@ -60,4 +105,4 @@ class StationProfile: self.dhcp = dhcp def build(self, resourceRadio, numStations): - print("Not yet Implemented") + print("Not yet implemented")