def enable_chassis_reactive_code():
    charm.use_defaults(
        'charm.installed',
        'config.changed',
        'config.rendered',
        'update-status',
        'upgrade-charm',
        'certificates.available',
    )
def initialize_ovsdbs():
    with charm.provide_charm_instance() as ovn_charm:
        # this will render the ``/etc/default/ovn-central`` file without
        # configuration for the cluster remote addresses which in turn
        # leads ``ovn-ctl`` on the path to initializing a new cluster
        ovn_charm.render_with_interfaces([])
        if ovn_charm.enable_services():
            # belated enablement of default certificates handler due to the
            # ``ovsdb-server`` processes must have finished database
            # initialization and be running prior to configuring TLS
            charm.use_defaults('certificates.available')
            reactive.set_flag('config.rendered')
        ovn_charm.assess_status()
Example #3
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms.reactive as reactive

import charms_openstack.charm as charm

# This charm's library contains all of the handler code associated with
# aodh
import charm.openstack.aodh as aodh

charm.use_defaults('certificates.available', )

# Minimal inferfaces required for operation
MINIMAL_INTERFACES = [
    'shared-db.available',
    'identity-service.available',
    'amqp.available',
]


# use a synthetic state to ensure that it get it to be installed independent of
# the install hook.
@reactive.when_not('charm.installed')
def install_packages():
    aodh.install()
    reactive.set_state('charm.installed')
Example #4
0
#  https://charmsreactive.readthedocs.io/en/latest/
#  https://docs.openstack.org/charm-guide/latest/charm-anatomy.html

import charms_openstack.charm as charm
import charms.reactive as reactive

# This charm's library contains all of the handler code associated with
# this charm -- we will use the auto-discovery feature of charms.openstack
# to get the definitions for the charm.
import charms_openstack.bus as bus
bus.discover()

charm.use_defaults(
    'charm.installed',
    'update-status',
    'upgrade-charm',
    #'keystone-backend.connected', ##need to define this on metadata (why do I need this?)
    # I don't think I will need this because I'm not implementing an interface
)


@reactive.when('config.changed')  #detects any change on config file
@reactive.when_not('keystone-ldap.installed')  # not sure about this
def config():
    #this will get the instance of the charm that we are deploying
    with charm.provide_charm_instance() as keystone_charm:
        ##calls the method from the created charm
        keystone_charm.config_ldap()
        reactive.set_flag('config.finished')

import charm.openstack.magnum.magnum as magnum  # noqa
import charms.reactive as reactive
import charms.leadership as leadership
import charms_openstack.charm as charm
import charmhelpers.core.hookenv as hookenv

from charmhelpers.contrib.openstack import context
from charmhelpers.core import templating

# Use the charms.openstack defaults for common states and hooks
charm.use_defaults(
    'charm.installed',
    'amqp.connected',
    'shared-db.connected',
    'identity-service.available',  # enables SSL support
    'config.changed',
    'update-status',
    'upgrade-charm',
    'certificates.available',
    'cluster.available')


@reactive.when('shared-db.available')
@reactive.when('identity-service.available')
@reactive.when('amqp.available')
@reactive.when_not('is-update-status-hook')
def render_config(*interfaces):
    with charm.provide_charm_instance() as magnum_charm:
        magnum_charm.render_with_interfaces(interfaces)
        magnum_charm.assess_status()
    reactive.set_state('config.complete')
# Copyright 2018 Cloudbase Solutions

from __future__ import absolute_import

import charms.reactive as reactive
import charmhelpers.core.hookenv as hookenv

import charms_openstack.charm as charm
import charm.openstack.magnum.magnum as magnum  # noqa

# Use the charms.openstack defaults for common states and hooks
charm.use_defaults(
    'charm.installed',
    'amqp.connected',
    'shared-db.connected',
    'identity-service.available',  # enables SSL support
    'config.changed',
    'update-status')


@reactive.when('shared-db.available')
@reactive.when('identity-service.available')
@reactive.when('amqp.available')
@reactive.when('trustee-credentials.available')
def render_stuff(*args):
    hookenv.log("about to call the render_configs with {}".format(args))
    with charm.provide_charm_instance() as magnum_charm:
        magnum_charm.render_with_interfaces(charm.optional_interfaces(args))
        magnum_charm.assess_status()
    reactive.set_state('config.complete')
Example #7
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms.reactive as reactive

import charms_openstack.bus
import charms_openstack.charm as charm

charms_openstack.bus.discover()

# Use the charms.openstack defaults for common states and hooks
charm.use_defaults('charm.installed', 'config.changed', 'update-status',
                   'upgrade-charm')


