cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
780
Views
1
Helpful
1
Replies

Python script to run 'application configuration ise' against DevNet

PatrickWelby0086
Frequent Visitor
Frequent Visitor

All,

I am trying to pull the configuration from the ISE DevNet Always On sandbox - https://devnetsandboxise.cisco.com - using the python script pasted below and I get the following error:  

 

 

PatrickWelby0086_0-1755634553219.png

import paramiko
import time
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox
import logging
from datetime import datetime

# Configure logging to file
log_filename = f"ise_config_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
logging.basicConfig(
    filename=log_filename,
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(message)s"
)

# Saved profiles
PROFILES = {
    "Cisco DevNet Sandbox": {
        "host": "https://devnetsandboxise.cisco.com",
        "username": "readonly,
        "password": "ISEisC00L"
       
       
   
    },
    "Local Test Server": {
        "host": "127.0.0.1",
        "username": "admin",
        "password": "admin123"
    }
}

def ssh_to_ise_and_configure(host, username, password, output_box, progress_bar😞
    try:
        progress_bar["value"] = 30
        output_box.insert(tk.END, f"Connecting to {host}...\n")
        logging.info(f"Connecting to {host}...")

        ssh_client = paramiko.SSHClient()
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh_client.connect(host, username=username, password=password, timeout=30)
        output_box.insert(tk.END, "Connection established!\n")
        logging.info("Connection established.")
        progress_bar["value"] = 30

        shell = ssh_client.invoke_shell()
        time.sleep(1)

        shell.send("application configure ise\n")
        time.sleep(2)
        output = shell.recv(65535).decode('utf-8')
        output_box.insert(tk.END, output + "\n")
        logging.info(output)
        progress_bar["value"] = 50

        if "Select" in output:
            shell.send("16\n")
            time.sleep(2)
            output = shell.recv(65535).decode('utf-8')
            output_box.insert(tk.END, output + "\n")
            logging.info(output)
            progress_bar["value"] = 70

            shell.send("0\n")
            time.sleep(2)
            output = shell.recv(65535).decode('utf-8')
            output_box.insert(tk.END, output + "\n")
            logging.info(output)

        ssh_client.close()
        output_box.insert(tk.END, "Configuration completed and connection closed.\n")
        logging.info("Configuration completed and connection closed.")
        progress_bar["value"] = 100

    except paramiko.AuthenticationException:
        messagebox.showerror("Authentication Error", "Invalid username or password.")
        logging.error("Authentication failed.")
    except paramiko.SSHException as ssh_error:
        messagebox.showerror("SSH Error", str(ssh_error))
        logging.error(f"SSH error: {ssh_error}")
    except Exception as e:
        messagebox.showerror("Error", str(e))
        logging.error(f"Unexpected error: {e}")

def launch_gui():
    window = tk.Tk()
    window.title("Cisco ISE Configurator")

    # Profile dropdown
    tk.Label(window, text="Profile:").grid(row=0, column=0, sticky="e")
    profile_var = tk.StringVar()
    profile_dropdown = ttk.Combobox(window, textvariable=profile_var, values=list(PROFILES.keys()), state="readonly", width=40)
    profile_dropdown.grid(row=0, column=1)
    profile_dropdown.current(0)

    # Output box
    output_box = scrolledtext.ScrolledText(window, width=80, height=20)
    output_box.grid(row=3, column=0, columnspan=2, padx=10, pady=10)

    # Progress bar
    progress_bar = ttk.Progressbar(window, orient="horizontal", length=400, mode="determinate")
    progress_bar.grid(row=4, column=0, columnspan=2, pady=10)

    # Button
    def on_connect():
        profile = PROFILES[profile_var.get()]
        output_box.delete(1.0, tk.END)
        progress_bar["value"] = 0
        ssh_to_ise_and_configure(profile["host"], profile["username"], profile["password"], output_box, progress_bar)

    connect_button = tk.Button(window, text="Connect & Configure", command=on_connect)
    connect_button.grid(row=2, column=0, columnspan=2, pady=10)

    window.mainloop()

if __name__ == "__main__":
    launch_gui()

 

 

Any assistance is appreciated!

John

1 Reply 1

Torbjørn
VIP
VIP

Paramiko uses SSH and should be supplied with the IP address only - you are currently supplying it with the https URL of the sandbox. The always on sandbox is also not available over SSH. You will have to test this against the reservable ISE sandbox.

This looks like a nice project to get familiar with ISE automation. Let us know if you need more assistance with this!

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev