Forum Discussion

Nate_W_50838's avatar
Nate_W_50838
Historic F5 Account
Mar 31, 2010

Trying to create a region definition via pycontrol

I’m trying to write some pycontrol code to create a region on a 10.1.0 GTM, I can’t seem to get the create() statement correct. I’m trying to create a region entry like this:

 

 

region {

 

name "test-region"

 

state."US/Alabama"

 

state.”US/Wyoming”

 

state.”US/Colorado”

 

state.”US/Nebraska”

 

state.”US/Nevada”

 

}

 

 

Either pycontrol 1 or 2 would be helpful, I've been trying to use:

 

 

d.create(

 

regions = ['my_region'],

 

items = ['US/California','US/Washington'],

 

)

 

 

But this appears to be incorrect. Any help would be most appreciated!
  • Here's a working sample.

        
     import pycontrol.pycontrol as pc 
     b = pc.BIGIP(hostname = '10.100.100.245', username='admin', password='admin', fromurl=True, wsdls=['GlobalLB.Region']) 
     reg = b.GlobalLB.Region 
      
      Create regions 
     regions = ['US/Alabama','US/Colorado','US/Nebraska','US/Nevada','US/Wyoming'] 
      
     reg_list = [] 
      
      Create region item type, append to reg_list 
     for x in range(1,6): 
         x = reg.typefactory.create('GlobalLB.Region.RegionItem') 
         x.type = 'REGION_TYPE_STATE' 
         x.negate = False 
         reg_list.append(x) 
      
      Bind the regions to the 'content' attribute 
     for index,region in enumerate(regions): 
         reg_list[index].content = region 
      
      create the sequence type 
     reg_seq = reg.typefactory.create('GlobalLB.Region.RegionItemSequence') 
     reg_seq.item = reg_list 
      
      create the region definition type 
     region_def = reg.typefactory.create('GlobalLB.Region.RegionDefinition') 
     region_def.name = 'myTestRegion-3' 
     region_def.db_type = 'REGION_TYPE_USER_DEFINED' 
      
      Create! 
     reg.create(regions = [region_def], items = [reg_seq]) 
     

    -Matt