@reactive.when('dashboard.available')
def dashboard_available():
    """Relation to OpenStack Dashboard principal charm complete.
    """
    # config and restart is handled by package install, just update our status
    with charm.provide_charm_instance() as watcher_dashboard_charm:
        watcher_dashboard_charm.assess_status()
import charms_openstack.charm as charm
import charms.reactive as reactive

import charm.openstack.netapp as netapp
assert netapp

charm.use_defaults('charm.installed')


@reactive.when_any('storage-backend.joined', 'storage-backend.changed')
@reactive.when_not('storage-backend.available')
def storage_backend():
    with charm.provide_charm_instance() as charm_class:
        charm_class.set_relation_data()
    reactive.set_state('storage-backend.available')


@reactive.when('config.changed')
def update_config():
    reactive.remove_state('storage-backend.available')
    with charm.provide_charm_instance() as charm_class:
        charm_class.set_relation_data()
    reactive.set_state('storage-backend.available')
import charm.openstack.designate as designate


COMPLETE_INTERFACE_STATES = [
    'dns-backend.available',
    'shared-db.available',
    'identity-service.available',
    'amqp.available',
]


# wire in defaults for various interfaces and default states
openstack_charm.use_defaults(
    'charm.installed',
    'amqp.connected',
    'shared-db.connected',
    'identity-service.connected',
    'identity-service.available',  # Enables the SSL handler
    'config.changed',
    'update-status')


@reactive.when_not('base-config.rendered')
@reactive.when(*COMPLETE_INTERFACE_STATES)
@openstack_charm.optional_interface('cluster.available')
@openstack_charm.provide_charm_instance
def configure_designate_basic(designate_charm, *args):
    """Configure the minimum to boostrap designate"""
    designate_charm.render_base_config(args)
    reactive.set_state('base-config.rendered')

def enable_default_certificates():
    # belated enablement of default certificates handler due to the
    # ``ovsdb-server`` processes must have finished database
    # initialization and be running prior to configuring TLS
    charm.use_defaults('certificates.available')
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms.reactive as reactive

from charms_openstack.charm import (
    provide_charm_instance,
    use_defaults,
)
import charm.openstack.infoblox as infoblox  # noqa


use_defaults('update-status')


@reactive.when_not('infoblox.installed')
def install_infoblox():
    with provide_charm_instance() as charm_class:
        charm_class.install()
    reactive.set_state('infoblox.installed')


@reactive.hook('config-changed')
def config_changed():
    reactive.remove_state('neutron.configured')
    reactive.remove_state('designate.configured')

Example #12
0
# See the License for the specific language governing permissions and
# limitations under the License.

import charms_openstack.charm as charm
import charms.reactive as reactive

# This charm's library contains all of the handler code associated with
# dmapi
import charm.openstack.dmapi as dmapi  # noqa

charm.use_defaults(
    "charm.installed",
    "amqp.connected",
    "shared-db.connected",
    "identity-service.connected",
    "identity-service.available",  # enables SSL support
    "config.changed",
    "update-status",
    "certificates.available",
    "cluster.available",
)


@reactive.when("shared-db.available")
@reactive.when("identity-service.available")
@reactive.when("amqp.available")
def render_config(*args):
    """Render the configuration for charm when all the interfaces are
    available.
    """
    with charm.provide_charm_instance() as charm_class:
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms.reactive as reactive

import charms_openstack.bus
import charms_openstack.charm as charm

charms_openstack.bus.discover()

charm.use_defaults(
    'config.changed',
    'update-status')


@reactive.when_not('charm.installed')
def check_snap_installed():
    # Installation is handled by the ``snap`` layer, just update our status.
    with charm.provide_charm_instance() as instance:
        instance.assess_status()
    reactive.set_flag('charm.installed')


