I am wondering how I can iterate through 48 ports of a SAN switch one by one and enable or disable them ? For some background info, I write python scripts for work to automate the testing of networking devices. I use a library called paramiko which connects to these devices using SSH.
Here is a simple function I wrote in where a user enters in which port they want to disable
def disablePort(ssh):
user_input = input("Enter the port number you want to disable\n")
channel = ssh.invoke_shell()
ssh.exec_command("portdisable " + user_input)
channel.close()
print("Port " + user_input + " " + "disabled\n")
print("Waiting 10 seconds as instructed by the test case\n")
time.sleep(10)
Now, I got 48 ports on this switch and I wish to disable them one by one. I feel like a naive solution would be to create a list where all the port names are hardcoded and iterate through each one and feed it in to the ssh.exec_command() method, but is there a more elegant/practical solution to this ? How would I be able to go about doing this ? Thanks for the help!