def main():
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)
def main():
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)
Esempio n. 3
0
def main():
    print sys.argv
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)
Esempio n. 4
0
def main():
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)
    os_application_version_set(VERSION_PACKAGE)
def assess_status(configs):
    if is_paused():
        status_set("maintenance",
                   "Unit paused - use 'resume' action "
                   "to resume normal service")
        return

    set_os_workload_status(configs, REQUIRED_INTERFACES)
Esempio n. 6
0
def check_optional_relations(configs):
    required_interfaces = {}
    if enable_nova_metadata():
        required_interfaces['neutron-plugin-api'] = ['neutron-plugin-api']
    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 7
0
def check_optional_relations(configs):
    required_interfaces = {}
    if enable_nova_metadata():
        required_interfaces['neutron-plugin-api'] = ['neutron-plugin-api']
    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
def assess_status():
    """Assess status of current unit."""
    os_application_version_set(VERSION_PACKAGE)
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)

    try:
        bluestore_compression = CephBlueStoreCompressionContext()
        bluestore_compression.validate()
    except ValueError as e:
        status_set('blocked', 'Invalid configuration: {}'.format(str(e)))
def main():
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    required_interfaces = copy.deepcopy(REQUIRED_INTERFACES)
    if config('encrypt'):
        required_interfaces['vault'] = ['secrets-storage']
    set_os_workload_status(CONFIGS,
                           required_interfaces,
                           charm_func=assess_status)
    os_application_version_set(VERSION_PACKAGE)
Esempio n. 10
0
def resume(args):
    """Resume all the swift services.

    @raises Exception if any services fail to start
    """
    for service in args.services:
        started = service_resume(service)
        if not started:
            raise Exception("{} didn't start cleanly.".format(service))
    with HookData()():
        kv().set('unit-paused', False)
    set_os_workload_status(CONFIGS,
                           REQUIRED_INTERFACES,
                           charm_func=assess_status)
Esempio n. 11
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids("ha"):
        required_interfaces["ha"] = ["cluster"]
        try:
            get_hacluster_config()
        except:
            return ("blocked", "hacluster missing configuration: " "vip, vip_iface, vip_cidr")

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return "unknown", "No optional relations"
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked', 'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked',
                    'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ceph'):
        required_interfaces['storage-backend'] = ['ceph']

    if relation_ids('neutron-plugin'):
        required_interfaces['neutron-plugin'] = ['neutron-plugin']

    if relation_ids('shared-db') or relation_ids('pgsql-db'):
        required_interfaces['database'] = ['shared-db', 'pgsql-db']

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 15
0
def assess_status(configs):
    """Assess status of current unit

    Decides what the state of the unit should be based on the current
    configuration.

    @param configs: a templating.OSConfigRenderer() object
    """

    if is_paused():
        status_set("maintenance",
                   "Paused. Use 'resume' action to resume normal service.")
        return

    # set the status according to the current state of the contexts
    set_os_workload_status(
        configs, REQUIRED_INTERFACES, charm_func=check_optional_relations)
Esempio n. 16
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked',
                    'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')
    if cmp_pkgrevno('radosgw', '0.55') >= 0 and \
            relation_ids('identity-service'):
        required_interfaces['identity'] = ['identity-service']
    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 17
0
def assess_status(configs):
    """Assess status of current unit"""
    required_interfaces = {}

    if is_paused():
        status_set("maintenance",
                   "Paused. Use 'resume' action to resume normal service.")
        return

    # Check for required swift-storage relation
    if len(relation_ids('swift-storage')) < 1:
        status_set('blocked', 'Missing relation: storage')
        return

    # Verify allowed_hosts is populated with enough unit IP addresses
    ctxt = SwiftRingContext()()
    if len(ctxt['allowed_hosts']) < config('replicas'):
        status_set('blocked', 'Not enough related storage nodes')
        return

    # Verify there are enough storage zones to satisfy minimum replicas
    rings = [r for r in SWIFT_RINGS.itervalues()]
    if not has_minimum_zones(rings):
        status_set('blocked', 'Not enough storage zones for minimum replicas')
        return

    if config('prefer-ipv6'):
        for rid in relation_ids('swift-storage'):
            for unit in related_units(rid):
                addr = relation_get(attribute='private-address', unit=unit,
                                    rid=rid)
                if not is_ipv6(addr):
                    status_set('blocked', 'Did not get IPv6 address from '
                               'storage relation (got=%s)' % (addr))
                    return

    if relation_ids('identity-service'):
        required_interfaces['identity'] = ['identity-service']

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
    else:
        status_set('active', 'Unit is ready')
