



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A python script that automates network configuration management using netconf. It demonstrates how to establish a netconf connection, retrieve the current running configuration, modify the configuration (e.g., change an interface description), verify the changes, and notify webex teams about the updates. The script uses the ncclient and requests libraries.
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




task 1:
def establish_netconf_connection(ip, port, username, password): return manager.connect(host=ip, port=port, username=username, password=password, device_params={'name':'default'}, hostkey_verify=False)
def retrieve_running_configuration(netconf_manager): return netconf_manager.get_config(source='running')
def main():
with establish_netconf_connection(DEVICE_IP_ADDRESS, NETCONF_PORT_NUMBER, NETCONF_USERNAME, NETCONF_PASSWORD) as netconf_manager:
current_configuration = retrieve_running_configuration(netconf_manager) print(xml.dom.minidom.parseString(current_configuration.xml).toprettyxml()) if name == "main": main() task 2:
def apply_configuration_change(netconf_manager, new_configuration): netconf_manager.edit_config(target='running', config=new_configuration)
def main():
with establish_netconf_connection(DEVICE_IP_ADDRESS, NETCONF_PORT_NUMBER, NETCONF_USERNAME, NETCONF_PASSWORD) as netconf_manager:
modified_configuration = """
GigabitEthernet1 New Description
"""
apply_configuration_change(netconf_manager, modified_configuration) if name == "main": main() task 3:
def main():
if name == "main": main() *******************************************’ pip install ncclient requests from ncclient import manager import xml.dom.minidom import requests
DEVICE_IP_ADDRESS = '192.168.233.129' NETCONF_PORT_NUMBER = '830' NETCONF_USERNAME = 'admin' NETCONF_PASSWORD = 'admin'
def establish_netconf_connection(ip, port, username, password): return manager.connect(host=ip, port=port, username=username, password=password, device_params={'name':'default'}, hostkey_verify=False)
def retrieve_running_configuration(netconf_manager): return netconf_manager.get_config(source='running')
def apply_configuration_change(netconf_manager, new_configuration): netconf_manager.edit_config(target='running', config=new_configuration)
def send_webex_notification(message, teams_token, teams_room_id): url = f"https://webexapis.com/v1/messages" headers = { "Authorization": f"Bearer {teams_token}", "Content-Type": "application/json" } data = { "roomId": teams_room_id, "text": message } requests.post(url, headers=headers, json=data)
def main(): with establish_netconf_connection(DEVICE_IP_ADDRESS, NETCONF_PORT_NUMBER, NETCONF_USERNAME, NETCONF_PASSWORD) as netconf_manager:
current_configuration = retrieve_running_configuration(netconf_manager) print(xml.dom.minidom.parseString(current_configuration.xml).toprettyxml())