Usage#

Let’s consider an example:

import os
from switch_TL_SG108PE.switch_manager import SwitchManager


# set required system variables before running script (example for Linux system)
# $ export ADMIN_IP=<switch ip>
# $ export ADMIN_USERNAME=<admin username>
# $ export ADMIN_PASSWORD=<admin password>

switch_manager = SwitchManager()
switch_manager.connect(os.environ['ADMIN_IP'],
                       os.environ['ADMIN_USERNAME'],
                       os.environ['ADMIN_PASSWORD'])
system = switch_manager.control('system')
info = system.system_info()
print(info)
switch_manager.disconnect()

As we can see in the example, the main package is switch_TL_SG108PE. It provides the SwitchManager() class that is a client for managing the switch via a website. The first step is to connect switch_manager to the switch using the connect() method. Then we select the section to manage. In our case it is the system section. The vlan object provides methods that allow us to perform selected actions on the switch. After carrying out the action on the switch, switch_manager should be disconnected.

Results:

$ python 01_get_system_information.py
{'Device Description': 'TL-SG108PE',
 'MAC Address': 'E4:C3:2A:BD:FF:F0',
 'IP Address': '192.168.1.42',
 'Subnet Mask': '255.255.255.0',
 'Default Gateway': '192.168.1.1',
 'Firmware Version': '1.0.0 Build 20200415 Rel.54962',
 'Hardware Version': 'TL-SG108PE 3.0'}

The above workflow is consistent with manually configuring the switch as shown in the image below:

basic usage

In a similar way, we can control sections:

  • system:
    • system_info() -> Dict[str, str]

    • set_device_description(description: str) -> None

    • ip_settings() -> Dict[str, str]

    • enable_dhcp_configuration() -> None

    • disable_dhcp_configuration() -> None

    • set_ip(ip_address: str, subnet_mask: str, default_gateway: str) -> None

    • led_on() -> None

    • led_off() -> None

    • user_account() -> Dict[str, str]

    • set_user_account_details(username: str, current_password: str, new_password: str, confirm_password: str) -> None

  • switching:
    • ports_settings() -> Dict[str, Dict[str, str]]

    • set_port_settings(port: int, status: STATUS, speed: SPEED, flow_control: FLOW_CONTROL) -> None

    • igmp_snooping() -> Dict[str, str]

    • enable_igmp_snooping() -> None

    • disable_igmp_snooping() -> None

    • enable_report_message_suppression() -> None

    • disable_report_message_suppression() -> None

    • lag_settings() -> Dict[str, str]

    • set_lag_ports(lag_id: int, ports: List[int]) -> None

    • unset_lag_ports(lag_id: int) -> None

  • monitoring:
    • port_statistics(refresh: bool = True) -> Dict[str, Dict[str, str]]

    • refresh_port_statistics() -> None

    • mirrored_ports() -> Dict[str, Dict[str, str]]

    • mirroring_port() -> Dict[str, str]

    • enable_port_mirroring(mirrored_ports: List[int], mirroring_port: int, ingress: bool = True, egress: bool = True) -> None

    • disable_port_mirroring() -> None

    • loop_prevention() -> Dict[str, str]

    • enable_loop_prevention() -> None

    • disable_loop_prevention() -> None

  • vlan:
    • mtu_vlan_configuration() -> Dict[str, str]

    • enable_mtu_vlan_configuration() -> None

    • disable_mtu_vlan_configuration() -> None

    • change_mtu_vlan_uplink_port(port: int) -> None

    • port_based_vlan_configuration() -> Dict[str, Union[List[str], str]]

    • enable_port_based_vlan_configuration() -> None

    • disable_port_based_vlan_configuration() -> None

    • add_port_based_vlan(vlan_id: int, ports: List[int]) -> None

    • remove_port_based_vlan(vlan_id: int) -> None

    • ieee_802_1q_vlan_configuration() -> Dict[str, str]

    • enable_ieee_802_1q_vlan_configuration() -> None

    • disable_ieee_802_1q_vlan_configuration() -> None

    • add_ieee_802_1q_vlan(vlan_id: int, ports: List[IEEE8021QPort], vlan_name: str = '') -> None

    • remove_ieee_802_1q_vlan(vlan_id: int) -> None

  • qos:
    • qos_mode(self) -> str

    • set_port_base_qos_mode(self) -> None

    • set_802_1p_based_qos_mode(self) -> None

    • set_dscp_802_1p_based_qos_mode(self) -> None

    • priority_queue_port_settings(self) -> Dict[str, str]

    • set_priority_queue_in_port_based_qos_mode(self, port: int, priority_queue: PriorityQueue) -> None