Thanks!!! I will look into JSONRPC but since we have mixture of codes in out env I don't think it is going to work.
I tried the second code but when i run it on by Linux machine, it shows nothing. It does run without giving me any errors but no output. I have a test device with user "user12" and password "1password2" with ip "10.10.10.1". Here is how I edited the code. Can you please check and see if I missed something. I am not familiar with classes.
I also added a print in main and I don't see that either.
class SSH2EXOS:
def __init__(self, switch, user='user12',password='1password2'):
self.connected = True
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(switch,username=user,password=password)
stdin, stdout, stderr = self.client.exec_command("disable clipaging")
stdin.close()
def cmdFast(self,cmd,timeout=30):
stdin, stdout, stderr = self.client.exec_command(cmd)
stdin.close()
return cmd+"\n"+stdout.read()
def exit(self):
self.client.close()
self.connected = False
def exitwithsave(self,save):
if save == "Y":
print "Saving config"
try:
stdin, stdout, stderr = self.client.exec_command('save')
stdin.flush()
print stdout.read()
self.client.close()
self.connected = False
except:
print "except"
self.client.close()
self.connected = False
def isConnected(self):
if self.connected:
return True
else:
return False
def main(): print "Main"
parser = argparse.ArgumentParser(description='Connect to switch(es) and delete xsf files')
parser.add_argument("-u", dest="user", default="user12", help="Username")
parser.add_argument("-p", dest="password", default="1password2", help="Password, leave out for none") parser.add_argument("-s", dest="switch", default=None, help="10.10.10.1")
args = parser.parse_args()
mlagfilters = None
if args.switch:
print "Connecting to :",args.switch
xos = SSH2EXOS(checkIP(args.switch), user=args.user, password=args.password)
if xos.isConnected():
print "Connected."
info = xos.cmdFast("show switch")
for line in info.splitlines():
m = re.search(r'SysName:\s+(\S+)',line)
if m:
switchname = m.group(1)
xos.exit()