[dosaboy] added support for 'source' and 'key' config options so that
an alternative archive can be added to get more recent packages e.g. Ceph packages from the Ubuntu Cloud Archive.
This commit is contained in:
commit
da0f385948
9
Makefile
9
Makefile
|
@ -3,12 +3,13 @@ PYTHON := /usr/bin/env python
|
|||
|
||||
lint:
|
||||
@flake8 --exclude hooks/charmhelpers hooks
|
||||
@flake8 --exclude hooks/charmhelpers unit_tests
|
||||
# @flake8 --exclude hooks/charmhelpers unit_tests
|
||||
@charm proof
|
||||
|
||||
test:
|
||||
@echo Starting tests...
|
||||
@$(PYTHON) /usr/bin/nosetests --nologcapture unit_tests
|
||||
# Disabling since we do not yet have unit tests
|
||||
#test:
|
||||
# @echo Starting tests...
|
||||
# @$(PYTHON) /usr/bin/nosetests --nologcapture unit_tests
|
||||
|
||||
sync:
|
||||
@charm-helper-sync -c charm-helpers.yaml
|
||||
|
|
|
@ -77,6 +77,12 @@ options:
|
|||
rbd pool has been created, changing this value will not have any
|
||||
effect (although it can be changed in ceph by manually configuring
|
||||
your ceph cluster).
|
||||
use-syslog:
|
||||
type: boolean
|
||||
default: False
|
||||
description: |
|
||||
If True, services that support it will log to syslog instead of their normal
|
||||
log location.
|
||||
key:
|
||||
type: string
|
||||
description: |
|
||||
|
@ -94,3 +100,4 @@ options:
|
|||
.
|
||||
The last option should be used in conjunction with the key configuration
|
||||
option.
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ CEPH_CONF = """[global]
|
|||
auth supported = %(auth)s
|
||||
keyring = %(keyring)s
|
||||
mon host = %(mon_hosts)s
|
||||
log to syslog = %(use_syslog)s
|
||||
err to syslog = %(use_syslog)s
|
||||
clog to syslog = %(use_syslog)s
|
||||
"""
|
||||
|
||||
|
||||
|
@ -165,7 +168,7 @@ def get_ceph_nodes():
|
|||
return hosts
|
||||
|
||||
|
||||
def configure(service, key, auth):
|
||||
def configure(service, key, auth, use_syslog):
|
||||
create_keyring(service, key)
|
||||
create_key_file(service, key)
|
||||
hosts = get_ceph_nodes()
|
||||
|
|
|
@ -89,9 +89,9 @@ def https():
|
|||
for r_id in relation_ids('identity-service'):
|
||||
for unit in relation_list(r_id):
|
||||
if (relation_get('https_keystone', rid=r_id, unit=unit) and
|
||||
relation_get('ssl_cert', rid=r_id, unit=unit) and
|
||||
relation_get('ssl_key', rid=r_id, unit=unit) and
|
||||
relation_get('ca_cert', rid=r_id, unit=unit)):
|
||||
relation_get('ssl_cert', rid=r_id, unit=unit) and
|
||||
relation_get('ssl_key', rid=r_id, unit=unit) and
|
||||
relation_get('ca_cert', rid=r_id, unit=unit)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
@ -73,15 +73,15 @@ def get_keypair(user):
|
|||
|
||||
pub_key = '%s.pub' % priv_key
|
||||
if not os.path.isfile(pub_key):
|
||||
utils.juju_log('INFO', 'Generatring missing ssh public key @ %s.' % \
|
||||
utils.juju_log('INFO', 'Generatring missing ssh public key @ %s.' %
|
||||
pub_key)
|
||||
cmd = ['ssh-keygen', '-y', '-f', priv_key]
|
||||
p = subprocess.check_output(cmd).strip()
|
||||
with open(pub_key, 'wb') as out:
|
||||
out.write(p)
|
||||
subprocess.check_call(['chown', '-R', user, ssh_dir])
|
||||
return open(priv_key, 'r').read().strip(), \
|
||||
open(pub_key, 'r').read().strip()
|
||||
return (open(priv_key, 'r').read().strip(),
|
||||
open(pub_key, 'r').read().strip())
|
||||
|
||||
|
||||
def write_authorized_keys(user, keys):
|
||||
|
@ -125,7 +125,8 @@ def ensure_user(user, group=None):
|
|||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
def ssh_authorized_peers(peer_interface, user, group=None, ensure_local_user=False):
|
||||
def ssh_authorized_peers(peer_interface, user, group=None,
|
||||
ensure_local_user=False):
|
||||
"""
|
||||
Main setup function, should be called from both peer -changed and -joined
|
||||
hooks with the same parameters.
|
||||
|
@ -149,7 +150,7 @@ def ssh_authorized_peers(peer_interface, user, group=None, ensure_local_user=Fal
|
|||
hosts.append(settings['private-address'])
|
||||
else:
|
||||
utils.juju_log('INFO',
|
||||
'ssh_authorized_peers(): ssh_pub_key '\
|
||||
'ssh_authorized_peers(): ssh_pub_key '
|
||||
'missing for unit %s, skipping.' % unit)
|
||||
write_authorized_keys(user, keys)
|
||||
write_known_hosts(user, hosts)
|
||||
|
@ -203,9 +204,9 @@ def sync_to_peers(peer_interface, user, paths=[], verbose=False):
|
|||
if add_host:
|
||||
hosts.append(settings['private-address'])
|
||||
else:
|
||||
print 'unison sync_to_peers: peer (%s) has not authorized '\
|
||||
'*this* host yet, skipping.' %\
|
||||
settings['private-address']
|
||||
print ('unison sync_to_peers: peer (%s) has not authorized '
|
||||
'*this* host yet, skipping.' %
|
||||
settings['private-address'])
|
||||
|
||||
for path in paths:
|
||||
# removing trailing slash from directory paths, unison
|
||||
|
|
|
@ -32,8 +32,7 @@ def install(*pkgs):
|
|||
cmd = [
|
||||
'apt-get',
|
||||
'-y',
|
||||
'install'
|
||||
]
|
||||
'install']
|
||||
for pkg in pkgs:
|
||||
cmd.append(pkg)
|
||||
subprocess.check_call(cmd)
|
||||
|
@ -54,9 +53,8 @@ except ImportError:
|
|||
|
||||
|
||||
def render_template(template_name, context, template_dir=TEMPLATES_DIR):
|
||||
templates = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(template_dir)
|
||||
)
|
||||
templates = \
|
||||
jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
|
||||
template = templates.get_template(template_name)
|
||||
return template.render(context)
|
||||
|
||||
|
@ -68,8 +66,7 @@ UDP = 'UDP'
|
|||
def expose(port, protocol='TCP'):
|
||||
cmd = [
|
||||
'open-port',
|
||||
'{}/{}'.format(port, protocol)
|
||||
]
|
||||
'{}/{}'.format(port, protocol)]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
|
@ -88,8 +85,7 @@ def juju_log(severity, message):
|
|||
cmd = [
|
||||
'juju-log',
|
||||
'--log-level', severity,
|
||||
message
|
||||
]
|
||||
message]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
|
@ -113,8 +109,7 @@ def cached(func):
|
|||
def relation_ids(relation):
|
||||
cmd = [
|
||||
'relation-ids',
|
||||
relation
|
||||
]
|
||||
relation]
|
||||
result = str(subprocess.check_output(cmd)).split()
|
||||
if result == "":
|
||||
return None
|
||||
|
@ -126,8 +121,7 @@ def relation_ids(relation):
|
|||
def relation_list(rid):
|
||||
cmd = [
|
||||
'relation-list',
|
||||
'-r', rid,
|
||||
]
|
||||
'-r', rid]
|
||||
result = str(subprocess.check_output(cmd)).split()
|
||||
if result == "":
|
||||
return None
|
||||
|
@ -138,8 +132,7 @@ def relation_list(rid):
|
|||
@cached
|
||||
def relation_get(attribute, unit=None, rid=None):
|
||||
cmd = [
|
||||
'relation-get',
|
||||
]
|
||||
'relation-get']
|
||||
if rid:
|
||||
cmd.append('-r')
|
||||
cmd.append(rid)
|
||||
|
@ -157,8 +150,7 @@ def relation_get(attribute, unit=None, rid=None):
|
|||
def relation_get_dict(relation_id=None, remote_unit=None):
|
||||
"""Obtain all relation data as dict by way of JSON"""
|
||||
cmd = [
|
||||
'relation-get', '--format=json'
|
||||
]
|
||||
'relation-get', '--format=json']
|
||||
if relation_id:
|
||||
cmd.append('-r')
|
||||
cmd.append(relation_id)
|
||||
|
@ -176,8 +168,7 @@ def relation_get_dict(relation_id=None, remote_unit=None):
|
|||
|
||||
def relation_set(**kwargs):
|
||||
cmd = [
|
||||
'relation-set'
|
||||
]
|
||||
'relation-set']
|
||||
args = []
|
||||
for k, v in kwargs.items():
|
||||
if k == 'rid':
|
||||
|
@ -194,8 +185,7 @@ def relation_set(**kwargs):
|
|||
def unit_get(attribute):
|
||||
cmd = [
|
||||
'unit-get',
|
||||
attribute
|
||||
]
|
||||
attribute]
|
||||
value = subprocess.check_output(cmd).strip() # IGNORE:E1103
|
||||
if value == "":
|
||||
return None
|
||||
|
@ -208,8 +198,7 @@ def config_get(attribute):
|
|||
cmd = [
|
||||
'config-get',
|
||||
'--format',
|
||||
'json',
|
||||
]
|
||||
'json']
|
||||
out = subprocess.check_output(cmd).strip() # IGNORE:E1103
|
||||
cfg = json.loads(out)
|
||||
|
||||
|
@ -273,7 +262,7 @@ def running(service):
|
|||
return False
|
||||
else:
|
||||
if ("start/running" in output or
|
||||
"is running" in output):
|
||||
"is running" in output):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -13,7 +13,10 @@ import apt_pkg as apt
|
|||
import _pythonpath
|
||||
_ = _pythonpath
|
||||
|
||||
from charmhelpers.contrib.openstack.utils import get_hostname
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
get_hostname,
|
||||
error_out
|
||||
)
|
||||
|
||||
PACKAGES = ['pwgen', 'rabbitmq-server', 'python-amqplib', 'unison']
|
||||
|
||||
|
|
|
@ -79,16 +79,16 @@ def amqp_changed(relation_id=None, remote_unit=None):
|
|||
|
||||
singleset = set([
|
||||
'username',
|
||||
'vhost'
|
||||
])
|
||||
'vhost'])
|
||||
|
||||
if singleset.issubset(settings):
|
||||
if None in [settings['username'], settings['vhost']]:
|
||||
utils.juju_log('INFO', 'amqp_changed(): Relation not ready.')
|
||||
return
|
||||
|
||||
relation_settings['password'] = configure_amqp(username=settings['username'],
|
||||
vhost=settings['vhost'])
|
||||
relation_settings['password'] = \
|
||||
configure_amqp(username=settings['username'],
|
||||
vhost=settings['vhost'])
|
||||
else:
|
||||
queues = {}
|
||||
for k, v in settings.iteritems():
|
||||
|
@ -100,8 +100,9 @@ def amqp_changed(relation_id=None, remote_unit=None):
|
|||
relation_settings = {}
|
||||
for amqp in queues:
|
||||
if singleset.issubset(queues[amqp]):
|
||||
relation_settings['_'.join([amqp, 'password'])] = configure_amqp(queues[amqp]['username'],
|
||||
queues[amqp]['vhost'])
|
||||
relation_settings['_'.join([amqp, 'password'])] = \
|
||||
configure_amqp(queues[amqp]['username'],
|
||||
queues[amqp]['vhost'])
|
||||
|
||||
relation_settings['hostname'] = utils.unit_get('private-address')
|
||||
|
||||
|
@ -287,11 +288,13 @@ def ceph_changed():
|
|||
utils.juju_log('INFO', 'Start Ceph Relation Changed')
|
||||
auth = utils.relation_get('auth')
|
||||
key = utils.relation_get('key')
|
||||
use_syslog = str(utils.config_get('use-syslog')).lower()
|
||||
if None in [auth, key]:
|
||||
utils.juju_log('INFO', 'Missing key or auth in relation')
|
||||
sys.exit(0)
|
||||
|
||||
ceph.configure(service=SERVICE_NAME, key=key, auth=auth)
|
||||
ceph.configure(service=SERVICE_NAME, key=key, auth=auth,
|
||||
use_syslog=use_syslog)
|
||||
|
||||
if cluster.eligible_leader('res_rabbitmq_vip'):
|
||||
rbd_img = utils.config_get('rbd-name')
|
||||
|
|
|
@ -29,6 +29,7 @@ from charmhelpers.contrib.hahelpers.cluster import (
|
|||
determine_apache_port,
|
||||
determine_api_port,
|
||||
https,
|
||||
is_clustered
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.hahelpers.apache import (
|
||||
|
@ -240,10 +241,13 @@ class CephContext(OSContextGenerator):
|
|||
'''This generates context for /etc/ceph/ceph.conf templates'''
|
||||
if not relation_ids('ceph'):
|
||||
return {}
|
||||
|
||||
log('Generating template context for ceph')
|
||||
|
||||
mon_hosts = []
|
||||
auth = None
|
||||
key = None
|
||||
use_syslog = str(config('use-syslog')).lower()
|
||||
for rid in relation_ids('ceph'):
|
||||
for unit in related_units(rid):
|
||||
mon_hosts.append(relation_get('private-address', rid=rid,
|
||||
|
@ -255,6 +259,7 @@ class CephContext(OSContextGenerator):
|
|||
'mon_hosts': ' '.join(mon_hosts),
|
||||
'auth': auth,
|
||||
'key': key,
|
||||
'use_syslog': use_syslog
|
||||
}
|
||||
|
||||
if not os.path.isdir('/etc/ceph'):
|
||||
|
@ -391,7 +396,7 @@ class ApacheSSLContext(OSContextGenerator):
|
|||
return ctxt
|
||||
|
||||
|
||||
class NeutronContext(object):
|
||||
class NeutronContext(OSContextGenerator):
|
||||
interfaces = []
|
||||
|
||||
@property
|
||||
|
@ -452,6 +457,22 @@ class NeutronContext(object):
|
|||
|
||||
return nvp_ctxt
|
||||
|
||||
def neutron_ctxt(self):
|
||||
if https():
|
||||
proto = 'https'
|
||||
else:
|
||||
proto = 'http'
|
||||
if is_clustered():
|
||||
host = config('vip')
|
||||
else:
|
||||
host = unit_get('private-address')
|
||||
url = '%s://%s:%s' % (proto, host, '9696')
|
||||
ctxt = {
|
||||
'network_manager': self.network_manager,
|
||||
'neutron_url': url,
|
||||
}
|
||||
return ctxt
|
||||
|
||||
def __call__(self):
|
||||
self._ensure_packages()
|
||||
|
||||
|
@ -461,7 +482,7 @@ class NeutronContext(object):
|
|||
if not self.plugin:
|
||||
return {}
|
||||
|
||||
ctxt = {'network_manager': self.network_manager}
|
||||
ctxt = self.neutron_ctxt()
|
||||
|
||||
if self.plugin == 'ovs':
|
||||
ctxt.update(self.ovs_ctxt())
|
||||
|
|
|
@ -49,6 +49,9 @@ CEPH_CONF = """[global]
|
|||
auth supported = {auth}
|
||||
keyring = {keyring}
|
||||
mon host = {mon_hosts}
|
||||
log to syslog = {use_syslog}
|
||||
err to syslog = {use_syslog}
|
||||
clog to syslog = {use_syslog}
|
||||
"""
|
||||
|
||||
|
||||
|
@ -194,7 +197,7 @@ def get_ceph_nodes():
|
|||
return hosts
|
||||
|
||||
|
||||
def configure(service, key, auth):
|
||||
def configure(service, key, auth, use_syslog):
|
||||
''' Perform basic configuration of Ceph '''
|
||||
create_keyring(service, key)
|
||||
create_key_file(service, key)
|
||||
|
@ -202,7 +205,8 @@ def configure(service, key, auth):
|
|||
with open('/etc/ceph/ceph.conf', 'w') as ceph_conf:
|
||||
ceph_conf.write(CEPH_CONF.format(auth=auth,
|
||||
keyring=_keyring_path(service),
|
||||
mon_hosts=",".join(map(str, hosts))))
|
||||
mon_hosts=",".join(map(str, hosts)),
|
||||
use_syslog=use_syslog))
|
||||
modprobe('rbd')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue