Merge pull request #37 from Mirantis/keystone_fixes

Keystone fixes
This commit is contained in:
Dmitry Shulyak 2015-07-20 12:34:40 +03:00
commit 94ad34c121
2 changed files with 88 additions and 90 deletions

View File

@ -118,9 +118,9 @@ def deploy():
signals.connect(node1, keystone_service_endpoint) signals.connect(node1, keystone_service_endpoint)
signals.connect(keystone_puppet, keystone_service_endpoint, { signals.connect(keystone_puppet, keystone_service_endpoint, {
'admin_token': 'admin_token', 'admin_token': 'admin_token',
'admin_port': 'keystone_admin_port', 'admin_port': ['admin_port', 'keystone_admin_port'],
'ip': ['keystone_host', 'admin_ip', 'internal_ip', 'public_ip'], 'ip': ['keystone_host', 'admin_ip', 'internal_ip', 'public_ip'],
'port': ['admin_port', 'internal_port', 'public_port'], 'port': ['internal_port', 'public_port'],
}) })
signals.connect(keystone_puppet, admin_tenant) signals.connect(keystone_puppet, admin_tenant)
@ -327,7 +327,7 @@ def undeploy():
'neutron_keystone_role', 'neutron_keystone_role',
'neutron_keystone_user', 'neutron_keystone_user',
'services_tenant', 'services_tenant',
#'keystone_service_endpoint', 'keystone_service_endpoint',
'admin_role', 'admin_role',
'admin_user', 'admin_user',
'admin_tenant', 'admin_tenant',
@ -338,7 +338,7 @@ def undeploy():
'mariadb_service1', 'mariadb_service1',
'openstack_rabbitmq_user', 'openstack_rabbitmq_user',
'openstack_vhost', 'openstack_vhost',
'rabbitmq1', 'rabbitmq_service1',
] ]
resources = map(resource.wrap_resource, db.get_list(collection=db.COLLECTIONS.resource)) resources = map(resource.wrap_resource, db.get_list(collection=db.COLLECTIONS.resource))
@ -376,7 +376,7 @@ def undeploy():
# actions.resource_action(resources['openstack_rabbitmq_user'], 'remove') # actions.resource_action(resources['openstack_rabbitmq_user'], 'remove')
# actions.resource_action(resources['openstack_vhost'], 'remove') # actions.resource_action(resources['openstack_vhost'], 'remove')
# actions.resource_action(resources['rabbitmq1'], 'remove') # actions.resource_action(resources['rabbitmq_service1'], 'remove')
db.clear() db.clear()

View File

