2011-12-08 09:52:12 -08:00
|
|
|
#!/usr/bin/python
|
2012-02-29 11:59:37 -08:00
|
|
|
|
|
|
|
import time
|
2013-02-14 15:20:54 -08:00
|
|
|
import urlparse
|
2012-10-02 17:36:25 -07:00
|
|
|
|
2013-02-07 21:03:44 -08:00
|
|
|
from base64 import b64encode
|
2012-10-02 17:36:25 -07:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
from keystone_utils import (
|
2013-04-04 19:35:06 -04:00
|
|
|
config_dirty,
|
2013-03-18 12:56:57 +00:00
|
|
|
config_get,
|
|
|
|
execute,
|
|
|
|
update_config_block,
|
|
|
|
set_admin_token,
|
|
|
|
ensure_initial_admin,
|
|
|
|
create_service_entry,
|
|
|
|
create_endpoint_template,
|
|
|
|
create_role,
|
|
|
|
get_admin_token,
|
|
|
|
get_service_password,
|
|
|
|
create_user,
|
|
|
|
grant_role,
|
|
|
|
get_ca,
|
|
|
|
synchronize_service_credentials,
|
|
|
|
do_openstack_upgrade,
|
|
|
|
configure_pki_tokens,
|
|
|
|
SSH_USER,
|
|
|
|
SSL_DIR,
|
2013-03-19 13:41:27 +00:00
|
|
|
CLUSTER_RES,
|
|
|
|
https
|
2013-03-18 12:56:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
from lib.openstack_common import (
|
|
|
|
get_os_codename_install_source,
|
|
|
|
get_os_codename_package,
|
|
|
|
get_os_version_codename,
|
|
|
|
get_os_version_package,
|
|
|
|
save_script_rc
|
|
|
|
)
|
2013-02-12 21:56:39 -08:00
|
|
|
import lib.unison as unison
|
2013-03-18 12:56:57 +00:00
|
|
|
import lib.utils as utils
|
|
|
|
import lib.cluster_utils as cluster
|
|
|
|
import lib.haproxy_utils as haproxy
|
2011-12-08 09:52:12 -08:00
|
|
|
|
|
|
|
config = config_get()
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
packages = [
|
|
|
|
"keystone", "python-mysqldb", "pwgen",
|
2013-05-22 11:15:37 +01:00
|
|
|
"haproxy", "python-jinja2", "openssl", "unison",
|
|
|
|
"python-sqlalchemy"
|
2013-03-18 12:56:57 +00:00
|
|
|
]
|
2011-12-08 09:52:12 -08:00
|
|
|
service = "keystone"
|
|
|
|
|
|
|
|
# used to verify joined services are valid openstack components.
|
2011-12-23 17:34:15 -08:00
|
|
|
# this should reflect the current "core" components of openstack
|
|
|
|
# and be expanded as we add support for them as a distro
|
2011-12-08 09:52:12 -08:00
|
|
|
valid_services = {
|
|
|
|
"nova": {
|
|
|
|
"type": "compute",
|
|
|
|
"desc": "Nova Compute Service"
|
|
|
|
},
|
2012-03-08 14:38:36 -08:00
|
|
|
"nova-volume": {
|
|
|
|
"type": "volume",
|
|
|
|
"desc": "Nova Volume Service"
|
|
|
|
},
|
2012-10-02 17:36:25 -07:00
|
|
|
"cinder": {
|
|
|
|
"type": "volume",
|
|
|
|
"desc": "Cinder Volume Service"
|
|
|
|
},
|
2012-03-01 12:35:39 -08:00
|
|
|
"ec2": {
|
|
|
|
"type": "ec2",
|
|
|
|
"desc": "EC2 Compatibility Layer"
|
|
|
|
},
|
2011-12-08 09:52:12 -08:00
|
|
|
"glance": {
|
|
|
|
"type": "image",
|
|
|
|
"desc": "Glance Image Service"
|
2011-12-21 15:29:31 -08:00
|
|
|
},
|
2012-04-13 17:24:56 -07:00
|
|
|
"s3": {
|
|
|
|
"type": "s3",
|
|
|
|
"desc": "S3 Compatible object-store"
|
|
|
|
},
|
2011-12-21 15:29:31 -08:00
|
|
|
"swift": {
|
2012-12-11 12:25:11 -08:00
|
|
|
"type": "object-store",
|
2011-12-21 15:29:31 -08:00
|
|
|
"desc": "Swift Object Storage Service"
|
2012-12-03 15:34:43 +00:00
|
|
|
},
|
|
|
|
"quantum": {
|
|
|
|
"type": "network",
|
|
|
|
"desc": "Quantum Networking Service"
|
2013-01-21 09:05:12 -06:00
|
|
|
},
|
|
|
|
"oxygen": {
|
|
|
|
"type": "oxygen",
|
|
|
|
"desc": "Oxygen Cloud Image Service"
|
2013-01-31 12:55:04 +01:00
|
|
|
},
|
|
|
|
"ceilometer": {
|
|
|
|
"type": "metering",
|
|
|
|
"desc": "Ceilometer Metering Service"
|
2011-12-08 09:52:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
def install_hook():
|
2013-03-18 13:52:29 +00:00
|
|
|
utils.configure_source()
|
2013-03-18 13:42:43 +00:00
|
|
|
utils.install(*packages)
|
2013-03-18 12:56:57 +00:00
|
|
|
update_config_block('DEFAULT',
|
|
|
|
public_port=cluster.determine_api_port(config["service-port"]))
|
|
|
|
update_config_block('DEFAULT',
|
|
|
|
admin_port=cluster.determine_api_port(config["admin-port"]))
|
2012-10-02 17:36:25 -07:00
|
|
|
set_admin_token(config['admin-token'])
|
2012-03-01 12:35:39 -08:00
|
|
|
|
2012-02-28 17:18:17 -08:00
|
|
|
# set all backends to use sql+sqlite, if they are not already by default
|
|
|
|
update_config_block('sql',
|
|
|
|
connection='sqlite:////var/lib/keystone/keystone.db')
|
|
|
|
update_config_block('identity',
|
|
|
|
driver='keystone.identity.backends.sql.Identity')
|
|
|
|
update_config_block('catalog',
|
|
|
|
driver='keystone.catalog.backends.sql.Catalog')
|
|
|
|
update_config_block('token',
|
|
|
|
driver='keystone.token.backends.sql.Token')
|
|
|
|
update_config_block('ec2',
|
|
|
|
driver='keystone.contrib.ec2.backends.sql.Ec2')
|
2013-01-30 16:48:51 -08:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.stop('keystone')
|
2012-02-28 17:18:17 -08:00
|
|
|
execute("keystone-manage db_sync")
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.start('keystone')
|
2013-02-07 21:03:44 -08:00
|
|
|
|
2013-03-21 12:23:04 -07:00
|
|
|
# ensure user + permissions for peer relations that
|
2013-02-12 21:56:39 -08:00
|
|
|
# may be syncing data there via SSH_USER.
|
2013-03-21 12:23:04 -07:00
|
|
|
unison.ensure_user(user=SSH_USER, group='keystone')
|
2013-02-12 21:56:39 -08:00
|
|
|
execute("chmod -R g+wrx /var/lib/keystone/")
|
2013-02-07 21:03:44 -08:00
|
|
|
|
2012-02-29 11:59:37 -08:00
|
|
|
time.sleep(5)
|
2011-12-08 09:52:12 -08:00
|
|
|
ensure_initial_admin(config)
|
|
|
|
|
2013-01-30 16:48:51 -08:00
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
def db_joined():
|
2013-03-18 12:56:57 +00:00
|
|
|
relation_data = {
|
|
|
|
"database": config["database"],
|
|
|
|
"username": config["database-user"],
|
|
|
|
"hostname": config["hostname"]
|
|
|
|
}
|
|
|
|
utils.relation_set(**relation_data)
|
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
|
|
|
|
def db_changed():
|
2013-03-18 17:21:42 +00:00
|
|
|
relation_data = utils.relation_get_dict()
|
2012-10-02 17:36:25 -07:00
|
|
|
if ('password' not in relation_data or
|
2013-02-15 12:23:41 -05:00
|
|
|
'db_host' not in relation_data):
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.juju_log('INFO',
|
|
|
|
"db_host or password not set. Peer not ready, exit 0")
|
|
|
|
return
|
2013-02-12 21:56:39 -08:00
|
|
|
|
2012-02-28 17:18:17 -08:00
|
|
|
update_config_block('sql', connection="mysql://%s:%s@%s/%s" %
|
2011-12-08 09:52:12 -08:00
|
|
|
(config["database-user"],
|
|
|
|
relation_data["password"],
|
2013-02-15 12:23:41 -05:00
|
|
|
relation_data["db_host"],
|
2011-12-08 09:52:12 -08:00
|
|
|
config["database"]))
|
2013-01-30 16:48:51 -08:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
if cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Cluster leader, performing db-sync')
|
|
|
|
execute("keystone-manage db_sync", echo=True)
|
2013-04-04 19:35:06 -04:00
|
|
|
|
|
|
|
if config_dirty():
|
|
|
|
utils.restart('keystone')
|
|
|
|
|
2012-02-29 11:59:37 -08:00
|
|
|
time.sleep(5)
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2013-03-18 16:29:54 +00:00
|
|
|
if cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
ensure_initial_admin(config)
|
|
|
|
# If the backend database has been switched to something new and there
|
|
|
|
# are existing identity-service relations,, service entries need to be
|
|
|
|
# recreated in the new database. Re-executing identity-service-changed
|
|
|
|
# will do this.
|
|
|
|
for rid in utils.relation_ids('identity-service'):
|
|
|
|
for unit in utils.relation_list(rid=rid):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
"Re-exec'ing identity-service-changed"
|
|
|
|
" for: %s - %s" % (rid, unit))
|
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2012-09-17 17:39:51 -07:00
|
|
|
|
2013-02-07 21:03:44 -08:00
|
|
|
def ensure_valid_service(service):
|
|
|
|
if service not in valid_services.keys():
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.juju_log('WARNING',
|
|
|
|
"Invalid service requested: '%s'" % service)
|
|
|
|
utils.relation_set(admin_token=-1)
|
2013-02-07 21:03:44 -08:00
|
|
|
return
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
|
|
|
|
def add_endpoint(region, service, publicurl, adminurl, internalurl):
|
2013-02-07 21:03:44 -08:00
|
|
|
desc = valid_services[service]["desc"]
|
|
|
|
service_type = valid_services[service]["type"]
|
|
|
|
create_service_entry(service, service_type, desc)
|
|
|
|
create_endpoint_template(region=region, service=service,
|
2013-03-18 12:56:57 +00:00
|
|
|
publicurl=publicurl,
|
|
|
|
adminurl=adminurl,
|
|
|
|
internalurl=internalurl)
|
|
|
|
|
2013-02-07 21:03:44 -08:00
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
def identity_joined():
|
|
|
|
""" Do nothing until we get information about requested service """
|
|
|
|
pass
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2013-09-03 12:46:13 +01:00
|
|
|
def get_requested_roles(settings):
|
|
|
|
''' Retrieve any valid requested_roles from dict settings '''
|
|
|
|
if ('requested_roles' in settings and
|
|
|
|
settings['requested_roles'] not in ['None', None]):
|
|
|
|
return settings['requested_roles'].split(',')
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2012-09-17 17:39:51 -07:00
|
|
|
def identity_changed(relation_id=None, remote_unit=None):
|
|
|
|
""" A service has advertised its API endpoints, create an entry in the
|
|
|
|
service catalog.
|
|
|
|
Optionally allow this hook to be re-fired for an existing
|
|
|
|
relation+unit, for context see see db_changed().
|
|
|
|
"""
|
2013-03-18 12:56:57 +00:00
|
|
|
if not cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Deferring identity_changed() to service leader.')
|
2012-12-18 12:00:48 +00:00
|
|
|
return
|
|
|
|
|
2013-03-18 17:21:42 +00:00
|
|
|
settings = utils.relation_get_dict(relation_id=relation_id,
|
|
|
|
remote_unit=remote_unit)
|
2012-03-01 12:37:18 -08:00
|
|
|
|
|
|
|
# the minimum settings needed per endpoint
|
|
|
|
single = set(['service', 'region', 'public_url', 'admin_url',
|
|
|
|
'internal_url'])
|
|
|
|
if single.issubset(settings):
|
|
|
|
# other end of relation advertised only one endpoint
|
2013-03-18 12:56:57 +00:00
|
|
|
if 'None' in [v for k, v in settings.iteritems()]:
|
2012-09-17 17:39:51 -07:00
|
|
|
# Some backend services advertise no endpoint but require a
|
|
|
|
# hook execution to update auth strategy.
|
2013-02-14 14:30:47 +00:00
|
|
|
relation_data = {}
|
|
|
|
# Check if clustered and use vip + haproxy ports if so
|
2013-03-18 12:56:57 +00:00
|
|
|
if cluster.is_clustered():
|
2013-02-14 14:30:47 +00:00
|
|
|
relation_data["auth_host"] = config['vip']
|
|
|
|
relation_data["service_host"] = config['vip']
|
|
|
|
else:
|
|
|
|
relation_data["auth_host"] = config['hostname']
|
|
|
|
relation_data["service_host"] = config['hostname']
|
2013-03-18 12:56:57 +00:00
|
|
|
relation_data["auth_port"] = config['admin-port']
|
|
|
|
relation_data["service_port"] = config['service-port']
|
2013-03-19 13:50:23 +00:00
|
|
|
if config['https-service-endpoints'] in ['True', 'true']:
|
2013-03-19 13:41:27 +00:00
|
|
|
# Pass CA cert as client will need it to
|
|
|
|
# verify https connections
|
|
|
|
ca = get_ca(user=SSH_USER)
|
|
|
|
ca_bundle = ca.get_ca_bundle()
|
|
|
|
relation_data['https_keystone'] = 'True'
|
|
|
|
relation_data['ca_cert'] = b64encode(ca_bundle)
|
2013-08-13 13:55:50 +01:00
|
|
|
if relation_id:
|
|
|
|
relation_data['rid'] = relation_id
|
2013-09-03 12:46:13 +01:00
|
|
|
# Allow the remote service to request creation of any additional
|
|
|
|
# roles. Currently used by Horizon
|
2013-09-03 13:03:32 +01:00
|
|
|
for role in get_requested_roles(settings):
|
2013-09-03 12:46:13 +01:00
|
|
|
utils.juju_log('INFO',
|
|
|
|
"Creating requested role: %s" % role)
|
|
|
|
create_role(role)
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.relation_set(**relation_data)
|
2013-09-03 12:46:13 +01:00
|
|
|
return
|
2013-09-03 09:10:11 +01:00
|
|
|
else:
|
|
|
|
ensure_valid_service(settings['service'])
|
|
|
|
add_endpoint(region=settings['region'],
|
|
|
|
service=settings['service'],
|
|
|
|
publicurl=settings['public_url'],
|
|
|
|
adminurl=settings['admin_url'],
|
|
|
|
internalurl=settings['internal_url'])
|
|
|
|
service_username = settings['service']
|
|
|
|
https_cn = urlparse.urlparse(settings['internal_url'])
|
|
|
|
https_cn = https_cn.hostname
|
2012-03-01 12:37:18 -08:00
|
|
|
else:
|
|
|
|
# assemble multiple endpoints from relation data. service name
|
|
|
|
# should be prepended to setting name, ie:
|
|
|
|
# realtion-set ec2_service=$foo ec2_region=$foo ec2_public_url=$foo
|
|
|
|
# relation-set nova_service=$foo nova_region=$foo nova_public_url=$foo
|
|
|
|
# Results in a dict that looks like:
|
|
|
|
# { 'ec2': {
|
|
|
|
# 'service': $foo
|
|
|
|
# 'region': $foo
|
|
|
|
# 'public_url': $foo
|
|
|
|
# }
|
|
|
|
# 'nova': {
|
|
|
|
# 'service': $foo
|
|
|
|
# 'region': $foo
|
|
|
|
# 'public_url': $foo
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
endpoints = {}
|
2013-03-18 12:56:57 +00:00
|
|
|
for k, v in settings.iteritems():
|
2012-03-01 12:37:18 -08:00
|
|
|
ep = k.split('_')[0]
|
|
|
|
x = '_'.join(k.split('_')[1:])
|
2013-02-19 17:41:43 -08:00
|
|
|
if ep not in endpoints:
|
2012-03-01 12:37:18 -08:00
|
|
|
endpoints[ep] = {}
|
|
|
|
endpoints[ep][x] = v
|
2012-03-02 12:46:20 -08:00
|
|
|
services = []
|
2013-02-19 17:41:43 -08:00
|
|
|
https_cn = None
|
2012-03-01 12:37:18 -08:00
|
|
|
for ep in endpoints:
|
|
|
|
# weed out any unrelated relation stuff Juju might have added
|
|
|
|
# by ensuring each possible endpiont has appropriate fields
|
|
|
|
# ['service', 'region', 'public_url', 'admin_url', 'internal_url']
|
|
|
|
if single.issubset(endpoints[ep]):
|
|
|
|
ep = endpoints[ep]
|
|
|
|
ensure_valid_service(ep['service'])
|
|
|
|
add_endpoint(region=ep['region'], service=ep['service'],
|
2012-10-28 11:08:49 +01:00
|
|
|
publicurl=ep['public_url'],
|
|
|
|
adminurl=ep['admin_url'],
|
|
|
|
internalurl=ep['internal_url'])
|
2012-03-02 12:46:20 -08:00
|
|
|
services.append(ep['service'])
|
2013-02-19 17:41:43 -08:00
|
|
|
if not https_cn:
|
|
|
|
https_cn = urlparse.urlparse(ep['internal_url'])
|
|
|
|
https_cn = https_cn.hostname
|
2012-03-02 12:46:20 -08:00
|
|
|
service_username = '_'.join(services)
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2013-09-03 12:55:49 +01:00
|
|
|
if 'None' in [v for k, v in settings.iteritems()]:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not service_username:
|
|
|
|
return
|
|
|
|
|
2012-03-08 14:38:36 -08:00
|
|
|
token = get_admin_token()
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.juju_log('INFO',
|
|
|
|
"Creating service credentials for '%s'" % service_username)
|
2012-03-09 14:56:59 -08:00
|
|
|
|
2013-01-30 16:48:51 -08:00
|
|
|
service_password = get_service_password(service_username)
|
2012-03-02 12:46:20 -08:00
|
|
|
create_user(service_username, service_password, config['service-tenant'])
|
2013-03-18 12:56:57 +00:00
|
|
|
grant_role(service_username, config['admin-role'],
|
|
|
|
config['service-tenant'])
|
2012-03-02 12:46:20 -08:00
|
|
|
|
2013-09-03 12:46:13 +01:00
|
|
|
# Allow the remote service to request creation of any additional roles.
|
|
|
|
# Currently used by Swift and Ceilometer.
|
2013-09-03 13:03:32 +01:00
|
|
|
for role in get_requested_roles(settings):
|
2013-09-03 12:46:13 +01:00
|
|
|
utils.juju_log('INFO',
|
|
|
|
"Creating requested role: %s" % role)
|
|
|
|
create_role(role, service_username,
|
|
|
|
config['service-tenant'])
|
|
|
|
|
2012-03-02 12:46:20 -08:00
|
|
|
# As of https://review.openstack.org/#change,4675, all nodes hosting
|
|
|
|
# an endpoint(s) needs a service username and password assigned to
|
|
|
|
# the service tenant and granted admin role.
|
|
|
|
# note: config['service-tenant'] is created in utils.ensure_initial_admin()
|
|
|
|
# we return a token, information about our API endpoints, and the generated
|
|
|
|
# service credentials
|
2011-12-08 09:52:12 -08:00
|
|
|
relation_data = {
|
|
|
|
"admin_token": token,
|
|
|
|
"service_host": config["hostname"],
|
|
|
|
"service_port": config["service-port"],
|
|
|
|
"auth_host": config["hostname"],
|
2012-03-02 12:46:20 -08:00
|
|
|
"auth_port": config["admin-port"],
|
|
|
|
"service_username": service_username,
|
|
|
|
"service_password": service_password,
|
2013-02-14 15:20:54 -08:00
|
|
|
"service_tenant": config['service-tenant'],
|
|
|
|
"https_keystone": "False",
|
|
|
|
"ssl_cert": "",
|
|
|
|
"ssl_key": "",
|
|
|
|
"ca_cert": ""
|
2011-12-08 09:52:12 -08:00
|
|
|
}
|
2013-02-07 21:03:44 -08:00
|
|
|
|
2013-02-14 15:20:54 -08:00
|
|
|
if relation_id:
|
|
|
|
relation_data['rid'] = relation_id
|
|
|
|
|
2012-12-17 15:42:52 +00:00
|
|
|
# Check if clustered and use vip + haproxy ports if so
|
2013-03-18 12:56:57 +00:00
|
|
|
if cluster.is_clustered():
|
2012-12-17 15:42:52 +00:00
|
|
|
relation_data["auth_host"] = config['vip']
|
|
|
|
relation_data["service_host"] = config['vip']
|
|
|
|
|
2013-02-12 21:56:39 -08:00
|
|
|
# generate or get a new cert/key for service if set to manage certs.
|
2013-02-07 21:03:44 -08:00
|
|
|
if config['https-service-endpoints'] in ['True', 'true']:
|
2013-02-19 20:35:04 -08:00
|
|
|
ca = get_ca(user=SSH_USER)
|
2013-02-19 17:41:43 -08:00
|
|
|
cert, key = ca.get_cert_and_key(common_name=https_cn)
|
2013-03-18 12:56:57 +00:00
|
|
|
ca_bundle = ca.get_ca_bundle()
|
2013-02-07 21:03:44 -08:00
|
|
|
relation_data['ssl_cert'] = b64encode(cert)
|
|
|
|
relation_data['ssl_key'] = b64encode(key)
|
|
|
|
relation_data['ca_cert'] = b64encode(ca_bundle)
|
2013-02-14 15:20:54 -08:00
|
|
|
relation_data['https_keystone'] = 'True'
|
2013-02-12 21:56:39 -08:00
|
|
|
unison.sync_to_peers(peer_interface='cluster',
|
|
|
|
paths=[SSL_DIR], user=SSH_USER, verbose=True)
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.relation_set(**relation_data)
|
2013-01-30 16:48:51 -08:00
|
|
|
synchronize_service_credentials()
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2012-08-08 16:17:52 -07:00
|
|
|
def config_changed():
|
2013-03-21 12:23:04 -07:00
|
|
|
unison.ensure_user(user=SSH_USER, group='keystone')
|
|
|
|
execute("chmod -R g+wrx /var/lib/keystone/")
|
2012-10-02 17:36:25 -07:00
|
|
|
|
|
|
|
# Determine whether or not we should do an upgrade, based on the
|
|
|
|
# the version offered in keyston-release.
|
2012-10-12 10:26:48 -07:00
|
|
|
available = get_os_codename_install_source(config['openstack-origin'])
|
2012-10-02 17:36:25 -07:00
|
|
|
installed = get_os_codename_package('keystone')
|
|
|
|
|
2012-12-18 19:39:14 -08:00
|
|
|
if (available and
|
2013-03-18 12:56:57 +00:00
|
|
|
get_os_version_codename(available) > \
|
|
|
|
get_os_version_codename(installed)):
|
2013-03-18 13:47:53 +00:00
|
|
|
# TODO: fixup this call to work like utils.install()
|
|
|
|
do_openstack_upgrade(config['openstack-origin'], ' '.join(packages))
|
2013-05-22 11:28:56 +01:00
|
|
|
# Ensure keystone group permissions
|
|
|
|
execute("chmod -R g+wrx /var/lib/keystone/")
|
2012-10-02 17:36:25 -07:00
|
|
|
|
2013-02-22 12:20:54 -07:00
|
|
|
env_vars = {'OPENSTACK_SERVICE_KEYSTONE': 'keystone',
|
2013-03-27 08:54:21 -06:00
|
|
|
'OPENSTACK_PORT_ADMIN': cluster.determine_api_port(
|
|
|
|
config['admin-port']),
|
|
|
|
'OPENSTACK_PORT_PUBLIC': cluster.determine_api_port(
|
|
|
|
config['service-port'])}
|
2013-02-21 09:42:08 -07:00
|
|
|
save_script_rc(**env_vars)
|
|
|
|
|
2012-10-02 17:36:25 -07:00
|
|
|
set_admin_token(config['admin-token'])
|
2012-12-18 12:00:48 +00:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
if cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Cluster leader - ensuring endpoint configuration'
|
|
|
|
' is up to date')
|
2012-12-18 12:00:48 +00:00
|
|
|
ensure_initial_admin(config)
|
2012-08-08 16:17:52 -07:00
|
|
|
|
2012-12-17 23:16:26 -08:00
|
|
|
update_config_block('logger_root', level=config['log-level'],
|
|
|
|
file='/etc/keystone/logging.conf')
|
2012-12-18 17:29:14 -08:00
|
|
|
if get_os_version_package('keystone') >= '2013.1':
|
|
|
|
# PKI introduced in Grizzly
|
|
|
|
configure_pki_tokens(config)
|
|
|
|
|
2013-04-04 19:35:06 -04:00
|
|
|
if config_dirty():
|
|
|
|
utils.restart('keystone')
|
2012-12-17 13:45:58 +00:00
|
|
|
|
2013-03-19 12:35:21 +00:00
|
|
|
if cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Firing identity_changed hook'
|
|
|
|
' for all related services.')
|
|
|
|
# HTTPS may have been set - so fire all identity relations
|
|
|
|
# again
|
|
|
|
for r_id in utils.relation_ids('identity-service'):
|
|
|
|
for unit in utils.relation_list(r_id):
|
|
|
|
identity_changed(relation_id=r_id,
|
|
|
|
remote_unit=unit)
|
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
def upgrade_charm():
|
2013-05-03 09:51:09 +01:00
|
|
|
# Ensure all required packages are installed
|
|
|
|
utils.install(*packages)
|
2012-12-17 13:45:58 +00:00
|
|
|
cluster_changed()
|
2013-03-18 12:56:57 +00:00
|
|
|
if cluster.eligible_leader(CLUSTER_RES):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Cluster leader - ensuring endpoint configuration'
|
|
|
|
' is up to date')
|
2012-12-18 12:00:48 +00:00
|
|
|
ensure_initial_admin(config)
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
|
2013-02-12 21:56:39 -08:00
|
|
|
def cluster_joined():
|
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
|
|
|
group='keystone',
|
|
|
|
peer_interface='cluster',
|
2013-04-09 13:16:44 +01:00
|
|
|
ensure_local_user=True)
|
2013-03-18 12:56:57 +00:00
|
|
|
update_config_block('DEFAULT',
|
|
|
|
public_port=cluster.determine_api_port(config["service-port"]))
|
|
|
|
update_config_block('DEFAULT',
|
|
|
|
admin_port=cluster.determine_api_port(config["admin-port"]))
|
2013-04-04 19:35:06 -04:00
|
|
|
if config_dirty():
|
|
|
|
utils.restart('keystone')
|
2013-03-18 12:56:57 +00:00
|
|
|
service_ports = {
|
2013-03-18 15:02:09 +00:00
|
|
|
"keystone_admin": [
|
2013-03-18 12:56:57 +00:00
|
|
|
cluster.determine_haproxy_port(config['admin-port']),
|
2013-03-18 15:02:09 +00:00
|
|
|
cluster.determine_api_port(config["admin-port"])
|
|
|
|
],
|
|
|
|
"keystone_service": [
|
|
|
|
cluster.determine_haproxy_port(config['service-port']),
|
|
|
|
cluster.determine_api_port(config["service-port"])
|
|
|
|
]
|
2013-03-18 12:56:57 +00:00
|
|
|
}
|
|
|
|
haproxy.configure_haproxy(service_ports)
|
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
def cluster_changed():
|
2013-02-12 21:56:39 -08:00
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
2013-03-18 12:56:57 +00:00
|
|
|
group='keystone',
|
|
|
|
peer_interface='cluster',
|
2013-04-09 13:16:44 +01:00
|
|
|
ensure_local_user=True)
|
2013-01-30 16:48:51 -08:00
|
|
|
synchronize_service_credentials()
|
2013-03-18 12:56:57 +00:00
|
|
|
service_ports = {
|
2013-03-18 15:02:09 +00:00
|
|
|
"keystone_admin": [
|
2013-03-18 12:56:57 +00:00
|
|
|
cluster.determine_haproxy_port(config['admin-port']),
|
2013-03-18 15:02:09 +00:00
|
|
|
cluster.determine_api_port(config["admin-port"])
|
|
|
|
],
|
|
|
|
"keystone_service": [
|
|
|
|
cluster.determine_haproxy_port(config['service-port']),
|
|
|
|
cluster.determine_api_port(config["service-port"])
|
|
|
|
]
|
2013-03-18 12:56:57 +00:00
|
|
|
}
|
|
|
|
haproxy.configure_haproxy(service_ports)
|
2013-01-30 16:48:51 -08:00
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
def ha_relation_changed():
|
2013-03-18 17:21:42 +00:00
|
|
|
relation_data = utils.relation_get_dict()
|
2012-12-18 12:00:48 +00:00
|
|
|
if ('clustered' in relation_data and
|
2013-03-18 12:56:57 +00:00
|
|
|
cluster.is_leader(CLUSTER_RES)):
|
|
|
|
utils.juju_log('INFO',
|
|
|
|
'Cluster configured, notifying other services'
|
|
|
|
' and updating keystone endpoint configuration')
|
2012-12-18 12:00:48 +00:00
|
|
|
# Update keystone endpoint to point at VIP
|
|
|
|
ensure_initial_admin(config)
|
2012-12-17 15:42:52 +00:00
|
|
|
# Tell all related services to start using
|
|
|
|
# the VIP and haproxy ports instead
|
2013-03-18 12:56:57 +00:00
|
|
|
for r_id in utils.relation_ids('identity-service'):
|
|
|
|
utils.relation_set(rid=r_id,
|
|
|
|
auth_host=config['vip'],
|
|
|
|
service_host=config['vip'])
|
2012-12-17 15:42:52 +00:00
|
|
|
|
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
def ha_relation_joined():
|
|
|
|
# Obtain the config values necessary for the cluster config. These
|
|
|
|
# include multicast port and interface to bind to.
|
|
|
|
corosync_bindiface = config['ha-bindiface']
|
|
|
|
corosync_mcastport = config['ha-mcastport']
|
2013-03-18 12:56:57 +00:00
|
|
|
vip = config['vip']
|
|
|
|
vip_cidr = config['vip_cidr']
|
|
|
|
vip_iface = config['vip_iface']
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
# Obtain resources
|
|
|
|
resources = {
|
2013-03-18 12:56:57 +00:00
|
|
|
'res_ks_vip': 'ocf:heartbeat:IPaddr2',
|
|
|
|
'res_ks_haproxy': 'lsb:haproxy'
|
2012-12-17 13:45:58 +00:00
|
|
|
}
|
|
|
|
resource_params = {
|
2013-03-18 12:56:57 +00:00
|
|
|
'res_ks_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' % \
|
|
|
|
(vip, vip_cidr, vip_iface),
|
|
|
|
'res_ks_haproxy': 'op monitor interval="5s"'
|
2012-12-17 13:45:58 +00:00
|
|
|
}
|
|
|
|
init_services = {
|
2013-03-18 12:56:57 +00:00
|
|
|
'res_ks_haproxy': 'haproxy'
|
2012-12-17 13:45:58 +00:00
|
|
|
}
|
2013-03-18 12:56:57 +00:00
|
|
|
clones = {
|
2013-03-18 15:49:00 +00:00
|
|
|
'cl_ks_haproxy': 'res_ks_haproxy'
|
2012-12-17 13:45:58 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.relation_set(init_services=init_services,
|
|
|
|
corosync_bindiface=corosync_bindiface,
|
|
|
|
corosync_mcastport=corosync_mcastport,
|
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params,
|
|
|
|
clones=clones)
|
2012-12-17 13:45:58 +00:00
|
|
|
|
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
hooks = {
|
|
|
|
"install": install_hook,
|
|
|
|
"shared-db-relation-joined": db_joined,
|
|
|
|
"shared-db-relation-changed": db_changed,
|
|
|
|
"identity-service-relation-joined": identity_joined,
|
2012-08-08 16:17:52 -07:00
|
|
|
"identity-service-relation-changed": identity_changed,
|
2012-12-17 13:45:58 +00:00
|
|
|
"config-changed": config_changed,
|
2013-02-12 21:56:39 -08:00
|
|
|
"cluster-relation-joined": cluster_joined,
|
2012-12-17 13:45:58 +00:00
|
|
|
"cluster-relation-changed": cluster_changed,
|
|
|
|
"cluster-relation-departed": cluster_changed,
|
|
|
|
"ha-relation-joined": ha_relation_joined,
|
|
|
|
"ha-relation-changed": ha_relation_changed,
|
|
|
|
"upgrade-charm": upgrade_charm
|
2011-12-08 09:52:12 -08:00
|
|
|
}
|
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
utils.do_hooks(hooks)
|