object_store_joined

This commit is contained in:
Andres Rodriguez 2013-07-01 14:28:39 -04:00
parent 44dddaee7e
commit 821c72d35c
5 changed files with 42 additions and 24 deletions

View File

@ -32,6 +32,21 @@ class CephContext(OSContextGenerator):
} }
class ObjectStoreContext(OSContextGenerator):
interfaces = ['object-store']
def __call__(self):
"""
Used to generate template context to be added to glance-api.conf in
the presence of a 'object-store' relation.
"""
if not relantion_ids('object-store'):
return {}
return {
'swift_store': True,
}
class HAProxyContext(OSContextGenerator): class HAProxyContext(OSContextGenerator):
interfaces = ['ceph'] interfaces = ['ceph']

View File

@ -158,33 +158,17 @@ def image_service_joined(relation_id=None):
def object_store_joined(): def object_store_joined():
relids = relation_ids('identity-service')
if not relids: if 'identity-service' not in CONFIGS.complete_contexts():
juju_log('INFO', 'Deferring swift stora configuration until ' \ juju_log('INFO', 'Deferring swift stora configuration until ' \
'an identity-service relation exists') 'an identity-service relation exists')
return return
set_or_update(key='default_store', value='swift', file='api') if 'object-store' not in CONFIGS.complete_contexts():
set_or_update(key='swift_store_create_container_on_put', value=True, file='api') juju_log('INFO', 'swift relation incomplete')
return
for rid in relids: CONFIGS.write('/etc/glance/glance-api.conf')
for unit in relation_list(rid=rid):
svc_tenant = relation_get(attribute='service_tenant', rid=rid, unit=unit)
svc_username = relation_get(attribute='service_username', rid=rid, unit=unit)
svc_password = relation_get(attribute='service_passwod', rid=rid, unit=unit)
auth_host = relation_get(attribute='private-address', rid=rid, unit=unit)
port = relation_get(attribute='service_port', rid=rid, unit=unit)
if auth_host and port:
auth_url = "http://%s:%s/v2.0" % (auth_host, port)
if svc_tenant and svc_username:
value = "%s:%s" % (svc_tenant, svc_username)
set_or_update(key='swift_store_user', value=value, file='api')
if svc_password:
set_or_update(key='swift_store_key', value=svc_password, file='api')
if auth_url:
set_or_update(key='swift_store_auth_address', value=auth_url, file='api')
restart('glance-api') restart('glance-api')

View File

@ -51,7 +51,8 @@ CONFIG_FILES = OrderedDict([
('/etc/glance/glance-api.conf', { ('/etc/glance/glance-api.conf', {
'hook_contexts': [context.SharedDBContext(), 'hook_contexts': [context.SharedDBContext(),
context.IdentityServiceContext(), context.IdentityServiceContext(),
glance_contexts.CephContext()], glance_contexts.CephContext(),
glance_contexts.ObjectStoreContext()],
'services': ['glance-api'] 'services': ['glance-api']
}), }),
('/etc/glance/glance-api-paste.ini', { ('/etc/glance/glance-api-paste.ini', {

View File

@ -3,6 +3,8 @@ verbose = True
debug = True debug = True
{% if rbd_pool %} {% if rbd_pool %}
default_store = rbd default_store = rbd
{% elif swift_store %}
default_store = swift
{% else %} {% else %}
default_store = file default_store = file
{% endif %} {% endif %}
@ -41,11 +43,18 @@ qpid_protocol = tcp
qpid_tcp_nodelay = True qpid_tcp_nodelay = True
filesystem_store_datadir = /var/lib/glance/images/ filesystem_store_datadir = /var/lib/glance/images/
swift_store_auth_version = 2 swift_store_auth_version = 2
{% if swift_store %}
swift_store_auth_address = http://{{ service_host }}:{{ service_port }}/v2.0/
swift_store_user = {{ admin_tenant_name }}:{{ admin_user }}
swift_store_key = {{ admin_password }}
swift_store_create_container_on_put = True
{% else %}
swift_store_auth_address = 127.0.0.1:35357/v2.0/ swift_store_auth_address = 127.0.0.1:35357/v2.0/
swift_store_user = jdoe:jdoe swift_store_user = jdoe:jdoe
swift_store_key = a86850deb2742ec3cb41518e26aa2d89 swift_store_key = a86850deb2742ec3cb41518e26aa2d89
swift_store_container = glance
swift_store_create_container_on_put = False swift_store_create_container_on_put = False
{% endif %}
swift_store_container = glance
swift_store_large_object_size = 5120 swift_store_large_object_size = 5120
swift_store_large_object_chunk_size = 200 swift_store_large_object_chunk_size = 200
swift_enable_snet = False swift_enable_snet = False

View File

@ -3,6 +3,8 @@ verbose = True
debug = True debug = True
{% if rbd_pool %} {% if rbd_pool %}
default_store = rbd default_store = rbd
{% elif swift_store %}
default_store = swift
{% else %} {% else %}
default_store = file default_store = file
{% endif %} {% endif %}
@ -48,11 +50,18 @@ qpid_protocol = tcp
qpid_tcp_nodelay = True qpid_tcp_nodelay = True
filesystem_store_datadir = /var/lib/glance/images/ filesystem_store_datadir = /var/lib/glance/images/
swift_store_auth_version = 2 swift_store_auth_version = 2
{% if swift_store %}
swift_store_auth_address = http://{{ service_host }}:{{ service_port }}/v2.0/
swift_store_user = {{ admin_tenant_name }}:{{ admin_user }}
swift_store_key = {{ admin_password }}
swift_store_create_container_on_put = True
{% else %}
swift_store_auth_address = 127.0.0.1:5000/v2.0/ swift_store_auth_address = 127.0.0.1:5000/v2.0/
swift_store_user = jdoe:jdoe swift_store_user = jdoe:jdoe
swift_store_key = a86850deb2742ec3cb41518e26aa2d89 swift_store_key = a86850deb2742ec3cb41518e26aa2d89
swift_store_container = glance
swift_store_create_container_on_put = False swift_store_create_container_on_put = False
{% endif %}
swift_store_container = glance
swift_store_large_object_size = 5120 swift_store_large_object_size = 5120
swift_store_large_object_chunk_size = 200 swift_store_large_object_chunk_size = 200
swift_enable_snet = False swift_enable_snet = False