import requests
import urllib3
import pprint
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
ip_addr = "192.168.50.29"
creds = {"userName": "admin", "password": "admin123"}
login = requests.post(
"http://{}/rest/v4/login-sessions".format(ip_addr),
json=creds,
verify=False,
timeout=10,
)
cookie = {"cookie": login.json()["cookie"]}
if login.status_code == 201:
print("Login OK to ArubaOS-Switch")
else:
print("Login error to ArubaOS-Switch IP: {}".format(login.status_code))
# turn_on_poe = requests.put(
# "http://{}/rest/v4/ports/10/poe".format(ip_addr),
# json = {'is_poe_enabled': True},
# headers=cookie,
# verify=False,
# timeout=10,
# )
turn_off_poe = requests.put(
"http://{}/rest/v4/ports/10/poe".format(ip_addr),
json={"is_poe_enabled": False},
headers=cookie,
verify=False,
timeout=10,
)
poe = requests.get(
"http://{}/rest/v4/poe/ports".format(ip_addr),
headers=cookie,
verify=False,
timeout=10,
)
single_port = requests.get(
"http://{}/rest/v4/ports/10/poe".format(ip_addr),
headers=cookie,
verify=False,
timeout=10,
)
pprint.pprint(single_port.json())
logout = requests.delete(
"http://{}/rest/v4/login-sessions".format(ip_addr),
headers=cookie,
verify=False,
timeout=10,
)
print(logout.status_code)