Forum Discussion

Andy_Litzinger's avatar
Dec 03, 2010

what is in pycontrol?

I'm a total noob with python. I've been reading as many python icontrol articles as i can find, but none of them have explained what objects/methods/etc are available directly from pycontrol.

 

 

for example, all the code samples initiate a connection to the BigIp with a call similar to this:

 

b = pc.BIGIP(hostname='192.168.1.245', username='admin', password='admin', fromurl=True, wsdls = ['LocalLB.Pool'])

 

 

 

how would I know that "BIGIP" is a method inside of pycontrol?

 

 

 

thanks!

 

andy

 

3 Replies

  • Andy: BIGIP is actually a *class* inside of pycontrol. The methods are actually bound to objects inside that class. If you're interested, you can go into your site-packages directory and look at the actual source of pycontrol.py. There you will see the class BIGIP() stuff where all the magic happens.

     

     

    One of the tricky parts for a brand-new Python person (welcome!) and pyControl could be that we actually build the methods dynamically, based on the actual WSDL file's method declarations. There's nothing statically built at all method wise: it's all done when you suck up a WSDL and parse it. This means that, generically speaking, a pure BIGIP object has no external methods exposed. It only happens once pyControl (or suds, more accurately) parses the WSDL. At that point they get created. So to get a feel for the actual methods we expose, have a look at the iControl SDK itself, which has all of the methods, etc.

     

     

    Alternatively, you can load up several WSDLs and poke around in an iPython or IDLE shell to see the methods.

     

     

    To me, it's one of the cool things about the library. In Python, you instantiate a class - in this case BIGIP() - and that translates to a parsed WSDL or set of WSDLs. Then we create attributes so you can call the methods in a clean way:

     

     

    b.LocalLB.Pool.get_list() - or -

     

    b.LocalLB.VirtualServer.get_list()

     

     

    All against the same object. Make sense? I'm afraid I may not have done a good job explaining this. If not, please fire away with more questions.

     

     

    -Matt
  • yes, that makes sense. I apologize for my butchering of OO vocabulary.

     

     

    so the question I should have asked is, how can I tell what classes are available in pycontrol? and it sounds like the answer is to browse the source of the pycontrol.py file. np, i can do that.

     

     

     

    I was asking mostly because I wasn't sure how I was supposed to know to call the BIGIP class in order to set up the connection parameters needed to communicate with my BIGIP aside from the fact that every example/sample code uses it. is there a 'man pycontrol' or 'pycontrol --help'? or is there a way from a python interactive shell to dump out the class(es) in pycontrol like you can with the other WSDLs once you've loaded them?

     

     

     

     

     

     

     

  • You can peek at the classes by firing up iPython (I use this and vim as my IDE), and doing this:

     

     

    import pycontrol.pycontrol

     

     

    Then you can do:

     

    pycontrol.

     

     

    **Notice the 'dot' at the end of pycontrol.

     

     

    Which will show you the classes, such as they are. The only one that is 'external' is BIGIP, so there's effectively only a single small class. The rest is done when you load the WSDL. I think what you may be asking for is: "What can I actually do with this thing pycontrol?"

     

     

    If that's true, then I'd refer you to the iControl SDK - that'll give you a definitive answer of exactly what pyControl can do. After all, it's essentially only a wrapper for the WSDLs themselves, with some transport code and convenience wrappers for authentication and loading built in.

     

     

    -Matt