mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-29 09:52:35 +00:00
begins python examples exercising json api
This commit is contained in:
36
py-json/LANforge/LFRequest.py
Normal file
36
py-json/LANforge/LFRequest.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Class holds default settings for json requests -
|
||||
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] != 3:
|
||||
print("This script requires Python 3")
|
||||
exit()
|
||||
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
class LFRequest:
|
||||
Default_Base_URL = "http://localhost:8080"
|
||||
requested_urls = []
|
||||
default_headers = {
|
||||
'Accept': 'application/json' }
|
||||
|
||||
|
||||
def __init__(self, urls):
|
||||
self.requested_urls.append(urls)
|
||||
|
||||
# request first url on stack
|
||||
def get(self):
|
||||
myrequest = urllib.request.Request(url=self.requested_urls.pop(0), headers=self.default_headers)
|
||||
myresponse = urllib.request.urlopen(myrequest)
|
||||
|
||||
#print(json_response)
|
||||
return myresponse
|
||||
|
||||
def getAsJson(self):
|
||||
response = self.get();
|
||||
json_data = json.loads(response.read())
|
||||
return json_data
|
||||
|
||||
# ~LFRequest
|
||||
0
py-json/LANforge/__init__.py
Normal file
0
py-json/LANforge/__init__.py
Normal file
BIN
py-json/LANforge/__pycache__/LFRequest.cpython-36.pyc
Normal file
BIN
py-json/LANforge/__pycache__/LFRequest.cpython-36.pyc
Normal file
Binary file not shown.
BIN
py-json/LANforge/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
py-json/LANforge/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
20
py-json/TODO.txt
Normal file
20
py-json/TODO.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
Able to select ports
|
||||
|
||||
Create client groups / single client:
|
||||
Should be able to control MAC address,
|
||||
client type(b/g/n/, ac),
|
||||
encryption (WPA2, WPA3),
|
||||
auth -( open, 802.1x , WebAuth, WISPR)
|
||||
Tx power etc
|
||||
|
||||
Able to control below failures with predetermined failure rate
|
||||
|
||||
eg:
|
||||
|
||||
Generate auth failure
|
||||
Generate assoc failure
|
||||
Generate EAP failure
|
||||
Generate WIPSR/WebAuth failure
|
||||
Generate Radius failure
|
||||
Generate DHCP failure
|
||||
|
||||
2
py-json/__init__.py
Normal file
2
py-json/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .LFRequest import LFRequest
|
||||
|
||||
26
py-json/show_ports.py
Normal file
26
py-json/show_ports.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# example of how to check a LANforge json url -
|
||||
# -
|
||||
# the syntax of the request is /port/<shelf=1>/<resource=1>/<list|all|portid> -
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
import sys
|
||||
if sys.version_info[0] != 3:
|
||||
print("This script requires Python 3")
|
||||
exit()
|
||||
|
||||
import json
|
||||
from LANforge import LFRequest
|
||||
|
||||
|
||||
def main():
|
||||
url = "http://localhost:8080/port/1/1/list"
|
||||
timeout = 5 # seconds
|
||||
|
||||
lf_r = LFRequest.LFRequest(url)
|
||||
json_response = lf_r.getAsJson()
|
||||
print(json_response)
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
#
|
||||
Reference in New Issue
Block a user