Added swift-temp-url-key parameter needed when creating temporary urls from glance

This commit is contained in:
Ionut Balutoiu 2015-10-31 00:11:38 +02:00
parent 9b412f15f4
commit c08a78477f
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