hackety hack

This commit is contained in:
Paul Collins 2012-10-02 23:52:44 +13:00
parent d1940639ef
commit 0a563bb818
8 changed files with 200 additions and 18 deletions

View File

@ -14,3 +14,6 @@ options:
this value will become the "mon." key
to generate a suitable value, use
ceph-authtool /dev/stdout --name=mon. --gen-key
source:
type: string
default: ppa:ceph-ubuntu/dev

26
hooks/ceph.py Normal file
View File

@ -0,0 +1,26 @@
#
# Copyright 2012 Canonical Ltd.
#
# Authors:
# James Page <james.page@canonical.com>
#
import subprocess
import json
import os
QUORUM = [ 'leader', 'peon' ]
def is_quorum():
cmd = [
"ceph",
"--admin-daemon",
"/var/run/ceph/ceph-mon.%s.asok" % os.uname()[1],
"mon_status"
]
result = json.loads(subprocess.check_output(cmd))
if result['state'] in QUORUM:
return True
else:
return False

1
hooks/config-changed Symbolic link
View File

@ -0,0 +1 @@
hooks.py

View File

@ -11,11 +11,31 @@ import os
import subprocess
import sys
import ceph
import utils
def install():
print "install"
utils.juju_log('INFO', 'Begin install hook.')
utils.configure_source()
utils.install('ceph')
# TODO: Install the upstart scripts.
utils.juju_log('INFO', 'End install hook.')
def config_changed():
print "config_changed"
utils.juju_log('INFO', 'Begin config-changed hook.')
fsid = utils.config_get('fsid')
if fsid == "":
utils.juju_log('CRITICAL', 'No fsid supplied, cannot proceed.')
sys.exit(1)
monitor_secret = utils.config_get('monitor-secret')
if monitor_secret == "":
utils.juju_log('CRITICAL', 'No monitor-secret supplied, cannot proceed.')
sys.exit(1)
osd_devices = utils.config_get('osd-devices')
utils.juju_log('INFO', 'End config-changed hook.')
def mon_relation():
print "mon_relation"
@ -32,8 +52,7 @@ hook = os.path.basename(sys.argv[0])
try:
hooks[hook]()
except:
subprocess.call(['juju-log', '-l', 'INFO',
"This charm doesn't know how to handle '%s'." % hook])
except KeyError:
utils.juju_log('INFO', "This charm doesn't know how to handle '%s'." % hook)
sys.exit(0)

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -e
set -u
for disk in $(config-get osd-devices); do
ceph-disk-prepare $disk
done
udevadm trigger --subsystem-match=block --action=add
exit 0

130
hooks/utils.py Normal file
View File

@ -0,0 +1,130 @@
#
# Copyright 2012 Canonical Ltd.
#
# Authors:
# James Page <james.page@canonical.com>
#
# Taken from lp:~james-page/charms/precise/ganglia/python-refactor
#
import subprocess
import os
import sys
def install (*pkgs):
cmd = [
"apt-get",
"-y",
"install"
]
for pkg in pkgs:
cmd.append(pkg)
subprocess.check_call(cmd)
TEMPLATES_DIR="templates"
try:
import jinja2
except ImportError:
install('python-jinja2')
import jinja2
def render_template (template_name, context, template_dir=TEMPLATES_DIR):
templates = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
template = templates.get_template(template_name)
return template.render(context)
def configure_source():
source = config_get("source")
if (source.startswith("ppa:") or
source.startswith("cloud:") or
source.startswith("http:")):
cmd = [
"add-apt-repository",
source
]
subprocess.check_call(cmd)
if source.startswith("http:"):
key = config_get("key")
cmd = [
"apt-key",
"import",
key
]
subprocess.check_call(cmd)
cmd = [
"apt-get",
"update"
]
subprocess.check_call(cmd)
# Protocols
TCP="TCP"
UDP="UDP"
def expose(port, protocol="TCP"):
cmd = [
"open-port",
"%d/%s" % (port,protocol)
]
subprocess.check_call(cmd)
def juju_log(message,severity="INFO"):
cmd = [
"juju-log",
"--log-level", severity,
message
]
subprocess.check_call(cmd)
def relation_ids(relation):
cmd = [
"relation-ids",
relation
]
return subprocess.check_output(cmd).split()
def relation_list(rid):
cmd = [
"relation-list",
"-r", rid,
]
return subprocess.check_output(cmd).split()
def relation_get(attribute,unit=None,rid=None):
cmd = [
"relation-get",
]
if rid:
cmd.append("-r")
cmd.append(rid)
cmd.append(attribute)
if unit:
cmd.append(unit)
return subprocess.check_output(cmd).strip()
def relation_set(*kwargs):
cmd = [
"relation-set"
]
for k, v in kwargs.items():
cmd.append("%s=%s" % (k,v))
subprocess.check_call(cmd)
def unit_get(attribute):
cmd = [
"unit-get",
attribute
]
return subprocess.check_output(cmd).strip()
def config_get(attribute):
cmd = [
"config-get",
attribute
]
return subprocess.check_output(cmd).strip()
def juju_log(level, message):
subprocess.call(['juju-log', '-l', level, message])

1
revision Normal file
View File

@ -0,0 +1 @@
13

15
templates/ceph.conf Normal file
View File

@ -0,0 +1,15 @@
[global]
auth supported = none
keyring = /etc/ceph/$cluster.$name.keyring
mon host =
[mon]
keyring = /var/lib/ceph/mon/$cluster-$id/keyring
[mds]
keyring = /var/lib/ceph/mds/$cluster-$id/keyring
[osd]
keyring = /var/lib/ceph/osd/$cluster-$id/keyring
osd journal size = 1000
filestore xattr use omap = true