mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-03 20:27:54 +00:00 
			
		
		
		
	Added info grabbing for ports
This commit is contained in:
		
							
								
								
									
										69
									
								
								Realm.py
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								Realm.py
									
									
									
									
									
								
							@@ -7,7 +7,7 @@ import json
 | 
				
			|||||||
import pprint
 | 
					import pprint
 | 
				
			||||||
from LANforge import LFRequest
 | 
					from LANforge import LFRequest
 | 
				
			||||||
from LANforge import LFUtils
 | 
					from LANforge import LFUtils
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def jsonPost(mgrURL, reqURL, data, debug=False):
 | 
					def jsonPost(mgrURL, reqURL, data, debug=False):
 | 
				
			||||||
   lf_r = LFRequest.LFRequest(mgrURL + reqURL)
 | 
					   lf_r = LFRequest.LFRequest(mgrURL + reqURL)
 | 
				
			||||||
@@ -16,11 +16,6 @@ def jsonPost(mgrURL, reqURL, data, debug=False):
 | 
				
			|||||||
   LFUtils.debug_printer.pprint(json_response)
 | 
					   LFUtils.debug_printer.pprint(json_response)
 | 
				
			||||||
   sys.exit(1)
 | 
					   sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def getJsonReq(mgrURL, reqURL):
 | 
					 | 
				
			||||||
   lf_r = LFRequest.LFRequest(mgrURL + reqURL)
 | 
					 | 
				
			||||||
   json_response = lf_r.getAsJson(debugOn)
 | 
					 | 
				
			||||||
   return json_response
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Realm:
 | 
					class Realm:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -28,18 +23,68 @@ class Realm:
 | 
				
			|||||||
      self.mgrURL = mgrURL
 | 
					      self.mgrURL = mgrURL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def cxList(self):
 | 
					   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):
 | 
					   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")
 | 
					      lf_r = LFRequest.LFRequest(self.mgrURL + "/port/list?fields=_links,alias")
 | 
				
			||||||
      response = lf_r.getAsJson(False)
 | 
					      response = lf_r.getAsJson(True)
 | 
				
			||||||
      print(response)
 | 
					
 | 
				
			||||||
 | 
					      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):
 | 
					   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=""):
 | 
					   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:
 | 
					class CxProfile:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -60,4 +105,4 @@ class StationProfile:
 | 
				
			|||||||
		self.dhcp = dhcp
 | 
							self.dhcp = dhcp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def build(self, resourceRadio, numStations):
 | 
						def build(self, resourceRadio, numStations):
 | 
				
			||||||
	   print("Not yet Implemented")      
 | 
						   print("Not yet implemented") 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user