use ~/.one/one_auth as default of ONE_AUTH file location (#64535)

* better excpetion handling when one_auth file is missing
* use Exception instead of BaseException
pull/64832/head
Youhua Li 6 years ago committed by Abhijeet Kasurde
parent 04b8f75ffa
commit 46a6c28bb0

@ -1300,15 +1300,16 @@ def get_connection_info(module):
if not username: if not username:
if not password: if not password:
authfile = os.environ.get('ONE_AUTH') authfile = os.environ.get('ONE_AUTH')
if authfile is not None: if authfile is None:
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
try: try:
authstring = open(authfile, "r").read().rstrip() authstring = open(authfile, "r").read().rstrip()
username = authstring.split(":")[0] username = authstring.split(":")[0]
password = authstring.split(":")[1] password = authstring.split(":")[1]
except BaseException: except (OSError, IOError):
module.fail_json(msg="Could not read ONE_AUTH file") module.fail_json(msg=("Could not find or read ONE_AUTH file at '%s'" % authfile))
else: except Exception:
module.fail_json(msg="No Credentials are set") module.fail_json(msg=("Error occurs when read ONE_AUTH file at '%s'" % authfile))
if not url: if not url:
module.fail_json(msg="Opennebula API url (api_url) is not specified") module.fail_json(msg="Opennebula API url (api_url) is not specified")
from collections import namedtuple from collections import namedtuple

Loading…
Cancel
Save