Python library for integrating Ansible with the Comware7 embedded system, enabling automation of inventory and device orchestration.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpip install pycw7-ansibleTo open a connection, you need to create a dictionary with the device parameters and pass it to the COM7 class, then call the open method, as shown below:
>>> from pycw7_ansible.comware import COM7
>>> HOST_IP = "10.100.73.119"
>>> USERNAME = "ped"
>>> PASSWORD = "Admin@1234"
>>> PORT = 830
>>> args = dict(host=HOST_IP, username=USERNAME, password=PASSWORD, port=PORT)
>>> device = COM7(**args)
>>> device.open()
<ncclient.manager.Manager object at 0x7c5536f51d60>To get run a command, you need to call the cli_display or cli_config method, as shown below:
>>> command = device.cli_config("vlan 1 \n name VLAN 0001 \n description VLAN-1-MANAGEMENT")
>>> print(command)
{'vlanid': '1', 'name': 'VLAN 0001', 'descr': 'VLAN-1-MANAGEMENT'}
>>> command = device.cli_display("display vlan 1")
>>> print(command)
{'vlanid': '1', 'name': 'VLAN 0001', 'descr': 'VLAN-1-MANAGEMENT'}To get the configuration of a feature, you need to create an instance of the feature class and call the get_config method, as shown below:
>>> from pycw7_ansible.features.vlan import Vlan
>>> vlan1 = Vlan(device, "1")
>>> config = vlan1.get_config()
>>> print(config)
{'vlanid': '1', 'name': 'VLAN 0001', 'descr': 'VLAN-1-MANAGEMENT'}