Skip to content

Commit

Permalink
Merge pull request #5 from MarkGodwin/feature/ap_ports
Browse files Browse the repository at this point in the history
Feature/ap ports
  • Loading branch information
MarkGodwin authored Mar 5, 2023
2 parents 6a412a0 + cd073dd commit 8b27796
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 186 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",

"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Only a subset of the controller's features are supported:
* Within site:
* List Devices (APs, Gateways and Switches)
* Basic device information
* Port status and PoE configuraton for Switches (<-- What I actually needed)
* Port status and PoE configuraton for Switches
* Lan port configuration for Access Points

Tested with OC200 on Omada Controller Version 5.5.7 - 5.7.6. Other versions may not be fully compatible.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tplink_omada_client"
version = "1.1.0"
version = "1.1.1"
authors = [
{ name="Mark Godwin", email="author@example.com" },
]
Expand Down
37 changes: 29 additions & 8 deletions sample_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import sys
from pprint import pprint
from src.tplink_omada_client.omadaclient import OmadaClient
from src.tplink_omada_client.omadasiteclient import AccessPointPortSettings


async def do_the_magic(url: str, username: str, password: str):
""" Not a real test client. """
"""Not a real test client."""

async with OmadaClient(url, username, password) as client:
async with OmadaClient(url, username, password, verify_ssl=False) as client:

print(f"Found Omada Controller: {await client.get_controller_name()}")

Expand All @@ -27,30 +29,49 @@ async def do_the_magic(url: str, username: str, password: str):
print(f" {len([d for d in devices if d.type == 'switch'])} Switches.")
print(f" {len([d for d in devices if d.type == 'gateway'])} Routers.")

#pprint(vars(devices[0]))
aps = [
await site_client.get_access_point(a) for a in devices if a.type == "ap"
]
for a in aps:
print(f"Access Point: {a.name}")
if a.name == "Office":
port_status = await site_client.update_access_point_port(
a, "ETH3", AccessPointPortSettings(enable_poe=True)
)
pprint(vars(port_status))
port_status = await site_client.update_access_point_port(
a, "ETH3", AccessPointPortSettings(enable_poe=False)
)
pprint(vars(port_status))

# pprint(vars(devices[0]))

# Get full info of all switches
switches = [await site_client.get_switch(s) for s in devices if s.type == "switch"]
switches = [
await site_client.get_switch(s) for s in devices if s.type == "switch"
]

#pprint(vars(switches[0]))
# pprint(vars(switches[0]))

#ports = await client.get_switch_ports(switches[0])
# ports = await client.get_switch_ports(switches[0])

port = await site_client.get_switch_port(switches[0], switches[0].ports[4])
print(f"Port index 4: {port.name} Profile: {port.profile_name}")
pprint(vars(port))

updated_port = await site_client.update_switch_port(
switches[0], port, new_name="Port5")
switches[0], port, new_name="Port5"
)
pprint(vars(updated_port))

profiles = await site_client.get_port_profiles()
pprint(vars(profiles[0]))

print("Done.")


def main():
""" Basic sample test client. """
"""Basic sample test client."""
if len(sys.argv) < 2 or len(sys.argv) > 4:
print("Usage: client <omada url> [username] [password]")
return
Expand Down
38 changes: 28 additions & 10 deletions src/tplink_omada_client/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from enum import IntEnum


class DeviceStatus(IntEnum):
""" Known status codes for devices. """
"""Known status codes for devices."""

DISCONNECTED = 0
DISCONNECTED_MIGRATING = 1
PROVISIONING = 10
PROVISIONING = 10
CONFIGURING = 11
UPGRADING = 12
REBOOTING = 13
Expand All @@ -29,53 +31,69 @@ class DeviceStatus(IntEnum):
ISOLATED = 40
ISOLATED_MIGRATING = 41


class DeviceStatusCategory(IntEnum):
""" Known status categories for devices """
"""Known status categories for devices"""

DISCONNECTED = 0
CONNECTED = 1
PENDING = 2
HEARTBEAT_MISSED = 3
ISOLATED = 4


class PortType(IntEnum):
""" Known types of switch port. """
"""Known types of switch port."""

COPPER = 1
COMBO = 2
SFP = 3


class LinkStatus(IntEnum):
""" Known link statuses. """
"""Known link statuses."""

LINK_UP = 0
LINK_DOWN = 2


class LinkSpeed(IntEnum):
""" Known link speeds. """
"""Known link speeds."""

SPEED_AUTO = 0
SPEED_10_MBPS = 1
SPEED_100_MBPS = 2
SPEED_1_GBPS = 3
SPEED_10_GBPS = 4


class LinkDuplex(IntEnum):
""" Known link duplex modes """
"""Known link duplex modes"""

AUTO = 0
HALF = 1
FULL = 2


class Eth802Dot1X(IntEnum):
""" 802.1x auth modes. """
"""802.1x auth modes."""

FORCE_UNAUTHORIZED = 0
FORCE_AUTHORIZED = 1
AUTO = 2


class BandwidthControl(IntEnum):
""" Modes of bandwidth control. """
"""Modes of bandwidth control."""

OFF = 0
RATE_LIMIT = 1
STORM_CONTROL = 2


class PoEMode(IntEnum):
""" Settings for PoE policy. """
"""Settings for PoE policy."""

DISABLED = 0
ENABLED = 1
USE_DEVICE_SETTINGS = 2
Loading

0 comments on commit 8b27796

Please sign in to comment.