# # ZTP Day0 Python Script for Cisco IOS-XE # #!/usr/bin/env python # ZTP Day0 for IOS XE C8000v — applies provided running-config, saves, verifies, reloads import cli import time def push_config_lines(lines, chunk=90, pause=0.2): """Send config in batches to avoid parser/VTY limits.""" for i in range(0, len(lines), chunk): cli.configure(lines[i:i+chunk]) time.sleep(pause) print("\n*** Applying Day0 Configuration ***\n") CFG = [ # ----- Global / platform ----- # ----- VRFs ----- # ----- AAA per your config ----- "no aaa new-model", # ----- DNS / domain ----- "ip name-server vrf mgmt 1.1.1.1 8.8.8.8", "ip domain name example.com", # ----- Logging/telemetry basics ----- # ----- Trustpoints (cert bodies omitted by design; ask to include) ----- # ----- Licensing / UDI ----- # ----- Local creds ----- "enable secret 0 MyPassword!", "username admin privilege 15 secret 0 MyPassword! # ----- Interfaces ----- "interface Loopback0", " no ip address", " shutdown", "exit", "interface Loopback1234", " no ip address", " shutdown", "exit", "interface GigabitEthernet1", " vrf forwarding vrf1", "exit", "interface GigabitEthernet2", " no ip address", " negotiation auto", "exit", "interface GigabitEthernet3", " vrf forwarding mgmt", " ip address 192.168.1.164 255.255.255.0", " negotiation auto", "exit", # ----- HTTP/SSH/Routes ----- # ----- Prefix-lists / route-maps ----- # ----- Control-plane placeholder ----- # ----- MGCP defaults ----- # ----- Aliases ----- # ----- Lines / access ----- "line con 0", " activation-character 13", " stopbits 1", "exit", "line aux 0", " activation-character 13", "exit", "line vty 0 4", " activation-character 13", " login local", " transport input ssh", "exit", "line vty 5 97", " activation-character 13", " login", " transport input ssh", "exit", # ----- NTP ----- "ntp peer vrf mgmt 192.168.1.155", # ----- NETCONF + Guestshell + Telemetry ----- "netconf-yang", "app-hosting appid guestshell", " app-vnic management guest-interface 0", "exit", "telemetry ietf subscription 1", " encoding encode-kvgpb", " filter xpath /memory-ios-xe-oper:memory-statistics/memory-statistic", " stream yang-push", " update-policy periodic 6000", " receiver ip address 192.168.2.111 10004 protocol grpc-tcp", "exit", ] try: push_config_lines(CFG) print("Setting license boot level...") # The license boot command is a configuration command cli.configurep(["license boot level network-advantage addon dna-advantage"]) print("License boot level configured. Writing memory to save.") print("\nWriting memory...") cli.execute("write memory") print("Configuration applied and save successfully.\n") # quick checks print("\n*** Quick checks ***\n") for cmd in [ "show vrf", "show ip interface brief", ]: print(f"\n> {cmd}") try: print(cli.execute(cmd)) except Exception as e: print(f"[exec error] {cmd}: {e}") print("\n*** Rebooting in 10 seconds... ***\n") time.sleep(10) cli.execute("reload") except Exception as e: print(f"Error during ZTP script execution: {e}") print("\n*** ZTP Day0 Python Script Execution Complete ***\n")