|
Recently I just started to use the Citrix Netscalers again ( Load Balancers ). Being the person that I am, I wanted a way to grab the information using the SOAP API. Now Citrix has a ton of documentation for Perl/C/C# and Java ( None for Python ). SOAP client support has not been the best for Python, in my opinion. I know you have soappy/ZSI, which I have had issues with consuming Broken WSDL files ( Having to fix the Broken WSDL file manually, SUCKS!).
Just 2 weeks ago, I encounterd SUDS. This module is by far, the best SOAP client for Python. There documentation is simple and straight to the point, with a bunch of nice samples to get you on your way.
Install SUDS before proceeding further. You can get suds from here. https://fedorahosted.org/suds/ Connection to my netscaler was as simple as this...
Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from suds.client import Client >>> url = "http://nsip/api/NSConfig.wsdl" >>> from suds.xsd.doctor import * >>> imp = Import('http://schemas.xmlsoap.org/soap/encoding/') >>> imp.filter.add("urn:NSConfig") >>> d = ImportDoctor(imp) >>> client = Client(url, doctor=d, location="http://nsip/soap/") >>> client.service.login(username="login", password="pass") (simpleResult){ rc = 0 message = "Done" } >>>
As you can see above, I used the xsd doctor to import Soap encoding URL and added a filter for the Netscaler URN. If you do not import the SOAP encoding schema, this is the error you will receive..
suds.TypeNotFound: Type not found: '(Array, http://schemas.xmlsoap.org/soap/encoding/, )
Once you type the above, you can now run commands in the python shell. for instance...
- client.service.getlbvserver()
- client.service.getservice()
- client.service.getservicegroup()
I am attaching a script that I have written, to get Load Balanced Virtual Servers and its Services and ServiceGroups. This script can also just list all the Virtual Servers, Services, or Service Groups. Examples below..
Download Query NS | | File Title: | Query NS (Details) | | File Type: | py | | File Version: | 1.0.1 | | File Size: | 8.81 Kb | | License: | | | File Author: | Allen Sanabria | | File HomePage: | | | Downloads: | 8 | | Rating: | ( Votes) | | Your Vote: | |
| |
python queryns.py -c "ZenossTest2_svc" -n "nsip" -u "login" -p "pass"
Service Name Server Name Status IPAddress Port Protocol ZenossTest2_svc zenossTest OUT OF SERVICE 192.168.101.221 9090 HTTP
python queryns.py -s foobar_test -n "nsip" -u "login" -p "pass"
Virtual Server State IPAddress Port Protocol foobar_test UP 192.168.101.19 55555 HTTP
ServiceGroup Name SG State Server Name Status IPAddress Port Protocol "Foo Bar" ENABLED billyboy UP 192.168.101.31 8080 HTTP "Foo Bar" ENABLED zenossTest UP 192.168.101.221 8080 HTTP
Service Name Server Name Status IPAddress Port Protocol ZenossTest2_svc zenossTest OUT OF SERVICE 192.168.101.221 9090 HTTP ------------------------------------------------------------------------------------------------------------------------
All the options are here..
python queryns.py -h usage: queryns.py [options] arg --username=username --password=password --netscaler=netscalerip
options: -h, --help show this help message and exit -n NETSCALER, --netscaler=NETSCALER Here you will put the netscaler IPAddress or the netscaler hostname -u USERNAME, --username=USERNAME Your username -p PASSWORD, --password=PASSWORD Your password -l LIST, --list=LIST List all the names of the Virtual Servers, Services, ServiceGroups. Example --list=lbvserver, --list=service, --list=servicegroup -s SERVER, --vserver=SERVER Virtual Server that you want to query. You can choose a Virtual Server or you can pass all, so you get all the Virtual Servers and its associated ServiceGroups or Services. Example.... --vserver="foobar_test" or --vserver="all" -g SGROUP, --sgroup=SGROUP ServiceGroup that you want the info from -c SERVICE, --service=SERVICE Service that you want the info from
|