Forum Discussion
Harry_Hubertus_
Jun 05, 2008Historic F5 Account
pyControl Log and Exception
Hi,
Is there a log file from running pyControl. Where is it located.
Also, how do you handle exception raised from passing invalid argument (like virtual name that doesn't exist).
Thanks.
2 Replies
- L4L7_53191
Nimbostratus
Hubertus: A nice trick is to pass the 'tracefile' keyword argument when you build the object. For example:
import sys
import pycontrol.pyControl as pc
b = pc.BIGIP(hostname = '192.168.1.245', username = 'admin', password = 'admin', wsdl_files = ['System.Statistics'], tracefile = sys.stdout)
....which will produce a dump of requests/responses to stdout so you can see what is going on (I'm using the iPython shell here):
In [4]: b.System_Statistics.get_version()
_________________________________ Fri Jun 06 08:18:08 2008 REQUEST:
xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SO
AP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> ader> on>
_________________________________ Fri Jun 06 08:18:09 2008 RESPONSE:
200
OK
-------
Date: Fri, 06 Jun 2008 12:18:08 GMT
Server: Apache
Set-Cookie: BIGIPAuthCookie=DD94709528BB1C83D08F3088D4043F4742891F4F; path=/;
SOAPServer: EasySoap++/0.6
Transfer-Encoding: chunked
Content-Type: text/xml; charset="UTF-8"
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
xmlns:iControl="urn:iControl"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
xmlns:m="urn:iControl:System/Statistics">
s:type="y:string">BIG-IP_v9.4.2
Out[4]: {'return': 'BIG-IP_v9.4.2'}
You can also specify a specific log file to dump to if you wish - this isn't limited to sys.stdout (although it's probably the most useful thing for debugging). From time to time you'll get the odd error, which I've forced as an example:
Let's find a getter that wants a specific argument structure, and intentionally pass in a bad value. A handy trick is to print out the special attribute "_h" for the getter method. This will tell you what the input and output params are:
In [8]: print b.System_Statistics.get_virtual_compression_statistics._h
InParams Count: 1
device_names: Common.StringSequence
OutParams Count: 1
return: System.Statistics.VirtualCompressionStatistics
So the get_virtual_compression_statistics() method expects an argument of device_names. Passing in a plain old string to this should generate a type mismatch (any parameter that ends in a plural, such as 'device_names' expects a list at a minimum):
In [10]: b.System_Statistics.get_virtual_compression_statistics(device_names = 'hello')
_________________________________ Fri Jun 06 08:22:57 2008 RESPONSE:
500
Internal Server Error
-------
Date: Fri, 06 Jun 2008 12:22:57 GMT
Server: Apache
Set-Cookie: BIGIPAuthCookie=DD94709528BB1C83D08F3088D4043F4742891F4F; path=/;
SOAPServer: EasySoap++/0.6
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml; charset="UTF-8"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xsi:type="xsd:string">SOAP-ENV:Server
xsi:type="xsd:string">Exception caught in System::Statistics::get_virtual_compression_s
tatistics()
Exception: Common::NotImplemented
EvaluateException: Type mismatch (http://www.w3.org/2001/XMLSchema namespace) (got string wanted QName)
[Element trace: /SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultcode]
When you see the "got string wanted QName" error, it almost always means you've generated a 500 ISE and that you've not passed in the correct structure - I know this error well!
Anyhow, handling these exceptions with a try: is probably the best way, since about all you'll get is the QName error which is fairly useless but conforms to the spec according to the ZSI folks...
I hope this is useful. At some point I'll try and do a write-up on debugging and give examples of some of the common data structures that get passed into various calls.
-Matt - Roberto_75166
Nimbostratus
If you want to get the appropriate exceptions from the box, instead of the "generic" QNAME error, you can have that with a small change in the ZSI library.
In the ZSI folder (in the site-packages directory, or inside the appropriate .egg file), just edit the fault.py file, and look for the FaultType.typecode definition. Within it, where it reads "QName(pname='faultcode')", change it to "String(pname='faultcode')". Save it and you should be able to get the expected "FaultException" instead of the dreaded EvaluateException.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
