F5Networks / f5-common-python

Python SDK for configuration and monitoring of F5® BIG-IP® devices via the iControl® REST API.
https://f5-sdk.readthedocs.org
Apache License 2.0
262 stars 135 forks source link

Provide a similar function as expandSubcollections when calling get_collection() #1038

Open jobec opened 7 years ago

jobec commented 7 years ago

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'])
caphrim007 commented 7 years ago

@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?

jobec commented 7 years ago

Yes, that's correct.

caphrim007 commented 7 years ago

@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.

wojtek0806 commented 7 years ago

@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 :)