mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Nova doesn't attempt to auth on obj instantiation
Need to call nova.authenticate() to validate credentials.
This commit is contained in:
parent
32986c4d64
commit
15613de6f5
2 changed files with 36 additions and 21 deletions
|
@ -2,6 +2,7 @@
|
|||
#coding: utf-8 -*-
|
||||
|
||||
# (c) 2013, Benno Joy <benno@ansibleworks.com>
|
||||
# (c) 2013, John Dewey <john@dewey.ws>
|
||||
#
|
||||
# This module is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,6 +19,7 @@
|
|||
|
||||
try:
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
from novaclient import exceptions
|
||||
import time
|
||||
except ImportError:
|
||||
print("failed=True msg='novaclient is required for this module'")
|
||||
|
@ -229,14 +231,18 @@ def main():
|
|||
),
|
||||
)
|
||||
|
||||
try:
|
||||
nova = nova_client.Client(module.params['login_username'],
|
||||
module.params['login_password'],
|
||||
module.params['login_tenant_name'],
|
||||
module.params['auth_url'],
|
||||
service_type='compute')
|
||||
except Exception as e:
|
||||
module.fail_json( msg = "Error in authenticating to nova: %s" % e.message)
|
||||
try:
|
||||
nova.authenticate()
|
||||
except exc.Unauthorized as e:
|
||||
module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message)
|
||||
except exc.AuthorizationFailure as e:
|
||||
module.fail_json(msg = "Unable to authorize user: %s" % e.message)
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
if not module.params['image_id']:
|
||||
module.fail_json( msg = "Parameter 'image_id' is required if state == 'present'")
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#coding: utf-8 -*-
|
||||
|
||||
# (c) 2013, Benno Joy <benno@ansibleworks.com>
|
||||
# (c) 2013, John Dewey <john@dewey.ws>
|
||||
#
|
||||
# This module is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,6 +19,7 @@
|
|||
|
||||
try:
|
||||
from novaclient.v1_1 import client
|
||||
from novaclient import exceptions
|
||||
import time
|
||||
except ImportError:
|
||||
print("failed=True msg='novaclient is required for this module to work'")
|
||||
|
@ -98,11 +100,18 @@ def main():
|
|||
),
|
||||
)
|
||||
|
||||
nova = nova_client.Client(module.params['login_username'],
|
||||
module.params['login_password'],
|
||||
module.params['login_tenant_name'],
|
||||
module.params['auth_url'],
|
||||
service_type='compute')
|
||||
try:
|
||||
nova = client.Client(module.params['login_username'], module.params['login_password'],
|
||||
module.params['login_tenant_name'], module.params['auth_url'], service_type='compute')
|
||||
except Exception as e:
|
||||
module.fail_json( msg = " Error in authenticating to nova: %s" % e.message)
|
||||
nova.authenticate()
|
||||
except exc.Unauthorized as e:
|
||||
module.fail_json(msg = "Invalid OpenStack Nova credentials.: %s" % e.message)
|
||||
except exc.AuthorizationFailure as e:
|
||||
module.fail_json(msg = "Unable to authorize user: %s" % e.message)
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
for key in nova.keypairs.list():
|
||||
if key.name == module.params['name']:
|
||||
|
|
Loading…
Reference in a new issue