Esempio n. 18
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids("ha"):
        required_interfaces["ha"] = ["cluster"]
        try:
            get_hacluster_config()
        except:
            return ("blocked", "hacluster missing configuration: " "vip, vip_iface, vip_cidr")

    if relation_ids("ceph") or relation_ids("object-store"):
        required_interfaces["storage-backend"] = ["ceph", "object-store"]

    if relation_ids("amqp"):
        required_interfaces["messaging"] = ["amqp"]

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return "unknown", "No optional relations"
Esempio n. 19
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked', 'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')
    if relation_ids('quantum-network-service'):
        required_interfaces['quantum'] = ['quantum-network-service']
    if relation_ids('cinder-volume-service'):
        required_interfaces['cinder'] = ['cinder-volume-service']
    if relation_ids('neutron-api'):
        required_interfaces['neutron-api'] = ['neutron-api']
    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 20
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked', 'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')

    if relation_ids('ceph') or relation_ids('object-store'):
        required_interfaces['storage-backend'] = ['ceph', 'object-store']

    if relation_ids('amqp'):
        required_interfaces['messaging'] = ['amqp']

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked',
                    'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')
    if relation_ids('quantum-network-service'):
        required_interfaces['quantum'] = ['quantum-network-service']
    if relation_ids('cinder-volume-service'):
        required_interfaces['cinder'] = ['cinder-volume-service']
    if relation_ids('neutron-api'):
        required_interfaces['neutron-api'] = ['neutron-api']
    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 22
0
def check_optional_relations(configs):
    required_interfaces = {}
    if relation_ids('ha'):
        required_interfaces['ha'] = ['cluster']
        try:
            get_hacluster_config()
        except:
            return ('blocked',
                    'hacluster missing configuration: '
                    'vip, vip_iface, vip_cidr')

    if relation_ids('ceph') or relation_ids('object-store'):
        required_interfaces['storage-backend'] = ['ceph', 'object-store']

    if relation_ids('amqp'):
        required_interfaces['messaging'] = ['amqp']

    if required_interfaces:
        set_os_workload_status(configs, required_interfaces)
        return status_get()
    else:
        return 'unknown', 'No optional relations'
Esempio n. 23
0
            'res_monitor': 'op monitor interval="60s"',
        }
        clones = {
            'cl_monitor': 'res_monitor meta interleave="true"',
        }

        relation_set(corosync_bindiface=cluster_config['ha-bindiface'],
                     corosync_mcastport=cluster_config['ha-mcastport'],
                     resources=resources,
                     resource_params=resource_params,
                     clones=clones)


@hooks.hook('ha-relation-departed')
def ha_relation_destroyed():
    # If e.g. we want to upgrade to Juno and use native Neutron HA support then
    # we need to un-corosync-cluster to enable the transition.
    if config('ha-legacy-mode'):
        stop_neutron_ha_monitor_daemon()
        remove_legacy_ha_files()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS,
                           REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)
        resource_params = {
            'res_monitor': 'op monitor interval="60s"',
        }
        clones = {
            'cl_monitor': 'res_monitor meta interleave="true"',
        }

        relation_set(corosync_bindiface=cluster_config['ha-bindiface'],
                     corosync_mcastport=cluster_config['ha-mcastport'],
                     resources=resources,
                     resource_params=resource_params,
                     clones=clones)


@hooks.hook('ha-relation-departed')
def ha_relation_destroyed():
    # If e.g. we want to upgrade to Juno and use native Neutron HA support then
    # we need to un-corosync-cluster to enable the transition.
    if config('ha-legacy-mode'):
        stop_neutron_ha_monitor_daemon()
        remove_legacy_ha_files()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
                           charm_func=check_optional_relations)
Esempio n. 25
0
    CONFIGS.write(CINDER_CONF)


@hooks.hook('nrpe-external-master-relation-joined',
            'nrpe-external-master-relation-changed')
def update_nrpe_config():
    # python-dbus is used by check_upstart_job
    apt_install('python-dbus')
    hostname = nrpe.get_nagios_hostname()
    current_unit = nrpe.get_nagios_unit_name()
    nrpe_setup = nrpe.NRPE(hostname=hostname)
    nrpe.copy_nrpe_checks()
    nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
    nrpe.add_haproxy_checks(nrpe_setup, current_unit)
    nrpe_setup.write()


@hooks.hook('update-status')
@harden()
def update_status():
    log('Updating status.')


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        juju_log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, required_interfaces(),
                           charm_func=check_optional_relations)
Esempio n. 26
0
    )


@hooks.hook('pre-series-upgrade')
def pre_series_upgrade():
    log("Running prepare series upgrade hook", "INFO")
    # In order to indicate the step of the series upgrade process for
    # administrators and automated scripts, the charm sets the paused and
    # upgrading states.
    set_unit_paused()
    set_unit_upgrading()


@hooks.hook('post-series-upgrade')
def post_series_upgrade():
    log("Running complete series upgrade hook", "INFO")
    # In order to indicate the step of the series upgrade process for
    # administrators and automated scripts, the charm clears the paused and
    # upgrading states.
    clear_unit_paused()
    clear_unit_upgrading()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)
    os_application_version_set(VERSION_PACKAGE)
Esempio n. 27
0
        #              this will need to be conditional on whether the
        #              configured driver is stateless or not.
        relation_set(relation_id=rel_id, stateless=True)


@hooks.hook('backup-backend-relation-changed')
def backup_backend_changed():
    # NOTE(jamespage) recall backup_backend as this only ever
    # changes post initial creation if the cinder charm is upgraded to a new
    # version of openstack.
    backup_backend_joined()


@hooks.hook('upgrade-charm')
@restart_on_change(restart_map())
def upgrade_charm():
    if 'ceph' in CONFIGS.complete_contexts():
        CONFIGS.write_all()
        set_ceph_env_variables(service=service_name())
        for rid in relation_ids('backup-backend'):
            backup_backend_joined(rid)


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)
    os_application_version_set(VERSION_PACKAGE)