@ -1,8 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copied from: https://github.com/openstack-ansible/openstack-ansible-modules/blob/master/keystone_service
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: keystone_service module: keystone_service
@ -124,116 +122,116 @@ def get_endpoint(keystone, name):
return endpoints[0] return endpoints[0]
def ensure_service_present(keystone, name, service_type, description, def ensure_present(keystone, name, service_type, description, public_url,
check_mode): internal_url, admin_url, region, check_mode):
""" Ensure the service is present and has the right values """ Ensure the service and its endpoint are present and have the right values.
Returns a pair, where the first element is a boolean that indicates Returns a tuple, where the first element is a boolean that indicates
a state change, and the second element is the service uuid, or None a state change, the second element is the service uuid (or None in
if running in check mode""" check mode), and the third element is the endpoint uuid (or None in
check mode)."""
# Fetch service and endpoint, if they exist.
service = None service = None
try:
service = get_service(keystone, name)
except:
# Service doesn't exist yet, we'll need to create one
pass
else:
# See if it matches exactly
if service.name == name and \
service.type == service_type and \
service.description == description:
# Same, no changes needed
return (False, service.id)
# At this point, we know we will need to make a change
if check_mode:
return (True, None)
if service is None:
service = keystone.services.create(name=name,
service_type=service_type,
description=description)
return (True, service.id)
else:
msg = "keystone v2 API doesn't support updating services"
raise ValueError(msg)
def ensure_endpoint_present(keystone, name, public_url, internal_url,
admin_url, region, check_mode):
""" Ensure the service endpoint is present and have the right values
Assumes the service object has already been created at this point"""
service = get_service(keystone, name)
endpoint = None endpoint = None
try: try: service = get_service(keystone, name)
endpoint = get_endpoint(keystone, name) except: pass
except: try: endpoint = get_endpoint(keystone, name)
# Endpoint doesn't exist yet, we'll need to create one except: pass
pass
else:
# See if it matches
if endpoint.publicurl == public_url and \
endpoint.adminurl == admin_url and \
endpoint.internalurl == internal_url and \
endpoint.region == region:
# Same, no changes needed changed = False
return (False, endpoint.id)
# At this point, we know we will need to make a change # Delete endpoint if it exists and doesn't match.
if check_mode: if endpoint is not None:
return (True, None) identical = endpoint.publicurl == public_url and \
endpoint.adminurl == admin_url and \
endpoint.internalurl == internal_url and \
endpoint.region == region
if not identical:
changed = True
ensure_endpoint_absent(keystone, name, check_mode)
endpoint = None
# Delete service and its endpoint if the service exists and doesn't match.
if service is not None:
identical = service.name == name and \
service.type == service_type and \
service.description == description
if not identical:
changed = True
ensure_endpoint_absent(keystone, name, check_mode)
endpoint = None
ensure_service_absent(keystone, name, check_mode)
service = None
# Recreate service, if necessary.
if service is None:
if not check_mode:
service = keystone.services.create(
name=name,
service_type=service_type,
description=description,
)
changed = True
# Recreate endpoint, if necessary.
if endpoint is None: if endpoint is None:
endpoint = keystone.endpoints.create(region=region, if not check_mode:
service_id=service.id, endpoint = keystone.endpoints.create(
publicurl=public_url, region=region,
adminurl=admin_url, service_id=service.id,
internalurl=internal_url) publicurl=public_url,
return (True, endpoint.id) adminurl=admin_url,
else: internalurl=internal_url,
msg = "keystone v2 API doesn't support updating endpoints" )
raise ValueError(msg) changed = True
if check_mode:
# In check mode, the service/endpoint uuids will be the old uuids,
# so omit them.
return changed, None, None
return changed, service.id, endpoint.id
def ensure_service_absent(keystone, name, check_mode): def ensure_service_absent(keystone, name, check_mode):
""" Ensure the service is absent""" """ Ensure the service is absent"""
try:
service = get_service(keystone, name)
if not check_mode:
keystone.services.delete(service.id)
return True
except KeyError:
# Service doesn't exist, so we're done.
return False
service = get_service(keystone, name)
keystone.services.delete(service.id)
return True
def ensure_endpoint_absent(keystone, name, check_mode): def ensure_endpoint_absent(keystone, name, check_mode):
""" Ensure the service endpoint """ """ Ensure the service endpoint """
endpoint = get_endpoint(keystone, name) try:
keystone.endpoints.delete(endpoint.id) endpoint = get_endpoint(keystone, name)
return True if not check_mode:
keystone.endpoints.delete(endpoint.id)
return True
except KeyError:
# Endpoint doesn't exist, so we're done.
return False
def dispatch(keystone, name, service_type, description, public_url, def dispatch(keystone, name, service_type, description, public_url,
internal_url, admin_url, region, state, check_mode): internal_url, admin_url, region, state, check_mode):
if state == 'present': if state == 'present':
(service_changed, service_id) = ensure_service_present(keystone, (changed, service_id, endpoint_id) = ensure_present(
name,
service_type,
description,
check_mode)
(endpoint_changed, endpoint_id) = ensure_endpoint_present(
keystone, keystone,
name, name,
service_type,
description,
public_url, public_url,
internal_url, internal_url,
admin_url, admin_url,
region, region,
check_mode) check_mode,
return dict(changed=service_changed or endpoint_changed, )
service_id=service_id, return dict(changed=changed, service_id=service_id, endpoint_id=endpoint_id)
endpoint_id=endpoint_id)
elif state == 'absent': elif state == 'absent':
endpoint_changed = ensure_endpoint_absent(keystone, name, check_mode) endpoint_changed = ensure_endpoint_absent(keystone, name, check_mode)
service_changed = ensure_service_absent(keystone, name, check_mode) service_changed = ensure_service_absent(keystone, name, check_mode)