diff options
author | Stuart Mackie <wsmackie@juniper.net> | 2016-10-07 12:24:58 -0700 |
---|---|---|
committer | Stuart Mackie <wsmackie@juniper.net> | 2016-10-07 12:24:58 -0700 |
commit | 4faa7f927149a5c4ef7a03523f7bc14523cb9baa (patch) | |
tree | 0be55aa0809cc395e45baeae63db660b4e72fe83 /charms/trusty/cassandra/hooks/hooks.py | |
parent | 82f1a7eb5535b30a95b1e71ff18c315d40d1e6f0 (diff) |
Charms for Contrail 3.1 with Mitaka
Change-Id: Id37f3b9743d1974e31fcd7cd9c54be41bb0c47fb
Signed-off-by: Stuart Mackie <wsmackie@juniper.net>
Diffstat (limited to 'charms/trusty/cassandra/hooks/hooks.py')
-rw-r--r-- | charms/trusty/cassandra/hooks/hooks.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/charms/trusty/cassandra/hooks/hooks.py b/charms/trusty/cassandra/hooks/hooks.py new file mode 100644 index 0000000..e5b64ed --- /dev/null +++ b/charms/trusty/cassandra/hooks/hooks.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 +# Copyright 2015 Canonical Ltd. +# +# This file is part of the Cassandra Charm for Juju. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +from charmhelpers import fetch +from charmhelpers.core import hookenv + + +def set_proxy(): + import os + config = hookenv.config() + if config['http_proxy']: + os.environ['ftp_proxy'] = config['http_proxy'] + os.environ['http_proxy'] = config['http_proxy'] + os.environ['https_proxy'] = config['http_proxy'] + + +def bootstrap(): + try: + import bcrypt # NOQA: flake8 + import cassandra # NOQA: flake8 + except ImportError: + packages = ['python3-bcrypt', 'python3-cassandra'] + set_proxy() + fetch.configure_sources(update=True) + fetch.apt_install(packages, fatal=True) + import bcrypt # NOQA: flake8 + import cassandra # NOQA: flake8 + + +def default_hook(): + if not hookenv.has_juju_version('1.24'): + hookenv.status_set('blocked', 'Requires Juju 1.24 or higher') + # Error state, since we don't have 1.24 to give a nice blocked state. + raise SystemExit(1) + + # These need to be imported after bootstrap() or required Python + # packages may not have been installed. + import definitions + + # Only useful for debugging, or perhaps have this enabled with a config + # option? + # from loglog import loglog + # loglog('/var/log/cassandra/system.log', prefix='C*: ') + + hookenv.log('*** {} Hook Start'.format(hookenv.hook_name())) + sm = definitions.get_service_manager() + sm.manage() + hookenv.log('*** {} Hook Done'.format(hookenv.hook_name())) |