So far you have learned about the SOAP protocol (an XML-based protocol that defines how messages are encapsulated), RPC's way of communication (the client sends a message that tells what function it wants the server to execute, and the server responds with a message that contains the data generated by the remote function) and WSDL (the language that defines what methods are available and what data types are used in requests/responses).
We also decided that we are going to generate two helper modules: one that contains remote methods and another that defines data structures, and that we are going to use wsdl2py tool that is available from ZSI library.
I am going to write a tool to manage Citrix Netscaler load balancer devices. These devices provide two web service interfaces:
• The Statistics Web Service. This service provides methods to query statistical information about all functional aspects of the loadbalancer, such as virtual servers, services, VLAN configuration and so on. In version 8.1 of Netscaler OS there are 44 objects that you can gather performance information from.
• The Configuration Web Service. This service allows you to change device configuration and perform maintenance tasks, such as enable/disable servers and services. In the same 8.1 NS OS there are 2364 configurable parameters that are accessible via SOAP interface.
Links to WSDL locations and other useful information, such as API documentation and SNMP object definitions, can be found by visiting http://192.168.1.1/ws/download. pl, where 192. 168.1.1 needs to be replaced with the IP address of the Netscaler load balancer that you are using. In this chapter I will assume and use 192.168.1.1 as the IP of my Netscaler device. A link to the downloads page is also available from the main management screen.
I have provided the following WSDL URLs, as it is unlikely they will change:
• WSDL for the statistics SOAP interface: http://192.168.1.1/api/NSStat.wsdl
• WSDL for the configuration SOAP interface: http://192.168.1.1/api/NSConfig.wsdl
Using the wsdl2py script is very simple; if no special configuration is required, all you need to do is provide the location of a WSDL document and it will generate both method and data type modules automatically. No additional user input is required. Either the wsdl2py tool can fetch the WSDL document from the web location, or you can provide a filename and it will parse the file.
In the example shown in Listing 2-5, we will point the wsdl2py script directly at the WSDL URL on the Netscaler load balancer.
Listing 2-5. A Command to convert Python modules from a WSDL file $ wsdl2py --url http://192.168.1.1/api/NSStat.wsdl
If the script can contact the destination server and the XML document it receives contains no errors, it will not produce any messages and will silently create two Python packages.
■Note If you have retrieved a WSDL file and stored it locally, you can use the - -file flag and supply the filename of the WSDL document. This will instruct wsdl2py to parse the locally stored file.
At this point we've run the script and wsdl2py has produced the following two modules:
NSStat_services. py: This module contains the Locator class, which is used to connect to the service and classes for each remotely available method.
NSStat_services_types. py: This file is rarely used directly. It is imported from the previous module and contains class definitions for every data type used by our web service. It does contain useful information that you will need later when creating requests and inspecting responses from the web service.
There are other options for the wsdl2py tool, which could be used to produce server helper modules. With these modules you can then implement your own version of the web service that exposes the same interface and understands same protocols as defined by our WSDL file, but this goes beyond the scope of our project.
Was this article helpful?