Forum Discussion
Smart way to convert a PoolMemberDefinitionSequenceSequence to a IPPortDefinitionSequenceSequence
Hi,
I want to dump out (and eventually read in and set) the enabled state of each of my GTM pools pool members. Its easy to get a list of the pools and pool members, but the PoolMember.get_enabled_state requires input parameters of the pools (simple) and a Common.IPPortDefinitionSequenceSequence. I'm having trouble figuring out the best way to programmatically get an IPPortDefinitionSequenceSequnce to pass in.
I have a PoolMemberDefinition named poolmembers loaded as follows:
wideips = wipobj.get_list()
pools = poolobj.get_list()
poolmembers = poolobj.get_member(pools)
I want to get the enabled state of each of the poolmembers. I should be able to loop through the poolmembers object and strip out each poolmember address and port and save it to another object (which would then be of type IPPortDefinition), but is that the best way?
thanks,
andy
- L4L7_53191NimbostratusAndy: give this a go.
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
- L4L7_53191NimbostratusForgot to add - change the wsdl to match yours (this example uses LocalLB.PoolMember..) .
- I'll give it a shot, but I'm not sure it will work. the crux of my problem is that the type returned for a GlobalLB poolmember object is not the same as the LocalLB poolmember object. The GlobalLB object includes the 'order' value of each pool which doesn't exist in an LTM.
- L4L7_53191NimbostratusAndy: I thought you were trying to create a Common.IPPortCombinantion sequencesequence, no? If so, just change it to wipobj.factory.create(...) instead of LocalLB.PoolMember or whatever. I have a feeling that I still don't understand what you're trying to do though...
- Hi Matt,
- L4L7_53191NimbostratusSo something like this?
In [11]: pool_list = pool.get_list() In [12]: states = pool.get_enabled_state(pool_list) In [13]: combined = zip(pool_list, states) In [14]: combined Out[14]: [(pc_test_pool, STATE_ENABLED)]
In[29]: pool.suds.factory.create('Common.EnabledState') In[30]: pool.set_enabled_state(pool_names = ['pc_test_pool'],states = [enabled_state.STATE_DISABLED]) In [31]: pool.get_enabled_state(plist) Out[31]: [STATE_DISABLED]
- you are doing pool state, i care about poolmember enabled state
- L4L7_53191NimbostratusThis is an example of how to do that with a GTM pool member:
enabled_state = pm.typefactory.create('GlobalLB.PoolMember.MemberEnabledState') enabled_state.member.address = '2.2.2.2' enabled_state.member.port = 80 enabled_state.state.value = 'STATE_DISABLED' enabled_state_seq = pm.typefactory.create('GlobalLB.PoolMember.MemberEnabledStateSequence') enabled_state_seq.items = [enabled_state] pm.set_enabled_state(pool_names = ['pc_test_pool'],states = [enabled_state_seq])
- L4L7_53191NimbostratusBy the way: since the enabled_state.member object is just a Common.IPPortSequence you can assign it to be another object of that type. That means you can query the enabled state of your pool members, then assign them:
current_state = pool.get_member(['pc_test_pool']) enabled_state.member = current_state[0][0].member pm.set_enabled_state(pool_names = ['pc_test_pool'],states = [enabled_state_seq])
- L4L7_53191NimbostratusYep, I see what you're doing now. Thanks for posting the whole thing it's much clearer. I see some definite areas to improve performance, but I'll need to fire up an environment and bang out some examples for you. Give me a few minutes and I'll get back with an example.
Recent Discussions
Related Content
* 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