Python program to configure a SD-WAN configuration:
import requests
import json # Define SD-WAN controller credentials controller_ip = '192.168.1.1' username = 'admin' password = 'password' # Define the SD-WAN template for configuration template = { "name": "WAN Configuration", "description": "SD-WAN WAN Configuration", "deviceType": "vedge-1000", "devices": [ { "deviceId": "vedge001", "parameters": [ { "key": "vpn0-interface-type", "value": "private" }, { "key": "vpn0-interface-ip", "value": "192.168.100.1/24" }, { "key": "vpn0-interface-gateway", "value": "192.168.100.254" }, { "key": "vpn512-interface-type", "value": "public" }, { "key": "vpn512-interface-ip", "value": "203.0.113.1/24" }, { "key": "vpn512-interface-gateway", "value": "203.0.113.254" } ] } ] } # Authenticate with the SD-WAN controller auth_url = f"https://{controller_ip}/j_security_check" auth_payload = { 'j_username': username, 'j_password': password } auth_response = requests.post(auth_url, data=auth_payload, verify=False) auth_response.raise_for_status() cookies = auth_response.cookies # Create the SD-WAN template config_url = f"https://{controller_ip}/dataservice/template/device/config/attachfeature" create_response = requests.post(config_url, json=template, cookies=cookies, verify=False) create_response.raise_for_status() # Check if the template deployment was successful task_id = create_response.json()['id'] status_url = f"https://{controller_ip}/dataservice/template/device/config/{task_id}" status_response = requests.get(status_url, cookies=cookies, verify=False) if status_response.json()['status'] == "scheduled": print("Template deployment successful.") else: print("Template deployment failed.") # Logout from the SD-WAN controller logout_url = f"https://{controller_ip}/j_security_logout" requests.get(logout_url, cookies=cookies, verify=False)
Comments
Post a Comment