Forum Discussion

Carl_Rosevear_1's avatar
Carl_Rosevear_1
Icon for Nimbostratus rankNimbostratus
May 18, 2009

Help with PyControl Accessing Enumerations

So, I'm new to iControl. I'm new to SOAP. I'm pretty Python-savvy and network-savvy but I need some help. I have already re-written some of my old SSH modules to make use of iControl instead of SSH for manipulating BigIP LTM configs. However, I need to write some web interfaces and I want to retrieve the value set from within an enumeration in the WSDL, say for example LocalLB... LBMethods. Not exactly sure how to reference these enumerations within the pycontrol setup that's for sure. So what am I missing? How can I retrieve these values to use for the options in a drop-down list box on a web interface, basically... Thanks.

 

 

--Carl

 

4 Replies

  • Carl: I'm not 100% clear on what you're trying to accomplish, but perhaps something like this would work?

     
     In [14]: pools = b.LocalLB_Pool.get_list()['return'] 
     In [15]: b.LocalLB_Pool.get_lb_method(pool_names = pools) 
     Out[15]: 
     {'return': ['LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_OBSERVED_MEMBER', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN', 
                 'LB_METHOD_ROUND_ROBIN']} 
     

    Where you could then convert into a dict, tuple, etc...the return list from get_lb_methods() should be in order of your pool list argument, so you can create pretty much whatever data structures you want. I've done stuff like this in the past:

     
     In[17]:  pools = b.LocalLB_Pool.get_list()['return'] 
     In [18]: methods = b.LocalLB_Pool.get_lb_method(pool_names = pools)['return'] 
     In [19]: combined = zip(pools, methods) 
     In [21]: combined[10] 
     Out[21]: ('pycontrol2-test', 'LB_METHOD_ROUND_ROBIN') 
     

    I hope this helps. If not, please post back.

    -Matt
  • Matt... thanks for your help! No, that's not exactly what I'm trying to do. Perhaps my code snippet was misleading...

     

     

    What I want is to retrieve a list of ALL AVAILABLE load-balancing methods, not just the ones in use. I see 'em in the WSDL but I'm not sure how to extract that information outside of using some XML module or something... seems like something PyControl would give me native access too though.

     

     

    Does that make sense? Thanks again.

     

     

    -Carl

     

  • In this case, progress is limited by the knowledge of the guy trying to make said progress. Okay, so I'm used to passing around literal values in Python and some objects here and there but I really don't know where to go from here. If you'd teach me how to fish here, I hopefully won't be asking for fish anymore. I get:

     

      
     In [14]: b.LocalLB_Pool._service._wsdl.types.items()   
     Out[14]:    
     [(u'urn:iControl',   
      

     

    Great. I see a unicode string of the URN and a ZSI object that I have no idea what to do with. I have been looking around ZSI docs and I assume there is some method to use that is part of this object to retrieve the values but I'm not finding the right one. Any ideas? As I say, I'm totally new to the web services landscape. Any sample code would really help seal the deal for me or any kind of pointer to a doc URL. Looks like you probably have pointed out exactly what I need but I still don't know how to access the data.

     

    --Carl
  • Ok, I finally got to the LB methods. Thanks a ton for the question, as this was pretty useful from a ZSI internals perspective. You totally nailed it with the 'facets':

     
     In [258]: for f in res.facets: 
        .....:     print f.getAttributeDictionary()['value'] 
        .....: 
        .....: 
     LB_METHOD_ROUND_ROBIN 
     LB_METHOD_RATIO_MEMBER 
     LB_METHOD_LEAST_CONNECTION_MEMBER 
     LB_METHOD_OBSERVED_MEMBER 
     LB_METHOD_PREDICTIVE_MEMBER 
     LB_METHOD_RATIO_NODE_ADDRESS 
     LB_METHOD_LEAST_CONNECTION_NODE_ADDRESS 
     LB_METHOD_FASTEST_NODE_ADDRESS 
     LB_METHOD_OBSERVED_NODE_ADDRESS 
     LB_METHOD_PREDICTIVE_NODE_ADDRESS 
     LB_METHOD_DYNAMIC_RATIO 
     LB_METHOD_FASTEST_APP_RESPONSE 
     LB_METHOD_LEAST_SESSIONS 
     LB_METHOD_DYNAMIC_RATIO_MEMBER 
     LB_METHOD_L3_ADDR 
     

    I'll work up an exact example of how I got to this point and post soon.

    -Matt