diff --git a/.gitignore b/.gitignore index 6912fefe16a04cd53f7feb66a024bc5e5c2b1076..9421a45ac8ddc1739d26a0bd0bef01bff7c047ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +builds/ deps/ diff --git a/builds/VyOS-proxy/README.ex b/builds/VyOS-proxy/README.ex deleted file mode 100644 index b6816b22ade2fa36326d7e1f612b6f6203768949..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/README.ex +++ /dev/null @@ -1,65 +0,0 @@ -# Overview - -Describe the intended usage of this charm and anything unique about how this -charm relates to others here. - -This README will be displayed in the Charm Store, it should be either Markdown -or RST. Ideal READMEs include instructions on how to use the charm, expected -usage, and charm features that your audience might be interested in. For an -example of a well written README check out Hadoop: -http://jujucharms.com/charms/precise/hadoop - -Use this as a Markdown reference if you need help with the formatting of this -README: http://askubuntu.com/editing-help - -This charm provides [service][]. Add a description here of what the service -itself actually does. - -Also remember to check the [icon guidelines][] so that your charm looks good -in the Juju GUI. - -# Usage - -Step by step instructions on using the charm: - -juju deploy servicename - -and so on. If you're providing a web service or something that the end user -needs to go to, tell them here, especially if you're deploying a service that -might listen to a non-default port. - -You can then browse to http://ip-address to configure the service. - -## Scale out Usage - -If the charm has any recommendations for running at scale, outline them in -examples here. For example if you have a memcached relation that improves -performance, mention it here. - -## Known Limitations and Issues - -This not only helps users but gives people a place to start if they want to help -you add features to your charm. - -# Configuration - -The configuration options will be listed on the charm store, however If you're -making assumptions or opinionated decisions in the charm (like setting a default -administrator password), you should detail that here so the user knows how to -change it immediately, etc. - -# Contact Information - -Though this will be listed in the charm store itself don't assume a user will -know that, so include that information here: - -## Upstream Project Name - - - Upstream website - - Upstream bug tracker - - Upstream mailing list or contact information - - Feel free to add things if it's useful for users - - -[service]: http://example.com -[icon guidelines]: https://jujucharms.com/docs/stable/authors-charm-icon diff --git a/builds/VyOS-proxy/bin/layer_option b/builds/VyOS-proxy/bin/layer_option deleted file mode 100755 index 90dc400e0c88cfb8ffc32e3bad1ee2c6b40b5b29..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/bin/layer_option +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - -import sys -sys.path.append('lib') - -import argparse -from charms.layer import options - - -parser = argparse.ArgumentParser(description='Access layer options.') -parser.add_argument('section', - help='the section, or layer, the option is from') -parser.add_argument('option', - help='the option to access') - -args = parser.parse_args() -value = options(args.section).get(args.option, '') -if isinstance(value, bool): - sys.exit(0 if value else 1) -elif isinstance(value, list): - for val in value: - print(val) -else: - print(value) diff --git a/builds/VyOS-proxy/hooks/config-changed b/builds/VyOS-proxy/hooks/config-changed deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/config-changed +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/hook.template b/builds/VyOS-proxy/hooks/hook.template deleted file mode 100644 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/hook.template +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/install b/builds/VyOS-proxy/hooks/install deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/install +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/leader-elected b/builds/VyOS-proxy/hooks/leader-elected deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/leader-elected +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/leader-settings-changed b/builds/VyOS-proxy/hooks/leader-settings-changed deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/leader-settings-changed +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/start b/builds/VyOS-proxy/hooks/start deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/start +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/stop b/builds/VyOS-proxy/hooks/stop deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/stop +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/update-status b/builds/VyOS-proxy/hooks/update-status deleted file mode 100755 index d36afe17f52f88dee796278bed7e677e828a5a74..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/update-status +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import sys -sys.path.append('lib') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/hooks/upgrade-charm b/builds/VyOS-proxy/hooks/upgrade-charm deleted file mode 100755 index 1465e8ed4a991d7904e797b2ce123e1b3d6b93de..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/hooks/upgrade-charm +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 - -# Load modules from $CHARM_DIR/lib -import os -import sys -sys.path.append('lib') - -# This is an upgrade-charm context, make sure we install latest deps -if not os.path.exists('wheelhouse/.upgrade'): - open('wheelhouse/.upgrade', 'w').close() - if os.path.exists('wheelhouse/.bootstrapped'): - os.unlink('wheelhouse/.bootstrapped') -else: - os.unlink('wheelhouse/.upgrade') - -from charms.layer import basic -basic.bootstrap_charm_deps() -basic.init_config_states() - - -# This will load and run the appropriate @hook and other decorated -# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive, -# and $CHARM_DIR/hooks/relations. -# -# See https://jujucharms.com/docs/stable/authors-charm-building -# for more information on this pattern. -from charms.reactive import main -main() diff --git a/builds/VyOS-proxy/lib/charms/layer/__init__.py b/builds/VyOS-proxy/lib/charms/layer/__init__.py deleted file mode 100644 index 33d37e909fccdbf4cd566eedb813ae9385b5ae0d..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/lib/charms/layer/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -import os - - -class LayerOptions(dict): - def __init__(self, layer_file, section=None): - import yaml # defer, might not be available until bootstrap - with open(layer_file) as f: - layer = yaml.safe_load(f.read()) - opts = layer.get('options', {}) - if section and section in opts: - super(LayerOptions, self).__init__(opts.get(section)) - else: - super(LayerOptions, self).__init__(opts) - - -def options(section=None, layer_file=None): - if not layer_file: - base_dir = os.environ.get('CHARM_DIR', os.getcwd()) - layer_file = os.path.join(base_dir, 'layer.yaml') - - return LayerOptions(layer_file, section) diff --git a/builds/VyOS-proxy/lib/charms/layer/basic.py b/builds/VyOS-proxy/lib/charms/layer/basic.py deleted file mode 100644 index 50bd6251ea61b2534f368d9a74bd658db07d4ebf..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/lib/charms/layer/basic.py +++ /dev/null @@ -1,159 +0,0 @@ -import os -import sys -import shutil -import platform -from glob import glob -from subprocess import check_call - -from charms.layer.execd import execd_preinstall - - -def bootstrap_charm_deps(): - """ - Set up the base charm dependencies so that the reactive system can run. - """ - # execd must happen first, before any attempt to install packages or - # access the network, because sites use this hook to do bespoke - # configuration and install secrets so the rest of this bootstrap - # and the charm itself can actually succeed. This call does nothing - # unless the operator has created and populated $CHARM_DIR/exec.d. - execd_preinstall() - # ensure that $CHARM_DIR/bin is on the path, for helper scripts - os.environ['PATH'] += ':%s' % os.path.join(os.environ['CHARM_DIR'], 'bin') - venv = os.path.abspath('../.venv') - vbin = os.path.join(venv, 'bin') - vpip = os.path.join(vbin, 'pip') - vpy = os.path.join(vbin, 'python') - if os.path.exists('wheelhouse/.bootstrapped'): - from charms import layer - cfg = layer.options('basic') - if cfg.get('use_venv') and '.venv' not in sys.executable: - # activate the venv - os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']]) - reload_interpreter(vpy) - return - # bootstrap wheelhouse - if os.path.exists('wheelhouse'): - with open('/root/.pydistutils.cfg', 'w') as fp: - # make sure that easy_install also only uses the wheelhouse - # (see https://github.com/pypa/pip/issues/410) - charm_dir = os.environ['CHARM_DIR'] - fp.writelines([ - "[easy_install]\n", - "allow_hosts = ''\n", - "find_links = file://{}/wheelhouse/\n".format(charm_dir), - ]) - apt_install(['python3-pip', 'python3-setuptools', 'python3-yaml']) - from charms import layer - cfg = layer.options('basic') - # include packages defined in layer.yaml - apt_install(cfg.get('packages', [])) - # if we're using a venv, set it up - if cfg.get('use_venv'): - if not os.path.exists(venv): - distname, version, series = platform.linux_distribution() - if series in ('precise', 'trusty'): - apt_install(['python-virtualenv']) - else: - apt_install(['virtualenv']) - cmd = ['virtualenv', '-ppython3', '--never-download', venv] - if cfg.get('include_system_packages'): - cmd.append('--system-site-packages') - check_call(cmd) - os.environ['PATH'] = ':'.join([vbin, os.environ['PATH']]) - pip = vpip - else: - pip = 'pip3' - # save a copy of system pip to prevent `pip3 install -U pip` - # from changing it - if os.path.exists('/usr/bin/pip'): - shutil.copy2('/usr/bin/pip', '/usr/bin/pip.save') - # need newer pip, to fix spurious Double Requirement error: - # https://github.com/pypa/pip/issues/56 - check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse', - 'pip']) - # install the rest of the wheelhouse deps - check_call([pip, 'install', '-U', '--no-index', '-f', 'wheelhouse'] + - glob('wheelhouse/*')) - if not cfg.get('use_venv'): - # restore system pip to prevent `pip3 install -U pip` - # from changing it - if os.path.exists('/usr/bin/pip.save'): - shutil.copy2('/usr/bin/pip.save', '/usr/bin/pip') - os.remove('/usr/bin/pip.save') - os.remove('/root/.pydistutils.cfg') - # flag us as having already bootstrapped so we don't do it again - open('wheelhouse/.bootstrapped', 'w').close() - # Ensure that the newly bootstrapped libs are available. - # Note: this only seems to be an issue with namespace packages. - # Non-namespace-package libs (e.g., charmhelpers) are available - # without having to reload the interpreter. :/ - reload_interpreter(vpy if cfg.get('use_venv') else sys.argv[0]) - - -def reload_interpreter(python): - """ - Reload the python interpreter to ensure that all deps are available. - - Newly installed modules in namespace packages sometimes seemt to - not be picked up by Python 3. - """ - os.execle(python, python, sys.argv[0], os.environ) - - -def apt_install(packages): - """ - Install apt packages. - - This ensures a consistent set of options that are often missed but - should really be set. - """ - if isinstance(packages, (str, bytes)): - packages = [packages] - - env = os.environ.copy() - - if 'DEBIAN_FRONTEND' not in env: - env['DEBIAN_FRONTEND'] = 'noninteractive' - - cmd = ['apt-get', - '--option=Dpkg::Options::=--force-confold', - '--assume-yes', - 'install'] - check_call(cmd + packages, env=env) - - -def init_config_states(): - import yaml - from charmhelpers.core import hookenv - from charms.reactive import set_state - from charms.reactive import toggle_state - config = hookenv.config() - config_defaults = {} - config_defs = {} - config_yaml = os.path.join(hookenv.charm_dir(), 'config.yaml') - if os.path.exists(config_yaml): - with open(config_yaml) as fp: - config_defs = yaml.load(fp).get('options', {}) - config_defaults = {key: value.get('default') - for key, value in config_defs.items()} - for opt in config_defs.keys(): - if config.changed(opt): - set_state('config.changed') - set_state('config.changed.{}'.format(opt)) - toggle_state('config.set.{}'.format(opt), config.get(opt)) - toggle_state('config.default.{}'.format(opt), - config.get(opt) == config_defaults[opt]) - hookenv.atexit(clear_config_states) - - -def clear_config_states(): - from charmhelpers.core import hookenv, unitdata - from charms.reactive import remove_state - config = hookenv.config() - remove_state('config.changed') - for opt in config.keys(): - remove_state('config.changed.{}'.format(opt)) - remove_state('config.set.{}'.format(opt)) - remove_state('config.default.{}'.format(opt)) - unitdata.kv().flush() diff --git a/builds/VyOS-proxy/lib/charms/layer/execd.py b/builds/VyOS-proxy/lib/charms/layer/execd.py deleted file mode 100644 index 3057419031b99856c1fe5cd8a15975b0fc2ff50d..0000000000000000000000000000000000000000 --- a/builds/VyOS-proxy/lib/charms/layer/execd.py +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright 2014-2016 Canonical Limited. -# -# This file is part of layer-basic, the reactive base layer for Juju. -# -# charm-helpers is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 as -# published by the Free Software Foundation. -# -# charm-helpers is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with charm-helpers. If not, see . - -# This module may only import from the Python standard library. -import os -import sys -import subprocess -import time - -''' -execd/preinstall - -It is often necessary to configure and reconfigure machines -after provisioning, but before attempting to run the charm. -Common examples are specialized network configuration, enabling -of custom hardware, non-standard disk partitioning and filesystems, -adding secrets and keys required for using a secured network. - -The reactive framework's base layer invokes this mechanism as -early as possible, before any network access is made or dependencies -unpacked or non-standard modules imported (including the charms.reactive -framework itself). - -Operators needing to use this functionality may branch a charm and -create an exec.d directory in it. The exec.d directory in turn contains -one or more subdirectories, each of which contains an executable called -charm-pre-install and any other required resources. The charm-pre-install -executables are run, and if successful, state saved so they will not be -run again. - - $CHARM_DIR/exec.d/mynamespace/charm-pre-install - -An alternative to branching a charm is to compose a new charm that contains -the exec.d directory, using the original charm as a layer, - -A charm author could also abuse this mechanism to modify the charm -environment in unusual ways, but for most purposes it is saner to use -charmhelpers.core.hookenv.atstart(). -''' - - -def default_execd_dir(): - return os.path.join(os.environ['CHARM_DIR'], 'exec.d') - - -def execd_module_paths(execd_dir=None): - """Generate a list of full paths to modules within execd_dir.""" - if not execd_dir: - execd_dir = default_execd_dir() - - if not os.path.exists(execd_dir): - return - - for subpath in os.listdir(execd_dir): - module = os.path.join(execd_dir, subpath) - if os.path.isdir(module): - yield module - - -def execd_submodule_paths(command, execd_dir=None): - """Generate a list of full paths to the specified command within exec_dir. - """ - for module_path in execd_module_paths(execd_dir): - path = os.path.join(module_path, command) - if os.access(path, os.X_OK) and os.path.isfile(path): - yield path - - -def execd_sentinel_path(submodule_path): - module_path = os.path.dirname(submodule_path) - execd_path = os.path.dirname(module_path) - module_name = os.path.basename(module_path) - submodule_name = os.path.basename(submodule_path) - return os.path.join(execd_path, - '.{}_{}.done'.format(module_name, submodule_name)) - - -def execd_run(command, execd_dir=None, stop_on_error=True, stderr=None): - """Run command for each module within execd_dir which defines it.""" - if stderr is None: - stderr = sys.stdout - for submodule_path in execd_submodule_paths(command, execd_dir): - # Only run each execd once. We cannot simply run them in the - # install hook, as potentially storage hooks are run before that. - # We cannot rely on them being idempotent. - sentinel = execd_sentinel_path(submodule_path) - if os.path.exists(sentinel): - continue - - try: - subprocess.check_call([submodule_path], stderr=stderr, - universal_newlines=True) - with open(sentinel, 'w') as f: - f.write('{} ran successfully {}\n'.format(submodule_path, - time.ctime())) - f.write('Removing this file will cause it to be run again\n') - except subprocess.CalledProcessError as e: - # Logs get the details. We can't use juju-log, as the - # output may be substantial and exceed command line - # length limits. - print("ERROR ({}) running {}".format(e.returncode, e.cmd), - file=stderr) - print("STDOUT<