Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update poe.py #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pyarubaoss/poe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,26 @@ def get_poe_ports(auth):
poe_ports = json.loads(r.text)['port_poe']
return poe_ports
except requests.exceptions.RequestException as error:
return "Error:\n" + str(error) + " get_poe_ports: An Error has occured"
return "Error:\n" + str(error) + " get_poe_ports: An Error has occured"

def toggle_poe_port(auth, poeOn, myport):
"""
Function to enable/disable poe ports on Aruba OS switch
:param auth: AOSSAuth class object returned by pyarubaoss.auth
:param poeOn: Boolean desired state of port True = PoE Enabled
:param myport: port being modified
:return port status
:rtype string
"""
url = "http://" + auth.ipaddr + "/rest/" + auth.version + "/ports/" + myport + "/poe"
poeOn = 'true' if poeOn else 'false'
payload = "{\"is_poe_enabled\": " + poeOn + "}"

try:
r = requests.request("PUT", url, data=payload, headers=auth.cookie)
poe_status = json.loads(r.text)['is_poe_enabled']
r_status = "enabled" if poe_status else "disabled"
return "PoE is " + r_status + " on port " + myport
except requests.exceptions.RequestException as error:
return "Error:\n" + str(error) + " toggle_poe_ports: An Error has occured"