2013-07-16 21:27:06 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from swift_storage_utils import (
|
|
|
|
PACKAGES,
|
2013-07-18 16:07:22 -07:00
|
|
|
RESTART_MAP,
|
2013-07-16 21:27:06 -07:00
|
|
|
determine_block_devices,
|
|
|
|
do_openstack_upgrade,
|
|
|
|
ensure_swift_directories,
|
|
|
|
fetch_swift_rings,
|
|
|
|
register_configs,
|
2013-07-18 16:07:22 -07:00
|
|
|
save_script_rc,
|
2013-07-16 21:27:06 -07:00
|
|
|
setup_storage,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
config,
|
|
|
|
log,
|
|
|
|
relation_get,
|
|
|
|
relation_set,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.host import (
|
|
|
|
apt_install,
|
|
|
|
apt_update,
|
2013-07-18 16:07:22 -07:00
|
|
|
restart_on_change,
|
2013-07-16 21:27:06 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
|
|
|
configure_installation_source,
|
|
|
|
openstack_upgrade_available,
|
|
|
|
)
|
|
|
|
|
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
|
|
|
|
|
|
|
|
2013-07-19 12:52:45 -07:00
|
|
|
@hooks.hook()
|
2013-07-16 21:27:06 -07:00
|
|
|
def install():
|
2013-07-18 16:07:22 -07:00
|
|
|
configure_installation_source(config('openstack-origin'))
|
2013-07-16 21:27:06 -07:00
|
|
|
apt_update()
|
2013-07-18 16:07:22 -07:00
|
|
|
apt_install(PACKAGES, fatal=True)
|
2013-07-16 21:27:06 -07:00
|
|
|
setup_storage()
|
|
|
|
ensure_swift_directories()
|
|
|
|
|
|
|
|
|
2013-07-18 16:07:22 -07:00
|
|
|
@hooks.hook('config-changed')
|
|
|
|
@restart_on_change(RESTART_MAP)
|
2013-07-16 21:27:06 -07:00
|
|
|
def config_changed():
|
|
|
|
if openstack_upgrade_available('swift'):
|
|
|
|
do_openstack_upgrade(configs=CONFIGS)
|
|
|
|
CONFIGS.write_all()
|
2013-07-18 16:07:22 -07:00
|
|
|
save_script_rc()
|
2013-07-16 21:27:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook()
|
|
|
|
def swift_storage_relation_joined():
|
|
|
|
devs = [os.path.basename(dev) for dev in determine_block_devices()]
|
|
|
|
rel_settings = {
|
|
|
|
'zone': config('zone'),
|
|
|
|
'object_port': config('object-server-port'),
|
|
|
|
'container_port': config('container-server-port'),
|
|
|
|
'account_port': config('account-server-port'),
|
|
|
|
'device': ':'.join(devs),
|
|
|
|
}
|
|
|
|
relation_set(**rel_settings)
|
|
|
|
|
|
|
|
|
2013-07-18 16:07:22 -07:00
|
|
|
@hooks.hook('swift-storage-relation-changed')
|
|
|
|
@restart_on_change(RESTART_MAP)
|
2013-07-16 21:27:06 -07:00
|
|
|
def swift_storage_relation_changed():
|
|
|
|
rings_url = relation_get('rings_url')
|
|
|
|
swift_hash = relation_get('swift_hash')
|
2013-07-18 16:07:22 -07:00
|
|
|
if '' in [rings_url, swift_hash] or None in [rings_url, swift_hash]:
|
2013-07-16 21:27:06 -07:00
|
|
|
log('swift_storage_relation_changed: Peer not ready?')
|
|
|
|
sys.exit(0)
|
|
|
|
CONFIGS.write('/etc/swift/swift.conf')
|
|
|
|
fetch_swift_rings(rings_url)
|
2013-07-18 16:07:22 -07:00
|
|
|
|
|
|
|
if '/usr/bin/nosetests' not in sys.argv:
|
|
|
|
hooks.execute(sys.argv)
|