Files
wlan-lanforge-scripts/py-json/show_ports.py
erinnerim 1d7578251c Updates to import statements:
- Import importlib, os, and sys to each python script.
 - Append "lanforge-scripts" root directory to the system path, allowing each script to be called from an antecedent directory. e.g.
if 'lanforge-scripts' not in sys.path:
    sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../../")))
 - All statements of the form 'from <module> import <class>' replace with:
<module> = importlib.import_module("lanforge-scripts.<directory>.<module>")
<class> = <module>.<class>
2021-09-15 16:17:16 -07:00

38 lines
1.2 KiB
Python

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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
import os
import importlib
import json
import pprint
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit()
if 'lanforge-scripts' not in sys.path:
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../")))
LFRequest = importlib.import_module("lanforge-scripts.py-json.LANforge.LFRequest")
def main():
url = "http://localhost:8080/port/1/1/list"
timeout = 5 # seconds
lf_r = LFRequest.LFRequest(url)
json_response = lf_r.getAsJson(True)
j_printer = pprint.PrettyPrinter(indent=2)
j_printer.pprint(json_response)
#for record in json_response['interfaces']:
#j_printer.pprint(record)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if __name__ == "__main__":
main()
#