Forum Discussion
bdavidfr_8739
Jun 20, 2010Historic F5 Account
pyControl with GTM to add member into Pool
Hi,
I try to use pyControl to add member to a Pool on GTM. I used the following code :
print 'Adding the new VS to the Pool'
p = b.GlobalLB.Pool
IpPortDef = [{'address' : SRV_Addr, 'port' : 80 }]
New_Member =[[{'member' : IpPortDef, 'order' : 1}]]
print New_Member
p.add_member( pool_names = Wide_Ip_Pool_Name , members = New_Member)
But I always receive :
Error Adding VS to Pool
Server raised fault: 'Could not find element by name: member'
Could somebody can help me ?????
1 Reply
- L4L7_53191
Nimbostratus
I have a feeling I know what is going on. The issue is that the ‘members’ keyword actually needs a ‘sequencesequence’, which you’ve tried to represent by a nested list:members=[[PMD]]
This is very reasonable and a natural way to try to do this. But unfortunately the issue is that Suds can’t extrapolate what kind of object you’re really trying to pass, so it’s not able to create the XML tree to represent it. What you need to do is coerce Suds into making the correct object structure. Here’s how.
Printing out the params attribute for the create() or add_member() methods, you can see this:
In [6]: b.GlobalLB.Pool.add_member.params
Out[6]:
[(pool_names, u'Common.StringSequence'),
(members, u'GlobalLB.Pool.PoolMemberDefinitionSequenceSequence')]
So here is what to do: Create the sequence type, add your pool member definition, then put the sequence object inside a list.In [14]: seq = b.GlobalLB.Pool.typefactory.create('GlobalLB.Pool.PoolMemberDefinitionSequence') In [14]: seq.items = [] Make an attribute called ‘items’ that is a list object.
Then:seq.items.append(PMD) add the PMD to this list object.
Then call it like this:
b.GlobalLB.Pool.add_member(pool_names=[Wide_Ip_Pool_Name], members=[seq])
So the pool member definition sequence is now a real object, wrapped in a list (a sequencesequence!).
At some point I want to look at writing some helpers for this type of use case. IMO the iControl API is complicated with this stuff because it allows users to create multiple objects. So a PoolMemberDefinitionSequence translates to: a list of pool members. A 'GlobalLB.Pool.PoolMemberDefinitionSequenceSequence’ is a list of pool member sequences, which have pool member objects inside of them.
I know it’s confusing – it is for me too. Sorry for that. One day I’ll try and create a wrapper for it and simplify things via a ‘shortcuts’ api or some such thing. But I need to think carefully about it because it’s easy to make bad assumptions and break stuff. If any of you have ideas on a non-brittle way to do this please let me know; I'd love the input.
HTH,
-Matt
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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