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
21 Replies
- L4L7_53191
Nimbostratus
Andy: 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
HTH,
-Matt - L4L7_53191
Nimbostratus
Forgot to add - change the wsdl to match yours (this example uses LocalLB.PoolMember..) .
To pass in a squencesequence, create your sequence first, then append the list of your members to sequence.items = []. Then simply wrap that in a list, e.g.
seqseq = [ your_member_sequence ]
I'll be back in front of the computer in a bit and can follow up with any questions.
-Matt - 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_53191
Nimbostratus
Andy: 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...
-Matt - Hi Matt,
I'm not trying to create, I'm trying to convert.
but I could be approaching it incorrectly. The end goal is to be able to print|set the enabled state of a GTM pool member. here are the params and response type for the GlobalLB.PoolMember.get_enabled_state method:
poolmemobj = b.GlobalLB.PoolMember
In [69]: poolmemobj.get_enabled_state.params
Out[69]:
[(pool_names, u'Common.StringSequence'),
(members, u'Common.IPPortDefinitionSequenceSequence')]
In [70]: poolmemobj.get_enabled_state.response_type
Out[70]: u'GlobalLB.PoolMember.MemberEnabledStateSequenceSequence'
so the immediate problem i'm trying to solve is the best way to create/convert a GTM object into a Common.IPPortDefinitionSequenceSequence. where i'm having trouble is that if I use the GlobalLB.Pool.get_member method to create a list of pool members, the resulting object is of type PoolMemberDefinitionSequenceSequence, which is NOT the same as an IPPortDefinitionSequenceSequence. Each object(?) in the PoolMemberDefinitionSequence has one or more address/port values, but also an order value which seems to be the main differentiator from an IPPortDefinition.
so i'm asking if looping through a PoolMemberDefinitionSequenceSequence to strip off the 'order' value and create/fill a new IPPortDefinitionSequenceSequence that I can then pass into the GlobalLB.PoolMember.get_enabled_state method is the best way to do things.
make sense? - L4L7_53191
Nimbostratus
So 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)]
followed by: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]
Let me know if that's what you're after...this was done against the GlobalLB.Pool wsdl.
-Matt - you are doing pool state, i care about poolmember enabled state
- L4L7_53191
Nimbostratus
This 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])
-Matt - L4L7_53191
Nimbostratus
By 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:
e.g.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])
In other words, we're dealing with plain old python attributes, which is nice!
-Matt - L4L7_53191
Nimbostratus
Yep, 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.
-Matt
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
