begins python examples exercising json api

This commit is contained in:
Jed Reynolds
2019-10-27 23:21:22 -07:00
parent 57d134d0a5
commit af606e9bb8
7 changed files with 84 additions and 0 deletions

View 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

View File

Binary file not shown.

Binary file not shown.

20
py-json/TODO.txt Normal file
View 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
View File

@@ -0,0 +1,2 @@
from .LFRequest import LFRequest

26
py-json/show_ports.py Normal file
View 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()
#