Python Scripts: Difference between revisions

Line 399:
username = "nsroot"
passwd = "pwd@123"
 
# Boolean true means Warm reboot, else; false means full reboot
boolean = "true"
 
# Nitro API calls using Curl
#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))
 
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')
Line 421 ⟶ 419:
 
uptime2 = sub.Popen(uptimeapi, stdout=sub.PIPE)
output2, err = uptime2.communicate()
print output2
 
if (output1 == output2):
print "Reboot unsuccessful"
else:
print "Reboot successful"
</pre>
 
;Updated version of above with using parameters:
<pre>
import subprocess as sub
import time
 
# Netscaler Parameters
host = "10.107.88.78"
username = "nsroot"
passwd = "pwd@123"
 
# Boolean true means Warm reboot; false means full reboot
boolean = "true"
 
# Nitro API calls using Curl
#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))u$
 
print uptimeapi
print rebootapi
 
uptime1 = sub.Popen(uptimeapi.split(), stdout=sub.PIPE)
output1, err = uptime1.communicate()
print output1
 
sub.Popen(rebootapi.split(), stdout=sub.PIPE)
time.sleep(10)
 
uptime2 = sub.Popen(uptimeapi.split(), stdout=sub.PIPE)
output2, err = uptime2.communicate()
print output2