[ionutbalutoiu, r=thedac] Adds additional variables to the image-service relation. These are available only when a relation with Swift object storage is present.

In case any charm needs to generate temporary URLs from Glance with Swift backend, it needs a temp-url-key which must be posted to Swift with the glance account. (Details: http://docs.openstack.org/liberty/config-reference/content/object-storage-tempurl.html)
This is needed for OpenStack Ironic charm (http://bazaar.launchpad.net/~cloudbaseit/charms/trusty/ironic/trunk/view/head:/hooks/ironic_context.py#L76), but might also be generally useful.
This commit is contained in:
David Ames 2015-11-02 10:10:22 -08:00
commit 3d8fc83e73
2 changed files with 41 additions and 0 deletions

View File

@ -26,6 +26,7 @@ from glance_utils import (
setup_ipv6,
REQUIRED_INTERFACES,
check_optional_relations,
swift_temp_url_key
)
from charmhelpers.core.hookenv import (
config,
@ -222,6 +223,13 @@ def image_service_joined(relation_id=None):
juju_log("%s: image-service_joined: To peer glance-api-server=%s" %
(CHARM, relation_data['glance-api-server']))
if ('object-store' in CONFIGS.complete_contexts() and
'identity-service' in CONFIGS.complete_contexts()):
relation_data.update({
'swift-temp-url-key': swift_temp_url_key(),
'swift-container': 'glance'
})
relation_set(relation_id=relation_id, **relation_data)
@ -238,6 +246,8 @@ def object_store_joined():
juju_log('swift relation incomplete')
return
[image_service_joined(rid) for rid in relation_ids('image-service')]
CONFIGS.write(GLANCE_API_CONF)

View File

@ -39,6 +39,7 @@ from charmhelpers.core.host import (
service_restart,
lsb_release,
write_file,
pwgen
)
from charmhelpers.contrib.openstack import (
@ -460,3 +461,33 @@ def check_optional_relations(configs):
return status_get()
else:
return 'unknown', 'No optional relations'
def swift_temp_url_key():
"""Generate a temp URL key, post it to Swift and return its value.
If it is already posted, the current value of the key will be returned.
"""
keystone_ctxt = context.IdentityServiceContext(service='glance',
service_user='glance')()
if not keystone_ctxt:
log('Missing identity-service relation. Skipping generation of '
'swift temporary url key.')
return
auth_url = '%s://%s:%s/v2.0/' % (keystone_ctxt['service_protocol'],
keystone_ctxt['service_host'],
keystone_ctxt['service_port'])
from swiftclient import client
swift_connection = client.Connection(
authurl=auth_url, user='glance', key=keystone_ctxt['admin_password'],
tenant_name=keystone_ctxt['admin_tenant_name'], auth_version='2.0')
account_stats = swift_connection.head_account()
if 'x-account-meta-temp-url-key' in account_stats:
log("Temp URL key was already posted.")
return account_stats['x-account-meta-temp-url-key']
temp_url_key = pwgen(length=64)
swift_connection.post_account(headers={'x-account-meta-temp-url-key':
temp_url_key})
return temp_url_key