Untitled

 avatar
unknown
python
9 hours ago
1.6 kB
11
No Index
import requests
from requests.auth import HTTPBasicAuth
import urllib3

# Disable SSL warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# Config
base_url = "https://[SWITCH IP]/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet"
username = "admin"
password = "password"

headers = {
    "Content-Type": "application/yang-data+json"
}

# Loop through interfaces GigabitEthernet1/0/17 to GigabitEthernet1/0/22
for i in range(5, 15):

    payload_without_template = {
        "Cisco-IOS-XE-native:GigabitEthernet": {
            "name": f"1/0/{i}",
            "description": "TEST"
        }
    }

    payload_with_template = {
        "Cisco-IOS-XE-native:GigabitEthernet": {
            "name": f"1/0/{i}",
            "description": "TEST",
            "source": {
                "template": {
                    "template-name": [
                        {"template-name": "TEMPLATE_TEST"}
                    ]
                }
            }
        }
    }

    # Send PATCH request

    # WITH TEMPLATE
    response = requests.patch(base_url, json=payload_with_template, headers=headers, auth=HTTPBasicAuth(username, password), verify=False)

    # WITHOUT TEMPLATE
    # response = requests.patch(base_url, json=payload_without_template, headers=headers, auth=HTTPBasicAuth(username, password), verify=False)

    # Print response for each interface
    print(f"Interface GigabitEthernet1/0/{i}")
    print("Status Code:", response.status_code)
    print("Response Body:", response.text)
    print("-" * 50)
Editor is loading...
Leave a Comment