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:
try: authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
authstring = open(authfile, "r").read().rstrip() try:
username = authstring.split(":")[0] authstring = open(authfile, "r").read().rstrip()
password = authstring.split(":")[1] username = authstring.split(":")[0]
except BaseException: password = authstring.split(":")[1]
module.fail_json(msg="Could not read ONE_AUTH file") except (OSError, IOError):
else: module.fail_json(msg=("Could not find or read ONE_AUTH file at '%s'" % authfile))
module.fail_json(msg="No Credentials are set") except Exception:
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