@reactive.when('identity-credentials.connected')
@reactive.when_not('identity-credentials.available')
def request_credentials():
    keystone_endpoint = reactive.endpoint_from_flag(
Example #14
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms_openstack.charm as charm

# This charm's library contains all of the handler code associated with
# trilio_horizon_plugin
import charm.openstack.trilio_horizon_plugin as trilio_horizon_plugin  # noqa

charm.use_defaults("charm.installed", "config.changed", "update-status")
# limitations under the License.

import charmhelpers.core as ch_core

import charms.reactive as reactive

import charms_openstack.bus
import charms_openstack.charm as charm

charms_openstack.bus.discover()

# Use the charms.openstack defaults for common states and hooks
charm.use_defaults(
    'charm.installed',
    'config.changed',
    'charm.default-select-release',
    'update-status',
    'upgrade-charm',
    'certificates.available',
)


@reactive.when_none('neutron-plugin.db_migration', 'neutron-plugin.available')
@reactive.when('charm.installed')
def maybe_flag_db_migration():
    with charm.provide_charm_instance() as instance:
        if instance.db_migration_needed:
            reactive.set_flag('neutron-plugin.db_migration')


@reactive.when_none('neutron-plugin.available', 'run-default-update-status')
@reactive.when('neutron-plugin.connected')
import charms.reactive as reactive
import charmhelpers.core.hookenv as hookenv

import charms_openstack.charm as charm

# This charm's library contains all of the handler code associated with
# barbican -- we need to import it to get the definitions for the charm.
import charm.openstack.barbican as barbican  # noqa


# Use the charms.openstack defaults for common states and hooks
charm.use_defaults(
    'charm.installed',
    'amqp.connected',
    'shared-db.connected',
    'identity-service.connected',
    'identity-service.available',  # enables SSL support
    'config.changed',
    'update-status')


# Note that because of the way reactive.when works, (which is to 'find' the
# __code__ segment of the decorated function, it's very, very difficult to add
# other kinds of decorators here.  This rules out adding other things into the
# charm args list.  It is also CPython dependent.
@reactive.when('shared-db.available')
@reactive.when('identity-service.available')
@reactive.when('amqp.available')
def render_stuff(*args):
    """Render the configuration for Barbican when all the interfaces are
    available.
Example #17
0
import charmhelpers.core.hookenv as hookenv
import charmhelpers.core.host as host
import charms.reactive.relations as relations

from charmhelpers.contrib.network import ip as ch_ip

DESIGNATE_DIR = '/etc/designate'
DESIGNATE_DEFAULT = '/etc/default/openstack'
DESIGNATE_CONF = DESIGNATE_DIR + '/designate.conf'
POOLS_YAML = DESIGNATE_DIR + '/pools.yaml'
RNDC_KEY_CONF = DESIGNATE_DIR + '/rndc.key'
NOVA_SINK_FILE = DESIGNATE_DIR + '/conf.d/nova_sink.cfg'
NEUTRON_SINK_FILE = DESIGNATE_DIR + '/conf.d/neutron_sink.cfg'
RC_FILE = '/root/novarc'
openstack_charm.use_defaults(
    'charm.default-select-release',
    'upgrade-charm',
)


class DesignateDBAdapter(openstack_adapters.DatabaseRelationAdapter):
    """Get database URIs for the two designate databases"""

    @property
    def designate_uri(self):
        """URI for designate DB"""
        return self.get_uri(prefix='designate')

    @property
    def designate_pool_uri(self):
        """URI for designate pool DB"""
        return self.get_uri(prefix='dpm')
Example #18
0
import os
import charms_openstack.charm as ldap_charm
import charmhelpers.core.hookenv as ch_hookenv  # noqa
#https://github.com/juju-solutions/charms.templating.jinja2
from charms.templating.jinja2 import render

#https://charm-helpers.readthedocs.io/en/latest/examples/config.html
hooks = ch_hookenv.Hooks()

ldap_charm.use_defaults('charm.default-select-release')

LDAP_CONFIG_FILE_DIR = "/etc/keystone/domains/"
LDAP_CONFIG_FILE = LDAP_CONFIG_FILE_DIR + "keystone.{}.conf"
TEMPLATE = "keystone_ldap.j2"

class CharmKeystoneLDAP():

    name = 'keystone ldap configuration'
    version = 'v0.0.1'

    def config_ldap(self):
        """
        Define the destination LDAP server in the /etc/keystone/keystone.conf or
        /etc/keystone/domains/keystone.DOMAIN_NAME.conf :

        [ldap]
        url = ldap://localhost
        user = dc=Manager,dc=example,dc=org
        password = samplepassword
        suffix = dc=example,dc=org
        """
# limitations under the License.

import charms.reactive as reactive

from charmhelpers.core.hookenv import (
    config,
    log,
)

from charms_openstack.charm import (
    provide_charm_instance,
    use_defaults,
)

use_defaults(
    'charm.default-select-release',
    'update-status',
)


@reactive.when_not('arista-package.installed')
@reactive.when('neutron-plugin-api-subordinate.available')
def install_arista():
    with provide_charm_instance() as charm_class:
        charm_class.install()
    reactive.set_state('arista-package.installed')


@reactive.when_any('config.changed.eapi-host', 'config.changed.eapi-username',
                   'config.changed.eapi-password',
                   'config.changed.region-name', 'config.changed.api-type',
                   'neutron-plugin-api-subordinate.connected')
# limitations under the License.

# this is just for the reactive handlers and calls into the charm.
from __future__ import absolute_import

import charms.reactive as reactive
import charms_openstack.charm as charm

# This charm's library contains all of the handler code associated with trove
import charm.openstack.trove as trove

charm.use_defaults(
    'config.changed',
    'amqp.connected',
    'identity-service.available',
    'charm.installed',
    'upgrade-charm',
    'update-status',
    'shared-db.connected',
)


# this is to check if ha is running
@reactive.when('ha.connected')
def cluster_connected(hacluster):
    trove.configure_ha_resources(hacluster)


@reactive.when('identity-service.connected')
def setup_endpoint(keystone):
    trove.setup_endpoint(keystone)
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms_openstack.charm as charm
import charms.reactive as reactive

# This charm's library contains all of the handler code associated with
# sdn_charm
import charm.openstack.group_based_policy as group_based_policy  # noqa

charm.use_defaults('charm.installed', 'update-status')


@reactive.when('neutron-plugin.connected')
def configure_neutron_plugin(neutron_plugin):
    with charm.provide_charm_instance() as charm_class:
        neutron_plugin.configure_plugin(
            plugin='group-based-policy',
            config={
                "neutron-api": {
                    "/etc/neutron/neutron.conf": {
                        "sections": {
                            'DEFAULT': [
                                ('service_plugins',
                                 'router,firewall,lbaas,vpnaas,metering,group_policy,servicechain'
                                 ),
import charms.reactive as reactive
import charms.leadership as leadership

import charms_openstack.bus
import charms_openstack.charm as charm

import charmhelpers.core as ch_core
import charmhelpers.contrib.openstack.cert_utils as cert_utils

import charms.coordinator as coordinator
import charm.openstack.mysql_innodb_cluster as mysql_innodb_cluster  # noqa

charms_openstack.bus.discover()

charm.use_defaults('update-status')


@reactive.hook('upgrade-charm')
def custom_upgrade_charm():
    """Custom upgrade charm.

    Fix old style dotted flag names during upgrade-charm hook
    """
    with charm.provide_charm_instance() as instance:
        if reactive.is_flag_set('leadership.is_leader'):
            # Change leadership cluster flags with dots in their names
            instance.update_dotted_flags()
        instance.upgrade_charm()
        instance.assess_status()
# See the License for the specific language governing permissions and
# limitations under the License.

# import to trigger openstack charm metaclass init
import charm.openstack.keystone_ldap  # noqa

import charms_openstack.charm as charm
import charms.reactive as reactive

import charms.reactive.flags as flags

import charmhelpers.core.hookenv as hookenv

charm.use_defaults(
    'charm.installed',
    'update-status',
    'upgrade-charm',
)

# if config has been changed we need to re-evaluate flags
# config.changed is set and cleared (atexit) in layer-basic
flags.register_trigger(when='config.changed',
                       clear_flag='config.rendered')
flags.register_trigger(when='config.changed',
                       clear_flag='config.complete')


@reactive.when('domain-backend.connected')
@reactive.when_not('domain-name-configured')
@reactive.when('config.complete')
def configure_domain_name(domain):
Example #24
0
import charmhelpers.core.hookenv as hookenv
import charmhelpers.core.host as host
import charms.reactive.relations as relations

from charmhelpers.contrib.network import ip as ch_ip

DESIGNATE_DIR = '/etc/designate'
DESIGNATE_DEFAULT = '/etc/default/openstack'
DESIGNATE_CONF = DESIGNATE_DIR + '/designate.conf'
POOLS_YAML = DESIGNATE_DIR + '/pools.yaml'
RNDC_KEY_CONF = DESIGNATE_DIR + '/rndc.key'
NOVA_SINK_FILE = DESIGNATE_DIR + '/conf.d/nova_sink.cfg'
NEUTRON_SINK_FILE = DESIGNATE_DIR + '/conf.d/neutron_sink.cfg'
RC_FILE = '/root/novarc'
openstack_charm.use_defaults(
    'charm.default-select-release',
    'upgrade-charm',
)


class DesignateDBAdapter(openstack_adapters.DatabaseRelationAdapter):
    """Get database URIs for the two designate databases"""
    @property
    def designate_uri(self):
        """URI for designate DB"""
        return self.get_uri(prefix='designate')

    @property
    def designate_pool_uri(self):
        """URI for designate pool DB"""
        return self.get_uri(prefix='dpm')
# limitations under the License.

# this is just for the reactive handlers and calls into the charm.
from __future__ import absolute_import

import charms.reactive as reactive
import charmhelpers.core.hookenv as hookenv

import charms_openstack.charm as charm

# This charm's library contains all of the handler code associated with
# dragent -- we need to import it to get the definitions for the charm.
import charm.openstack.dragent as dragent  # noqa

# Use the charms.openstack defaults for common states and hooks
charm.use_defaults('charm.installed', 'amqp.connected', 'config.changed',
                   'update-status')


@reactive.when('charm.installed')
def debug():
    if not hookenv.config('debug'):
        return
    for key, value in reactive.get_states().items():
        print(key, value)


# Use for testing with the quagga charm
@reactive.when('endpoint.bgp-speaker.joined')
def publish_bgp_info(endpoint):
    endpoint.publish_info(asn=hookenv.config('asn'), passive=True)
Example #26
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import charms_openstack.charm as charm
import charms.reactive as reactive

# This charm's library contains all of the handler code associated with
# trilio_dm
import charm.openstack.trilio_dm as trilio_dm  # noqa

charm.use_defaults(
    "charm.installed",
    "config.changed",
    "update-status",
    "shared-db.connected",
)


@reactive.when("shared-db.available")
@reactive.when("amqp.available")
def render_config(*args):
    """Render the configuration for charm when all the interfaces are
    available.
    """
    ceph = reactive.endpoint_from_flag("ceph.available")
    if ceph:
        args = (ceph, ) + args
    with charm.provide_charm_instance() as charm_instance:
        charm_instance.render_with_interfaces(args)
Example #27
0
import charms_openstack.charm as charm
import charms.reactive as reactive

import boto3
import botocore

import charm.openstack.gnocchi as gnocchi  # noqa

import charmhelpers.core.hookenv as hookenv

charm.use_defaults(
    'charm.installed',
    'shared-db.connected',
    'identity-service.connected',
    'config.changed',
    'config.rendered',
    'update-status',
    'certificates.available',
    'cluster.available',
)

required_interfaces = [
    'coordinator-memcached.available', 'shared-db.available',
    'identity-service.available'
]

if hookenv.config('storage-backend').lower() == 'ceph':
    required_interfaces.append('storage-ceph.pools.available')

storage_config = [
    'config.changed.storage-backend', 'config.changed.s3-endpoint-url',
Example #28
0
import charms_openstack.adapters as openstack_adapters
import charms_openstack.charm as openstack_charm
import charms_openstack.ip as os_ip

from charmhelpers.contrib.openstack.utils import config_flags_parser
from charmhelpers.core.hookenv import (
    config,
    log,
    WARNING
)

WATCHER_CONF = '/etc/watcher/watcher.conf'
WATCHER_WSGI_CONF = '/etc/apache2/sites-available/watcher-api.conf'

openstack_charm.use_defaults('charm.default-select-release')


@openstack_adapters.config_property
def planner_weights(cls):
    conf = config('planner')
    if conf in ['weight', 'workload_stabilization']:
        conf = config_flags_parser(config('planner-config'))
        weights = conf.get('weights', None)
        if not weights:
            log('Provided planner-config dictionary does not contain key '
                'weights - ignoring', level=WARNING)
        else:
            return weights

Example #29
0
import charms.reactive as reactive
import charms.leadership as leadership

import charms_openstack.bus
import charms_openstack.charm as charm

import charmhelpers.core as ch_core

import charm.mysql_innodb_cluster as mysql_innodb_cluster  # noqa

charms_openstack.bus.discover()


charm.use_defaults(
    'config.changed',
    'update-status',
    'upgrade-charm',
    'certificates.available')


@reactive.when('leadership.is_leader')
@reactive.when('snap.installed.mysql-shell')
@reactive.when_not('charm.installed')
def leader_install():
    """Leader install.

    Set passwords and install MySQL packages.
    """
    with charm.provide_charm_instance() as instance:
        instance.install()
        reactive.set_flag("charm.installed")
from charms.reactive.flags import (
    set_flag,
)

# This charm's library contains all of the handler code associated with
# nova_cell_controller -- we need to import it to get the definitions for the
# charm.
import charm.openstack.nova_cell_controller as nova_cell_controller  # noqa


# Use the charms.openstack defaults for common states and hooks
charm.use_defaults(
    'charm.installed',
    'amqp.connected',
    'shared-db.connected',
    'config.changed',
    'cluster.available',
    'update-status')


@reactive.when('identity-credentials.connected')
def request_credentials():
    keystone_relation = endpoint_from_flag(
        'identity-credentials.connected')
    keystone_relation.request_credentials(
        'nova-cell-controller',
        project='services')


# Note that because of the way reactive.when works, (which is to 'find' the