# # ZTP Day0 Python Script for Cisco IOS-XE # # Importing the correct cli module for IOS-XE import cli print("\n*** Sample ZTP Day0 Python Script for IOS-XE ***\n") # Use the correct syntax for cli.configurep, passing a list of strings try: print("Configuring hostname, interfaces, and user accounts...") cli.configurep(["hostname myrouter1"]) cli.configurep(["interface vlan 1", "ip address 10.5.123.27 255.255.255.0", "no shutdown"]) cli.configurep(["username admin privilege 15 secret 0 MyPassword!"]) cli.configurep(["enable secret 0 MyPassword!"]) cli.configurep(["aaa new-model", "aaa authentication login default local", "end"]) cli.configurep(["aaa authorization exec default local", "aaa session-id common", "end"]) cli.configurep(["netconf-yang", "end"]) 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("Writing memory...") # 'write mem' is a privileged EXEC command cli.executep("write mem") print("Configuration applied and save successfully.\n") print("\n\n*** Executing show ip interface brief ***\n\n") # cli.executep returns the output as a string, which can be printed output = cli.executep("sh ip int brief") print(output) print("\n\n*** ZTP Day0 Python Script Execution Complete. Rebooting in 10 seconds. ***\n\n") time.sleep(10) # Wait 10 seconds before rebooting # 'reload' is a privileged EXEC command and will exit the script cli.executep("reload") except Exception as e: print(f"Error during ZTP script execution: {e}") print("\n\n*** ZTP Day0 Python Script Execution Complete ***\n\n")