Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26 from UpCloudLtd/fix/default_timeout_as_float
Browse files Browse the repository at this point in the history
fix: add float conversion for default timeout
  • Loading branch information
Turo committed Oct 23, 2020
2 parents 13b6806 + 4b1ecb3 commit 5914710
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions inventory/upcloud.py
Expand Up @@ -232,9 +232,11 @@ def read_api_credentials(config):

# setup API connection
username, password = read_api_credentials(config)
default_timeout = os.getenv('UPCLOUD_API_TIMEOUT')
default_timeout = os.getenv('UPCLOUD_API_TIMEOUT') or config.get('upcloud', 'default_timeout')
if not default_timeout:
default_timeout = config.get('upcloud', 'default_timeout') or None
default_timeout = None
else:
default_timeout = float(default_timeout)
manager = upcloud_api.CloudManager(username, password, default_timeout)

# decide whether to return hostnames or ip_addresses
Expand Down
10 changes: 5 additions & 5 deletions modules/upcloud.py
Expand Up @@ -149,6 +149,7 @@

from distutils.version import LooseVersion
import os
import ConfigParser

# make sure that upcloud-api is installed
HAS_UPCLOUD = True
Expand Down Expand Up @@ -305,26 +306,25 @@ def main():
),
)


# ensure dependencies and API credentials are in place
#

if not HAS_UPCLOUD:
module.fail_json(msg='upcloud-api required for this module (`pip install upcloud-api`)')

api_user = module.params.get('api_user') or os.getenv('UPCLOUD_API_USER')
api_passwd = module.params.get('api_passwd') or os.getenv('UPCLOUD_API_PASSWD')
default_timeout = os.getenv('UPCLOUD_API_TIMEOUT')

if not default_timeout:
default_timeout = module.params.get('upcloud', 'default_timeout') or None
default_timeout = 300
else:
default_timeout = float(default_timeout)

if not api_user or not api_passwd:
module.fail_json(msg='''Please set UPCLOUD_API_USER and UPCLOUD_API_PASSWD environment variables or provide api_user and api_passwd arguments.''')


# begin execution. Catch all unhandled exceptions.
# Note: UpCloud's API has good error messages that the api client passes on.
#

server_manager = ServerManager(api_user, api_passwd, default_timeout)
try:
Expand Down

0 comments on commit 5914710

Please sign in to comment.