Jump to content

Python Scripts: Difference between revisions

Line 385:
</pre>
 
= Reboot Netscaler via APIs =
{{notice|This script is under construction.}}
*Needs Authentication alerts
*Needs NS Parameters to be set globally
*Needs to confirm API execution via HTTP Status Codes
 
<pre>
import subprocess as sub
import time
 
# Netscaler Parameters
host = '10.107.88.78'
#username = 'nsroot'
#passwd = 'pwd@123'
# Boolean true means Warm reboot, else false
#boolean = 'true'
 
#i = 1
 
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$
output1, err = uptime1.communicate()
print output1
 
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)
 
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()
print output2
 
if (output1 == output2):
print "Reboot unsuccessful"
else:
print "Reboot successful."
</pre>
 
<br />
Cookies help us deliver our services. By using our services, you agree to our use of cookies.