Forum Discussion

uisomdc_95191's avatar
uisomdc_95191
Icon for Nimbostratus rankNimbostratus
Sep 04, 2008

adding strings to data group

so we had a whole bunch of stuff to add to a string data group, but didn't feel safe giving operators privs to do this manually. in comes pycontrol and the class wsdl. This will iterate over inputfile.list, chop off carriage returns (you may need to take that part out depending on your inputfile), and submit it all to pyTest data group. I've only tried this for strings.

The try/except may not be all that elegant to prevent adding duplicate entries, but it works.

   
   addString.py    
      
   !/usr/bin/python2.5   
      
   import pycontrol.pyControl as pyControl   
      
      
       BIG IP CONFIG        
   host = '123.456.78.9'     
   username = 'pyControl'    
   password = 'pyControl'    
   className = 'pyTest'      
      
      
    Create object    
   b = pyControl.BIGIP(   
           hostname = host,    
           username   = username,    
           password   = password,    
           wsdl_files = ['LocalLB.Class']   
           )   
      
   c = b.LocalLB_Class   
      
   f = open("inputfile.list", "r")   
   while True:   
         line = f.readline()[:-1]  :-1 takes out carriage return   
   if len(line) == 0:    
   break   
   try:   
   c.add_string_class_member(class_members = [{'members': [line], 'name': className}])   
   except:   
   continue   
   f.close()   
      
      
   

6 Replies

  • This is great! Would you mind my contributing it to the iControl CodeShare? Since you posted it here, I'm sure you wouldn't but I figured I'd ask anyway...

     

     

    BTW, if anyone would like alternate versions of this code (C, PowerShell, Perl, etc), let me know and I'll whip it up for you.

     

     

    -Joe
  • hey Joe, I tried to add it myself to the codeshare but had no success. nodeAlert is all done too, let me know where you want it.
  • Here's how to manually add it to the Wiki.

     

     

    1. Go to the iControl wiki (Click here)

     

    2. Click on the title "iControl Wiki Home".

     

    3. In the edit box, type the topic (ie. pyNodeAlert) and hit enter.

     

    4. You'll now be on a "Editing pyNodeAlert" page.

     

    5. Delete the content in the topic and click the "Sample Code" template in the right panel.

     

    6. Paste the code where the pound signs are in the code section at the bottom.

     

    7. Add a summary after "Summary: "

     

    8. Replace the "In Progress..." line with your own description.

     

    9. Click "Save".

     

     

    I'll go in after the fact and update the FEATURES_USED so that the sample will be linked to in the various API pages.

     

     

    If this is too much work, go ahead and post it here as a .txt attachment and I'll add them for you.

     

     

    Cheers and thanks for contributing!

     

     

    -Joe
  • I'm trying to add addresses to a data group with pycontrol and not having much luck using variations of:

     

     

    b.LocalLB_Class.add_address_class_member(class_members = ...

     

     

    I can't get the syntax right after trying many different combinations.

     

    Any help on that front would be appreciated.

     

     

    Thanks
  • Wish I could help you out but I no almost nothing about Python. I'd be able to get you going with Perl if that helps B-). Any Python folks out there care to help?

    The format of the API is

    struct AddressEntry { 
       String address 
       String netmask 
     } 
      
     struct AddressClass { 
       String name 
       AddressEntry [] members 
     } 
      
     LocalLB.Class.add_address_class_member( 
       AddressClass [] class_members 
     )

    So, you'll be needing to pass in an array of AddressClass structures each contiaining a name for the class along with an array of AddressEntry structures containing the address information.

    Good luck...

    -Joe