Skip to main content

Execute API calls to Omada Controller from python code

Project description

omada-client

PyPI Version

Python client for Tp-Link Omada Controller (Omada Software Controller). Execute API calls to Omada Controller from python code.

Installation

pip install omada-client

Examples

Create class

from omada_client import OmadaClient
omada = OmadaClient( "OMADA_DOMAIN", "OMADA_USER", "OMADA_PASSWORD" )

where:

  • OMADA_DOMAIN: URL of Omada WebUi page
  • OMADA_USER: Username of Omada WebUi
  • OMADA_PASSWORD: Password of Omada WebUi

or using environment variables "OMADA_DOMAIN" and "OMADA_USER" and "OMADA_PASSWORD":

from dotenv import load_dotenv
import os
from omada_client import OmadaClient
load_dotenv()

def main():
    omadaClient = OmadaClient( 
        os.getenv("OMADA_DOMAIN"), 
        os.getenv("OMADA_USER"), 
        os.getenv("OMADA_PASSWORD")
    )

    print( omadaClient.get_devices() )
if __name__ == "__main__":
    main() 

Methods

# Get a list of WAN ports
omadaClient.get_all_wan_ports()
# Get WAN port by its name
omadaClient.get_wan_ports_by_name("WAN/LAN1")
# Get WAN port by its name
omadaClient.get_wan_ports_by_desc("domru")
# Create a static route
omadaClient.create_static_route(
    route_name="test",
    destinations=["8.8.8.8/24", "1.1.1.1/24"],
    interface_id=omadaClient.get_wan_ports_by_desc("openwrt").port_uuid,
    next_hop_ip="192.168.1.1",
    enable=False
)
# Get list of devices
omadaClient.get_devices()
# Get a client by their MAC address
omadaClient.get_client_by_mac("ff:ff:ff:ff:ff:ff")
# Get all clients
omadaClient.get_clients()
# Get a client by its IP address
omadaClient.get_client_by_ip("10.0.0.100")
# Assign a fixed IP address to the client based on its MAC address
omadaClient.set_client_fixed_address_by_mac("ff:ff:ff:ff:ff:ff", "10.0.0.100")
# Assign a fixed IP address to the client based on its IP address
omadaClient.set_client_fixed_address_by_ip("10.0.0.100")
# Assign a dynamic IP address to the client
omadaClient.set_client_dymanic_address_by_mac("ff:ff:ff:ff:ff:ff")

Advanced methods

Create a static route from a large amount of data

from dotenv import load_dotenv
import os
from omada_client import OmadaClient
load_dotenv()

def main():
    omadaClient = OmadaClient( 
        os.getenv("OMADA_DOMAIN"), 
        os.getenv("OMADA_USER"), 
        os.getenv("OMADA_PASSWORD")
    )

    data = [
        {
            "name" : "group_1",
            "ips" : "99.99.99.99/24, 88.88.88.88/24"
        },
        {
            "name" : "group_2",
            "ips" : "99.99.99.99/24, 88.88.88.88/24"
        }
    ]
    wan = omadaClient.get_wan_ports_by_desc("openwrt")
    omadaClient.create_static_route_to_inteface_with_big_data(
        data_static_routes=data,
        interface_id=wan.port_uuid,
        next_hop_ip=wan.wan_port_ipv4_setting.get("ipv4Static").get("gateway"),
        enable=False
    )
if __name__ == "__main__":
    main() 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omada_client-1.2.1.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file omada_client-1.2.1.tar.gz.

File metadata

  • Download URL: omada_client-1.2.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for omada_client-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6e4912f19ae72730ead1f6ce785cae0b62d465ec0e987c8ef77be06c023a1f56
MD5 7015f0ba82f5c06a2ff25f5a1d7fc56c
BLAKE2b-256 f79a5aa78f0954c9b532e27f7cf41027c2d6fde0cbe79ccdcf85ea89b8ccbf5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page