Forum Discussion
andy_12_5042
Jul 19, 2011Nimbostratus
create a pool with members
For some reason I will hit these walls every once in a while as I have to keep wrapping my head around the best way to implement something with pycontrol.
I am trying to figure out the best way to create a pool with multiple members. I have built a web service that I want to be able to make call to create a pool with 1 or more members. The problem I am having is how do you feed in the member ip port definitions via a web call?
I can do this fine with what I will call a one off type script.. However, I need to instantiate an instance of a Common.IPPortDefinition for each member in a single call. I am sure this is not rocket science but this is where I am lacking in development experience. I am looking to get this to work dynamicall regardless of how many members are passed or pools.....
I am referring to something like this :
member1= b.LocalLB.PoolMember.typefactory.create('Common.IPPortDefinition')
member2= b.LocalLB.PoolMember.typefactory.create('Common.IPPortDefinition')
If anyone can point me in the right direction that would be great. One thing I have learned as I have been building stuff with pycontrol is that once I see the correct logic, I usually think wow that is so simple while I was trying to re-invent the wheel :)
love pycontrol and python in general!
thanks for any help
4 Replies
Sort By
- is feeding the members in as a list and then do some for loop logic in my web service the best way to do this or is the something better?
- getting closer but this is probably not the best way to go about it:
- Andy: have a look here for a helper function that will hopefully be of some value.
Note how the positional arguments are laid out: one is the BIGIP object, the other is ip:port combination you want to create the IPPortDefinition from. Fom here you could do something like (not tested, free form code below!):def member_factory(b, member): ''' Produces a Common.IPPortDefinition object per member ip:port combination object per member ip:port combination. Add these to Common.IPPortDefinitionSequence. args: a pycontrol LocalLB.PoolMember object and an ip:port combination that you'd like to add. ''' ip,port = member.split(':') pmem = b.LocalLB.PoolMember.typefactory.create('Common.IPPortDefinition') pmem.address = ip pmem.port = int(port) return pmem
members = ['10.10.10.20:80','10.10.10.30:80','10.10.10.40:80'] ipport_objects = [member_factory(b, x) for x in members]
- Sorry for delay in response. Yeah that is cleaner way to do this with a helper method in the same class. This makes the code easier and less clunky looking. I would rather
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