Follow me!

LinkedIn Twitter

Who's Online

We have 153 guests online

Python News



  

How to get information from the Netscaler using Python and Suds.
Programming HowTo's - Python HowTo's
Written by Allen Sanabria   
Monday, 01 February 2010 08:22

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:37
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


Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! Yahoo! Free Joomla PHP extensions, software, information and tutorials.
Comments
Search RSS
rasputnik   |Registered |2010-05-25 00:57:28
Thanks a lot for this; I've been banging my head against the SOAP API for ages
(even got as far as finding suds) but no success.

I seem to be able to login
now - client.service.login(..) returns 0, and I see the user login in the
netscaler logs - but whenever I try to call a method on client.service , I
get

(getlbvserverResult){
rc = 1027
message = "Not logged in or
connection timed out"
}

Any clues? Thanks again!
dynasty   |SAdministrator |2010-05-25 05:50:15
Can you run the script? Or is it you are trying to run methods using the Python
Virtual Shell?

Try passing the timeout option..

go here in my forum ...
http://www.linuxdynasty.org/index.php?option=com_a
gora&task=topic&id=64&Itemid=7
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated on Monday, 01 February 2010 21:26