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
This commit is contained in:
parent
04b8f75ffa
commit
46a6c28bb0
1 changed files with 10 additions and 9 deletions
|
@ -1300,15 +1300,16 @@ def get_connection_info(module):
|
|||
if not username:
|
||||
if not password:
|
||||
authfile = os.environ.get('ONE_AUTH')
|
||||
if authfile is not None:
|
||||
try:
|
||||
authstring = open(authfile, "r").read().rstrip()
|
||||
username = authstring.split(":")[0]
|
||||
password = authstring.split(":")[1]
|
||||
except BaseException:
|
||||
module.fail_json(msg="Could not read ONE_AUTH file")
|
||||
else:
|
||||
module.fail_json(msg="No Credentials are set")
|
||||
if authfile is None:
|
||||
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
|
||||
try:
|
||||
authstring = open(authfile, "r").read().rstrip()
|
||||
username = authstring.split(":")[0]
|
||||
password = authstring.split(":")[1]
|
||||
except (OSError, IOError):
|
||||
module.fail_json(msg=("Could not find or read ONE_AUTH file at '%s'" % authfile))
|
||||
except Exception:
|
||||
module.fail_json(msg=("Error occurs when read ONE_AUTH file at '%s'" % authfile))
|
||||
if not url:
|
||||
module.fail_json(msg="Opennebula API url (api_url) is not specified")
|
||||
from collections import namedtuple
|
||||
|
|
Loading…
Reference in a new issue