Python Scripts: Difference between revisions

Content added Content deleted
Line 396: Line 396:


# Netscaler Parameters
# Netscaler Parameters
host = '10.107.88.78'
host = "10.107.88.78"
#username = 'nsroot'
username = "nsroot"
#passwd = 'pwd@123'
passwd = "pwd@123"
# Boolean true means Warm reboot, else false
# Boolean true means Warm reboot, else false
#boolean = 'true'
boolean = "true"


# Nitro API calls using Curl
#i = 1
#uptimeapi = ("['curl', '-s', '-k', '-X', 'GET', '-H', 'Content-Type:application/json', '--basic', '--user', '%s:%s', 'http://%s/nitro/v1/stat/system?attrs=starttime']" %(username, passwd, host))
#rebootapi = ("('curl', '-s', '-k', '-X', 'POST', '-H', 'Content-Type:application/vnd.com.citrix.netscaler.reboot+json', '--basic', '--user', '%s:%s', '-d', '{'reboot':{'warm':%s}}', 'http://%s/nitro/v1/config/reboot')" %(username,passwd,boolean,host))


uptime1 = sub.Popen(('curl', '-s', '-k', '-X', 'GET', '-H', 'Content-Type:application/json', '--basic', '--user', 'nsroot:pwd@123', 'http://10.107.88.78/nitro/v1/stat/system?attrs=start$
uptimeapi = ('curl', '-s', '-k', '-X', 'GET', '-H', 'Content-Type:application/json', '--basic', '--user', 'nsroot:pwd@123', 'http://10.107.88.78/nitro/v1/stat/system?attrs=starttime')
rebootapi = ('curl', '-s', '-k', '-X', 'POST', '-H', 'Content-Type:application/vnd.com.citrix.netscaler.reboot+json', '--basic', '--user', 'nsroot:pwd@123', '-d', '{"reboot":{"warm":true}}', 'http://10.107.88.78/nitro/v1/config/reboot')


print uptimeapi
print rebootapi

uptime1 = sub.Popen(uptimeapi, stdout=sub.PIPE)
output1, err = uptime1.communicate()
output1, err = uptime1.communicate()
print output1
print output1


sub.Popen(rebootapi, stdout=sub.PIPE)
sub.Popen(('curl', '-s', '-k', '-X', 'POST', '-H', 'Content-Type:application/vnd.com.citrix.netscaler.reboot+json', '--basic', '--user', 'nsroot:pwd@123', '-d', '{"reboot":{"warm":true}$
time.sleep(50)
time.sleep(50)


uptime2 = sub.Popen(uptimeapi, stdout=sub.PIPE)
uptime2 = sub.Popen(('curl', '-s', '-k', '-X', 'GET', '-H', 'Content-Type:application/json', '--basic', '--user', 'nsroot:pwd@123', 'http://10.107.88.78/nitro/v1/stat/system?attrs=start$
output2, err = uptime2.communicate()
output2, err = uptime2.communicate()
print output2
print output2
Line 418: Line 427:
print "Reboot unsuccessful"
print "Reboot unsuccessful"
else:
else:
print "Reboot successful."
print "Reboot successful"
</pre>
</pre>