Skip to main content

A simple library to control Citrix Netscaler 9.2+ with NITRO API.

Project description

Simple Python Library to control Citrix Netscaler 9.2+ load balancers with NITRO API.
What we're trying here is to implement Citrix NITRO API SDK (that's available for Java and C#) in Python.

You can find a simple command-line interface using this library in contrib/.
Feedback/comments welcome.

Very basic usage::

import time
from nsnitro import *

nitro = NSNitro('localhost', 'api_user', 'api_user')
nitro.login()

# add server test
addserver = NSServer()
addserver.set_name("mp-nitroserver")
addserver.set_ipaddress("10.32.110.99")
NSServer.add(nitro, addserver)

server = NSServer()
server.set_name("mp-nitroserver")
server = server.get(nitro, server)
print server.get_name() + ": " + server.get_state()

# disable server test
server = NSServer()
server.set_name("mp-nitroserver")
NSServer.disable(nitro, server)

time.sleep(2)

server = NSServer()
server.set_name("mp-nitroserver")
server = server.get(nitro, server)
print server.get_name() + ": " + server.get_state()


# enable server test
server = NSServer()
server.set_name("mp-nitroserver")
NSServer.enable(nitro, server)

time.sleep(2)

server = NSServer()
server.set_name("mp-nitroserver")
server = server.get(nitro, server)
print server.get_name() + ": " + server.get_state()

# add service test

addservice = NSService()
addservice.set_name("aurora_testnitroadd")
addservice.set_servername("mp-nitroserver")
addservice.set_servicetype("HTTP")
addservice.set_port(11111)
NSService.add(nitro, addservice)

# add lbvserver test
lbvserver = NSLBVServer()
lbvserver.set_name("nitro_lbvserver_test")
lbvserver.set_ipv46("10.32.110.55")
lbvserver.set_port(11111)
lbvserver.set_clttimeout(180)
lbvserver.set_persistencetype("NONE")
lbvserver.set_servicetype("HTTP")
NSLBVServer.add(nitro, lbvserver)
#
print "LB vserver added"

# bind service to lbvserver test
lbbinding = NSLBVServerServiceBinding()
lbbinding.set_name("nitro_lbvserver_test")
lbbinding.set_servicename("aurora_testnitroadd")
lbbinding.set_weight(40)
NSLBVServerServiceBinding.add(nitro, lbbinding)

print "Binding added"

lbbinding = NSLBVServerServiceBinding()
lbbinding.set_name("nitro_lbvserver_test")
lbbindings = NSLBVServerServiceBinding.get(nitro, lbbinding)

for lbb in lbbindings:
print "sgn: " + lbb.get_servicegroupname()

# delete binding test
lbbinding = NSLBVServerServiceBinding()
lbbinding.set_name("nitro_lbvserver_test")
lbbinding.set_servicename("aurora_testnitroadd")
NSLBVServerServiceBinding.delete(nitro, lbbinding)

print "Binding removed"

# delete lbvserver test
lbvserver = NSLBVServer()
lbvserver.set_name("nitro_lbvserver_test")
NSLBVServer.delete(nitro, lbvserver)

# get service test

service = NSService()
service.set_name("aurora_testnitroadd")
service = service.get(nitro, service)
print service.get_name() + ": " + service.get_svrstate()
print service.get_name() + ": %s %s" % (service.get_port(), service.get_useproxyport())

#update service test
updateservice = NSService()
updateservice.set_name("aurora_testnitroadd")
updateservice.set_comment("test comment")
updateservice.set_useproxyport("NO")
NSService.update(nitro, updateservice)

# get service test

service = NSService()
service.set_name("aurora_testnitroadd")
service = service.get(nitro, service)
print service.get_name() + ": " + service.get_svrstate()
print service.get_name() + ": %s %s %s" % (service.get_port(), service.get_comment(), service.get_useproxyport())

# disable service test

disservice = NSService()
disservice.set_name("aurora_testnitroadd")
NSService.disable(nitro, disservice)

service = NSService()
service.set_name("aurora_testnitroadd")
service = service.get(nitro, service)
print service.get_name() + ": " + service.get_svrstate()

# enable service test

enservice = NSService()
enservice.set_name("aurora_testnitroadd")
NSService.enable(nitro, enservice)

service = NSService()
service.set_name("aurora_testnitroadd")
service = service.get(nitro, service)
print service.get_name() + ": " + service.get_svrstate()


# rename service test

renservice = NSService()
renservice.set_name("aurora_testnitroadd")
renservice.set_newname("aurora_testnitroadd_rename")
NSService.rename(nitro, renservice)

# rename service back test

renservice = NSService()
renservice.set_name("aurora_testnitroadd_rename")
renservice.set_newname("aurora_testnitroadd")
NSService.rename(nitro, renservice)

# delete service test

delservice = NSService()
delservice.set_name("aurora_testnitroadd")
NSService.delete(nitro, delservice)

try:
service = NSService()
service.set_name("aurora_testnitroadd")
service = service.get(nitro, service)
print service.get_name() + ": " + service.get_svrstate()
except NSNitroError, e:
print e.message


# delete server test
delserver = NSServer()
delserver.set_name("mp-nitroserver")
NSServer.delete(nitro, delserver)


try:
server = NSServer()
server.set_name("mp-nitroserver")
server = server.get(nitro, server)
print server.get_name() + ": " + server.get_state()
except NSNitroError, e:
print e.message

#add system cmd policy
cmdpol = NSSystemCMDPolicy()
cmdpol.set_action('ALLOW')
cmdpol.set_policyname('nitro-cmd-policy')
cmdpol.set_cmdspec('show hardware')
NSSystemCMDPolicy.add(nitro,cmdpol)

#update system cmd policy
cmdpol = NSSystemCMDPolicy()
cmdpol.set_action('DENY')
cmdpol.set_policyname('nitro-cmd-policy')
cmdpol.set_cmdspec('show hardware')
NSSystemCMDPolicy.update(nitro,cmdpol)

#delete system cmd policy
cmdpol = NSSystemCMDPolicy()
cmdpol.set_policyname('nitro-cmd-policy')
NSSystemCMDPolicy.delete(nitro,cmdpol)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsnitro-1.0.35.tar.gz (165.3 kB view details)

Uploaded Source

Built Distribution

nsnitro-1.0.35.macosx-10.10-x86_64.tar.gz (407.4 kB view details)

Uploaded Source

File details

Details for the file nsnitro-1.0.35.tar.gz.

File metadata

  • Download URL: nsnitro-1.0.35.tar.gz
  • Upload date:
  • Size: 165.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nsnitro-1.0.35.tar.gz
Algorithm Hash digest
SHA256 afe971c1054d187119f8030274bca8ed35d759e575d4fd15879386732cfdfa6e
MD5 439645b04edcede0ab98c4cabf30ec2c
BLAKE2b-256 90cc4d56af6b91f4c3c1f3d8e367bea3dad0dddb3cb8bbe4af481095e4864dc3

See more details on using hashes here.

File details

Details for the file nsnitro-1.0.35.macosx-10.10-x86_64.tar.gz.

File metadata

File hashes

Hashes for nsnitro-1.0.35.macosx-10.10-x86_64.tar.gz
Algorithm Hash digest
SHA256 97e974685773f99189b9e1a2ea077463f6c79f685ae84e61767c05f6b45f857e
MD5 ab6bd4786083943e224e0dfb0fa8d0e4
BLAKE2b-256 0b4e1092b948ed9d0dda63604837c3daca3d4345940cc1dd49dee5fc9b0afcef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page