f5-common-python icon indicating copy to clipboard operation
f5-common-python copied to clipboard

Provide a similar function as expandSubcollections when calling get_collection()

Open jobec opened this issue 7 years ago • 4 comments

Provide a similar function as expandSubcollections=true from the REST api when calling get_collection(). When you have hundreds of pools across a couple of vCMP guests, you get an enormous scaling issue.

The below code would make 101 API calls if there were 100 pools

from f5.bigip import ManagementRoot
mgmt = ManagementRoot('10.10.10.10', 'admin', 'admin')
pools = mgmt.tm.ltm.pools.get_collection()
for pool in pools:
    print(pool.name)
    for member in pool.members_s.get_collection():
         print(member.name)

While code like this, would one do 2 calls if it queried for all pool members at once.

from f5.bigip import ManagementRoot
mgmt = ManagementRoot('10.10.10.10', 'admin', 'admin')
pools = mgmt.tm.ltm.pools.get_collection(expand_subcollections=True)
for pool in pools:
    print(pool.name)
    for member in pool.members:
         print(member.name)

You can currently hack your way around it but it defeats all use for the sdk.

from f5.bigip import ManagementRoot
mgmt = ManagementRoot('10.10.10.10', 'admin', 'admin')
pools = mgmt.tm.ltm.pools.get_collection(requests_params={'params': {'expandSubcollections':'true'}})
for pool in pools:
    print(pool.name)
    for member in pool.membersReference['items']:
         print(member['name'])

jobec avatar Mar 08 '17 14:03 jobec

@jobec, thats not a hack, thats the way to send different params to a subcollection. Its the same method one would use to send odata filters.

The way I'm interpreting the issue here is

  1. Make the expand subcollection boolean less verbose
  2. Make the expanded subcollections available in object form

Does that sound correct?

caphrim007 avatar Mar 08 '17 14:03 caphrim007

Yes, that's correct.

jobec avatar Mar 09 '17 07:03 jobec

@wojtek0806 I don't think the first bullet there is an unreasonable ask. I've experienced the same frustration in the past and if it's a common usage, which I believe it is, then it should have a way to get to it without hassle.

Also I think the expandSubcollections in BIG-IQ and iWorkflow are called something completely different (i think its just expand=true). Having this param act as an abstraction would allow us to make the user experience consistent.

The second ask about the objection creation, could get a little hairy. I'm not sure what would be required to do that. Although I haven't taken a gander at that part of the code in some time.

caphrim007 avatar Mar 09 '17 08:03 caphrim007

@caphrim007 I will try to look into this next week, as the first ask is not a problem like you said, the second might be near impossible, given the way we instantiate sub-collections, but let me have a look, might turn out otherwise and be very simple :)

wojtek0806 avatar Mar 09 '17 09:03 wojtek0806