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 134 forks source link

Unable to check if the GSLB pool member "exists" using SDK and get the member configuration using "load" #1522

Closed manojk011 closed 5 years ago

manojk011 commented 5 years ago

I am trying to check if the pool member exists in a GSLB pool using SDK.

I have created a GSLB pool with name - "gslb_pool" and have added and added LTM server with name and can see that all the vip's in the LTM are being discovered.

url to make actual get call is - https://xx.x.xxx.xx:xxx/mgmt/tm/gtm/pool/a/~Common~gslb_pool/members/~Common~sanjoseltm:~Common~createdwetwo

By using the subPath option, I was able to provide all the details which SDK can use to construct the actual url but it misses to add the tilda sign (~) and also avoids me to add a tilda sign (~) in the subPath.

command used:
gslbpool.members_s.member.exists(name='createdwetwo',partition="Common", subPath="sanjoseltm:Common")

URL constructed:
https://xx.x.xxx.xx:xxx/mgmt/tm/gtm/pool/a/~Common~gslb_pool/members/~Common~sanjoseltm:Common~createdwetwo

Since we cannot use special characters in the subPath, the above method makes a service call to

~Common~sanjoseltm:Common~createdwetwo instead of
~Common~sanjoseltm:~Common~createdwetwo

Thus, there is no way we can use exists or load method for checking or getting the member details of a GSLB pool.

After debugging and going through the BIG IP f5-dns SDK, this is the only way to check weather the pool member exists:

workaround 1: Step 1. Get the collection using below code:

   gslbpool = mgmt.tm.gtm.pools.a_s.a.load(name="gslb_pool",partition="Common")

Step 2. Iterate through the gslb pool collection and check whether it exists. Pass the path in the suffix while using exists or loads:

workaround 2: Instead of using the above steps other way to check is to pass the path of the member and pass it as suffix as below:

if gslbpool.members_s.member.exists(suffix="**/~Common~sanjoseltm:~Common~createdwetwo**", name=""):

I believe this is a bug and needs to be fixed so that developers can use the SDK for GSLB functions as well. Please let me know if I have missed something and there are other ways to do this.

In short:

With current version of SDK, we are not able to use "exists", "load" methods to check if the GSLB pool member exists and get the configuration of a pool member.

jasonrahm commented 5 years ago

can you put your code specifics in a code block? Some stuff is being rendered incorrectly, making it difficult to figure out what your problem is @manojk011

manojk011 commented 5 years ago

can you put your code specifics in a code block? Some stuff is being rendered incorrectly, making it difficult to figure out what your problem is @manojk011

jasonrahm commented 5 years ago

@manojk011 this looks to be a problem with the underlying icontrol rest library the SDK uses. If I tweak the subPath it works fine, but provided as is, I get the error where the folder "/" is not translated to a "~".

Need to research what my options are, I'll dig in to this tomorrow when I get back from vacation.

gp.members_s.member.exists(name='v1', subPath='ltm3.test.local:~part1', partition='Common')
True
gp.members_s.member.exists(name='v1', subPath='ltm3.test.local:/part1', partition='Common')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/rahm/Documents/PycharmProjects/f5-common-python/f5/bigip/tm/gtm/pool.py", line 316, in exists
    return self._exists(**kwargs)
  File "/Users/rahm/Documents/PycharmProjects/f5-common-python/f5/bigip/resource.py", line 1187, in _exists
    session.get(base_uri, **kwargs)
  File "/Users/rahm/Documents/PycharmProjects/f5-common-python/f5py3/lib/python3.7/site-packages/icontrol/session.py", line 284, in wrapper
    raise iControlUnexpectedHTTPError(error_message, response=response)
icontrol.exceptions.iControlUnexpectedHTTPError: 400 Unexpected Error: Bad Request for uri: https://ltm3.test.local:443/mgmt/tm/gtm/pool/a/~part1~p1/members/~Common~ltm3.test.local:/part1~v1
Text: '{"code":400,"message":"Found unexpected URI tmapi_mapper/gtm/pool/a/~part1~p1/members/~Common~ltm3.test.local:/part1~v1.","errorStack":[],"apiError":1}'
jasonrahm commented 5 years ago

This issue belongs to the underlying f5-icontrol-rest-python module. I opened an issue there you can track.

jasonrahm commented 5 years ago

@manojk011, I released 1.3.12 of the icontrol library, so if you upgrade that sdk dependency, you can now use transform_subpath=True and exists should work for you.

manojk011 commented 5 years ago

Thank you Jason. I will test it out.

Regards Manoj

On Mon, Apr 1, 2019 at 5:20 PM Jason Rahm notifications@github.com wrote:

@manojk011 https://github.com/manojk011, I released 1.3.12 of the icontrol library, so if you upgrade that sdk dependency, you can now use transform_subpath=True and exists should work for you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/F5Networks/f5-common-python/issues/1522#issuecomment-478794365, or mute the thread https://github.com/notifications/unsubscribe-auth/AoxlmcuVq2eDmrsDYUVnoAG8gvRDlQ5Lks5vcqJJgaJpZM4bpe7g .