sending hosts when active/active

This commit is contained in:
yolanda.robla@canonical.com 2013-12-12 17:45:24 +01:00
parent 5186c3211f
commit 674c9f6eee
5 changed files with 45 additions and 55 deletions

View File

@ -41,7 +41,7 @@ def install():
def rbd_exists(service, pool, rbd_img):
(rc, out) = commands.getstatusoutput('rbd list --id %s --pool %s' %\
(rc, out) = commands.getstatusoutput('rbd list --id %s --pool %s' %
(service, pool))
return rbd_img in out
@ -56,8 +56,7 @@ def create_rbd_image(service, pool, image, sizemb):
'--id',
service,
'--pool',
pool
]
pool]
execute(cmd)
@ -72,8 +71,7 @@ def create_pool(service, name):
'--id',
service,
'mkpool',
name
]
name]
execute(cmd)
@ -94,8 +92,7 @@ def create_keyring(service, key):
keyring,
'--create-keyring',
'--name=client.%s' % service,
'--add-key=%s' % key
]
'--add-key=%s' % key]
execute(cmd)
utils.juju_log('INFO', 'ceph: Created new ring at %s.' % keyring)
@ -144,8 +141,7 @@ def map_block_storage(service, pool, image):
'--user',
service,
'--secret',
keyfile_path(service),
]
keyfile_path(service)]
execute(cmd)
@ -159,16 +155,18 @@ def make_filesystem(blk_device, fstype='ext4'):
while not os.path.exists(blk_device):
if count >= 10:
utils.juju_log('ERROR',
'ceph: gave up waiting on block device %s' % blk_device)
'ceph: gave up waiting on block device %s' %
blk_device)
raise IOError(e_noent, os.strerror(e_noent), blk_device)
utils.juju_log('INFO',
'ceph: waiting for block device %s to appear' % blk_device)
'ceph: waiting for block device %s to appear' %
blk_device)
count += 1
time.sleep(1)
else:
utils.juju_log('INFO',
'ceph: Formatting block device %s as filesystem %s.' %
(blk_device, fstype))
'ceph: Formatting block device %s as filesystem %s.' %
(blk_device, fstype))
execute(['mkfs', '-t', fstype, blk_device])
@ -258,7 +256,7 @@ def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point,
for svc in system_services:
if utils.running(svc):
utils.juju_log('INFO',
'Stopping services %s prior to migrating '\
'Stopping services %s prior to migrating '
'data' % svc)
utils.stop(svc)

View File

@ -14,8 +14,7 @@ from lib.utils import (
relation_list,
relation_get,
get_unit_hostname,
config_get
)
config_get)
import subprocess
import os
@ -34,8 +33,7 @@ def is_clustered():
def is_leader(resource):
cmd = [
"crm", "resource",
"show", resource
]
"show", resource]
try:
status = subprocess.check_output(cmd)
except subprocess.CalledProcessError:

View File

@ -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,14 +53,12 @@ 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)
CLOUD_ARCHIVE = \
""" # Ubuntu Cloud Archive
CLOUD_ARCHIVE = """ # Ubuntu Cloud Archive
deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
"""
@ -71,8 +68,7 @@ CLOUD_ARCHIVE_POCKETS = {
'folsom/proposed': 'precise-proposed/folsom',
'grizzly': 'precise-updates/grizzly',
'grizzly/updates': 'precise-updates/grizzly',
'grizzly/proposed': 'precise-proposed/grizzly'
}
'grizzly/proposed': 'precise-proposed/grizzly'}
def configure_source():
@ -82,8 +78,7 @@ def configure_source():
if source.startswith('ppa:'):
cmd = [
'add-apt-repository',
source
]
source]
subprocess.check_call(cmd)
if source.startswith('cloud:'):
install('ubuntu-cloud-keyring')
@ -97,8 +92,7 @@ def configure_source():
cmd = [
'apt-key',
'adv', '--keyserver keyserver.ubuntu.com',
'--recv-keys', key
]
'--recv-keys', key]
subprocess.check_call(cmd)
elif l == 1:
apt_line = source
@ -107,8 +101,7 @@ def configure_source():
apt.write(apt_line + "\n")
cmd = [
'apt-get',
'update'
]
'update']
subprocess.check_call(cmd)
# Protocols
@ -119,8 +112,7 @@ UDP = 'UDP'
def expose(port, protocol='TCP'):
cmd = [
'open-port',
'{}/{}'.format(port, protocol)
]
'{}/{}'.format(port, protocol)]
subprocess.check_call(cmd)
@ -131,8 +123,7 @@ def open_port(port, protocol='TCP'):
def close_port(port, protocol='TCP'):
cmd = [
'close-port',
'{}/{}'.format(port, protocol)
]
'{}/{}'.format(port, protocol)]
subprocess.check_call(cmd)
@ -140,16 +131,14 @@ def juju_log(severity, message):
cmd = [
'juju-log',
'--log-level', severity,
message
]
message]
subprocess.check_call(cmd)
def relation_ids(relation):
cmd = [
'relation-ids',
relation
]
relation]
result = str(subprocess.check_output(cmd)).split()
if result == "":
return None
@ -160,8 +149,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
@ -171,8 +159,7 @@ def relation_list(rid):
def relation_get(attribute, unit=None, rid=None):
cmd = [
'relation-get',
]
'relation-get']
if rid:
cmd.append('-r')
cmd.append(rid)
@ -188,8 +175,7 @@ def relation_get(attribute, unit=None, rid=None):
def relation_set(**kwargs):
cmd = [
'relation-set'
]
'relation-set']
args = []
for k, v in kwargs.items():
if k == 'rid':
@ -205,8 +191,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
@ -218,8 +203,7 @@ def config_get(attribute):
cmd = [
'config-get',
'--format',
'json',
]
'json']
out = subprocess.check_output(cmd).strip() # IGNORE:E1103
cfg = json.loads(out)
@ -280,8 +264,7 @@ def running(service):
except subprocess.CalledProcessError:
return False
else:
if ("start/running" in output or
"is running" in output):
if ("start/running" in output or "is running" in output):
return True
else:
return False

View File

@ -65,7 +65,18 @@ def amqp_changed(relation_id=None, remote_unit=None):
}
if cluster.is_clustered():
relation_settings['clustered'] = 'true'
relation_settings['vip'] = utils.config_get('vip')
if utils.is_relation_made('ha'):
# active/passive settings
relation_settings['vip'] = utils.config_get('vip')
else:
# send active/active settings
relation_settings['vip'] = None
peers = utils.peer_units()
hosts = []
for peer in peers:
hosts.append(peer.unit_get('private-address'))
relation_settings['hosts'] = hosts
if relation_id:
relation_settings['rid'] = relation_id
utils.relation_set(**relation_settings)

View File

@ -1 +1 @@
99
100