Adds an option to specify the glance endpoint type

Some environments that utilize an SSL terminator with a self-signed
certificate can use the publicURL without getting certificate
verify errors.  This allows using the internalURL with in my case
is HTTP and not HTTPS.

Closes issue: #8057
This commit is contained in:
Eric Brown 2014-07-08 00:30:40 -07:00
parent 0a33ac418a
commit 7bbe3dc30c

View file

@ -104,6 +104,12 @@ options:
- The path to the file which has to be uploaded, mutually exclusive with copy_from - The path to the file which has to be uploaded, mutually exclusive with copy_from
required: false required: false
default: None default: None
endpoint_type:
description:
- endpoint URL type
choices: [publicURL, internalURL]
required: false
default: publicURL
requirements: ["glanceclient", "keystoneclient"] requirements: ["glanceclient", "keystoneclient"]
''' '''
@ -127,6 +133,7 @@ try:
except ImportError: except ImportError:
print("failed=True msg='glanceclient and keystone client are required'") print("failed=True msg='glanceclient and keystone client are required'")
def _get_ksclient(module, kwargs): def _get_ksclient(module, kwargs):
try: try:
client = ksclient.Client(username=kwargs.get('login_username'), client = ksclient.Client(username=kwargs.get('login_username'),
@ -138,17 +145,18 @@ def _get_ksclient(module, kwargs):
return client return client
def _get_endpoint(module, client): def _get_endpoint(module, client, endpoint_type):
try: try:
endpoint = client.service_catalog.url_for(service_type='image', endpoint_type='publicURL') endpoint = client.service_catalog.url_for(service_type='image', endpoint_type=endpoint_type)
except Exception, e: except Exception, e:
module.fail_json(msg="Error getting endpoint for glance: %s" % e.message) module.fail_json(msg="Error getting endpoint for glance: %s" % e.message)
return endpoint return endpoint
def _get_glance_client(module, kwargs): def _get_glance_client(module, kwargs):
_ksclient = _get_ksclient(module, kwargs) _ksclient = _get_ksclient(module, kwargs)
token = _ksclient.auth_token token = _ksclient.auth_token
endpoint =_get_endpoint(module, _ksclient) endpoint =_get_endpoint(module, _ksclient, kwargs.get('endpoint_type'))
kwargs = { kwargs = {
'token': token, 'token': token,
} }
@ -158,6 +166,7 @@ def _get_glance_client(module, kwargs):
module.fail_json(msg="Error in connecting to glance: %s" % e.message) module.fail_json(msg="Error in connecting to glance: %s" % e.message)
return client return client
def _glance_image_present(module, params, client): def _glance_image_present(module, params, client):
try: try:
for image in client.images.list(): for image in client.images.list():
@ -167,6 +176,7 @@ def _glance_image_present(module, params, client):
except Exception, e: except Exception, e:
module.fail_json(msg="Error in fetching image list: %s" % e.message) module.fail_json(msg="Error in fetching image list: %s" % e.message)
def _glance_image_create(module, params, client): def _glance_image_create(module, params, client):
kwargs = { kwargs = {
'name': params.get('name'), 'name': params.get('name'),
@ -194,6 +204,7 @@ def _glance_image_create(module, params, client):
else: else:
module.fail_json(msg=" The module timed out, please check manually " + image.status) module.fail_json(msg=" The module timed out, please check manually " + image.status)
def _glance_delete_image(module, params, client): def _glance_delete_image(module, params, client):
try: try:
for image in client.images.list(): for image in client.images.list():
@ -203,6 +214,7 @@ def _glance_delete_image(module, params, client):
module.fail_json(msg="Error in deleting image: %s" % e.message) module.fail_json(msg="Error in deleting image: %s" % e.message)
module.exit_json(changed=True, result="Deleted") module.exit_json(changed=True, result="Deleted")
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
@ -222,6 +234,7 @@ def main():
copy_from = dict(default= None), copy_from = dict(default= None),
timeout = dict(default=180), timeout = dict(default=180),
file = dict(default=None), file = dict(default=None),
endpoint_type = dict(default='publicURL', choices=['publicURL', 'internalURL']),
state = dict(default='present', choices=['absent', 'present']) state = dict(default='present', choices=['absent', 'present'])
), ),
mutually_exclusive = [['file','copy_from']], mutually_exclusive = [['file','copy_from']],
@ -246,4 +259,3 @@ def main():
# this is magic, see lib/ansible/module.params['common.py # this is magic, see lib/ansible/module.params['common.py
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
main() main()