PureStorage-OpenConnect / rest-client

Pure Storage FlashArray Python REST 1.X Client
BSD 2-Clause "Simplified" License
39 stars 23 forks source link

Adding Timeout Error catch #15

Open mgagliardo opened 5 years ago

mgagliardo commented 5 years ago

So testing the lib I found out there is no catching for timeout exception (i.e. the cluster is down, the IP is wrong, etc.), this PR fixes that.

>>> import urllib3
>>>
>>> from purestorage import FlashArray
>>> from purestorage import PureError
>>>
>>> urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
>>>
>>> timeout=10
>>> cluster="MYIP"
>>>
>>> try:
...     array = FlashArray(cluster, api_token="MY_TOKEN", request_kwargs={'timeout':timeout})
... except PureError as err:
...     print("PureError timeout while connecting to the cluster {0}. Error: {1}".format(cluster, err))
...

PureError timeout while connecting to the cluster MYIP. Error: PureError: HTTPSConnectionPool(host='MYIP', port=443): Max retries exceeded with url: /api/api_version (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f9a89b05128>, 'Connection to MYIP timed out. (connect timeout=10)'))