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.0.tar.gz (6.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: omada_client-1.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 86b4dfc824e88bff7eceb5156828276f33bb486e2daf1ea22a4de0c1ca33bb32
MD5 93dba291ee33d9f5d189c90516dd1eb0
BLAKE2b-256 4fedf9ebc15962801c97c2500b1205904b0c5e306c150f8b07824fef36faed6d

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