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

Regarding whitespaces #1094

Open himalayanBuddy opened 7 years ago

himalayanBuddy commented 7 years ago

I executed the following code:

if not bigip.tm.ltm.pools.pool.exists(name=poola_name, partition='Common'):
    bigip.tm.ltm.pools.pool.create(name=poola_name, partition='Common')

I had a pool already in LTM with same name. But f5-sdk threw out an error specifying that the poola_name already exist when it tried to execute create method which I had not expected.

Upon troubleshooting I figured out that my file for the pools had a whitespace at the end. So, looks like the exists method takes the name with whitespace. But when LTM tried to create the pool (May be it trims white space at that time) it figured out that the pool already exist and threw the error.

Traceback (most recent call last):
  File "create_virtual.py", line 54, in <module>
    bigip.tm.ltm.pools.pool.create(name=poola_name, partition='Common')
  File "C:\Python27\lib\site-packages\f5\bigip\resource.py", line 974, in create

    return self._create(**kwargs)
  File "C:\Python27\lib\site-packages\f5\bigip\resource.py", line 941, in _creat
e
    response = session.post(_create_uri, json=kwargs, **requests_params)
  File "C:\Python27\lib\site-packages\icontrol\session.py", line 272, in wrapper

    raise iControlUnexpectedHTTPError(error_message, response=response)
icontrol.exceptions.iControlUnexpectedHTTPError: 409 Unexpected Error: Conflict
for uri: https://172.22.10.5:443/mgmt/tm/ltm/pool/
Text: u'{"code":409,"message":"01020066:3: The requested Pool (/Common/sameweb-80-apool) already exists in partition Common.","errorStack":[]}'

Can't f5-sdk trim whitespaces as it is obvious that LTM trims whitespace while creating objects.

caphrim007 commented 7 years ago

@harishpokharel i think this is probably a valid feature request.

caphrim007 commented 7 years ago

@harishpokharel I'm not familiar enough with the BIG-IP UI to know what all forms it does this on though, we'll cover your use case of pools as a place to start and then address others in the future.