Python Scripts: Difference between revisions

Line 637:
== Save Netscaler config, Reboot & Verify ==
*Need to remove repeating code lines for connection from each function
 
<pre>
<syntaxhighlight lang="python">
import sys
import time
Line 645 ⟶ 646:
from nssrc.com.citrix.netscaler.nitro.resource.stat.system.system_stats import system_stats
 
class ns_edit :
ip = "10.107.88.78"
def __init__(self, ip, username, password):
username = "nsroot"
self.ip = ip
password = "pwd@123"
self.username = "nsroot"username
 
self.password = "pwd@123"password
def uptime():
try:
self.client = nitro_service(self.ip,"http")
self.client.set_credential(self.username,self.password)
client.timeout = 20
except nitro_exception as e:
node = system_stats.get(client)
print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
for i in node:
def uptime(self):
print "Last reboot time is %s" %i.starttime
try:
 
node = system_stats.get(self.client)
def save_cfg():
for i in node:
client = nitro_service(ip,"http")
print "Last reboot time is %s" %i.starttime
client.set_credential(username,password)
except nitro_exception as e:
client.timeout = 20
print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
client.save_config()
def reboot(self):
print ("Config Saved")
try:
 
def self.client.reboot(True):
print "Node rebooted"
client = nitro_service(ip,"http")
except nitro_exception as e:
client.set_credential(username,password)
print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
client.timeout = 20
client.reboot(True)
print ("Reboot Initiated")
 
try:
uptime()
save_cfg()
reboot()
time.sleep(60)
uptime()
 
if __name__ == '__main__':
except nitro_exception as e:
ns = ns_edit("10.107.88.78", "nsroot", "pwd@123")
print("Exception::errorcode="+str(e.errorcode)+",message="+ e.message)
ns.uptime()
</pre>
client ns.reboot(True)
time.sleep(60)
ns.uptime()
</syntaxhighlight>
 
= Extensions Doctor =