コード例 #1
0
ファイル: hooks.py プロジェクト: AdamIsrael/reddit-charm
def config_changed():
    config = hookenv.config()

    for key in config:
        if config.changed(key):
            log("config['{}'] changed from {} to {}".format(
                key, config.previous(key), config[key]))

    if config.changed('development-mode'):
        if config['development-mode']:
            # Development mode: Engage!
            log('Turning on development mode')
            cmd = """
reddit-run %s/r2/models/populatedb.py -c 'populate()'
""" % REDDIT_INSTALL_PATH

            log(cmd)
            subprocess.call(cmd)
            # cd $REDDIT_HOME/src/reddit/r2
            # reddit-run r2/models/populatedb.py -c 'populate()'

        else:
            log('Turning off development mode')
    else:
        log('Development mode not changed')
    config.save()
    start()
コード例 #2
0
 def config_changed(self):
     changed = False
     if config.changed("http_proxy") or config.changed(
             "https_proxy") or config.changed("no_proxy"):
         self._render_config()
         changed = True
     return changed
コード例 #3
0
def config_changed():
    if config.changed("nested_mode"):
        raise Exception('Nested mode cannot be changed after deployment.')
    # TODO: analyze other params and raise exception if readonly params were changed

    utils.update_nrpe_config()
    if config.changed("control-network"):
        settings = {'private-address': common_utils.get_ip()}
        rnames = ("contrail-controller", "contrail-kubernetes-config")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)

    _notify_contrail_kubernetes_node()
    if config.changed("kubernetes_api_hostname") or config.changed(
            "kubernetes_api_secure_port"):
        _notify_controller()

    config[
        "config_analytics_ssl_available"] = common_utils.is_config_analytics_ssl_available(
        )
    config.save()

    docker_utils.config_changed()
    utils.update_charm_status()
コード例 #4
0
def config_changed():
    utils.update_nrpe_config()
    # Charm doesn't support changing of some parameters.
    if config.changed("dpdk"):
        raise Exception("Configuration parameter dpdk couldn't be changed")
    if config.changed("l3mh-cidr"):
        raise Exception(
            "Configuration parameter l3mh-cidr couldn't be changed")
    # Charm doesn't support changing container runtime (check for empty value after upgrade).
    if config.changed("container_runtime") and config.previous(
            "container_runtime"):
        raise Exception(
            "Configuration parameter container_runtime couldn't be changed")

    if not config["dpdk"] and (config.changed("kernel-hugepages-1g")
                               or config.changed("kernel-hugepages-2m")):
        utils.prepare_hugepages_kernel_mode()
    common_utils.container_engine().config_changed()
    utils.pull_images()
    utils.update_charm_status()

    # leave it as latest - in case of exception in previous steps
    # config.changed doesn't work sometimes...
    if config.get("saved-image-tag") != config["image-tag"]:
        utils.update_ziu("image-tag")
        config["saved-image-tag"] = config["image-tag"]
        config.save()
コード例 #5
0
def config_changed():
    utils.update_nrpe_config()
    auth_mode = config.get("auth-mode")
    if auth_mode not in ("rbac", "cloud-admin", "no-auth"):
        raise Exception("Config is invalid. auth-mode must one of: "
                        "rbac, cloud-admin, no-auth.")

    if config.changed("control-network") or config.changed("data-network"):
        ip = common_utils.get_ip()
        data_ip = common_utils.get_ip(config_param="data-network", fallback=ip)

        rel_settings = {"private-address": ip}
        for rname in ("http-services", "https-services"):
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=rel_settings)

        cluster_settings = {"unit-address": ip, "data-address": data_ip}
        if config.get('local-rabbitmq-hostname-resolution'):
            cluster_settings.update({
                "rabbitmq-hostname":
                utils.get_contrail_rabbit_hostname(),
            })
            # this will also take care of updating the hostname in case
            # control-network changes to something different although
            # such host reconfiguration is unlikely
            utils.update_rabbitmq_cluster_hostnames()
        for rid in relation_ids("controller-cluster"):
            relation_set(relation_id=rid, relation_settings=cluster_settings)

        if is_leader():
            _address_changed(local_unit(), ip, 'ip')
            _address_changed(local_unit(), data_ip, 'data_ip')

    if config.changed("local-rabbitmq-hostname-resolution"):
        if config.get("local-rabbitmq-hostname-resolution"):
            # enabling this option will trigger events on other units
            # so their hostnames will be added as -changed events fire
            # we just need to set our hostname
            utils.update_rabbitmq_cluster_hostnames()
        else:
            kvstore = kv()
            rabbitmq_hosts = kvstore.get(key='rabbitmq_hosts', default={})
            for ip, hostname in rabbitmq_hosts:
                utils.update_hosts_file(ip, hostname, remove_hostname=True)

    docker_utils.config_changed()
    utils.update_charm_status()

    # leave it after update_charm_status - in case of exception in previous steps
    # config.changed doesn't work sometimes...
    if config.get("saved-image-tag") != config["image-tag"]:
        utils.update_ziu("image-tag")
        config["saved-image-tag"] = config["image-tag"]
        config.save()

    update_http_relations()
    update_https_relations()
    update_northbound_relations()
    update_southbound_relations()
    update_issu_relations()
コード例 #6
0
def config_changed():
    auth_mode = config.get("auth-mode")
    if auth_mode not in ("rbac", "cloud-admin", "no-auth"):
        raise Exception("Config is invalid. auth-mode must one of: "
                        "rbac, cloud-admin, no-auth.")

    if config.changed("control-network"):
        ip = get_ip()
        settings = {"private-address": ip}
        rnames = ("contrail-controller", "contrail-analytics",
                  "contrail-analyticsdb", "http-services", "https-services")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)
        settings = {"unit-address": ip}
        for rid in relation_ids("controller-cluster"):
            relation_set(relation_id=rid, relation_settings=settings)
        if is_leader():
            _address_changed(local_unit(), ip)

    if config.changed("docker-registry"):
        apply_docker_insecure()
    if config.changed("docker-user") or config.changed("docker-password"):
        docker_login()

    update_charm_status()
    _notify_proxy_services()

    if not is_leader():
        return

    update_northbound_relations()
    update_southbound_relations()
コード例 #7
0
def config_changed():
    docker_utils.config_changed()

    if config.changed("rabbit-user") or config.changed("rabbit-vhost"):
        _notify_amqp()

    utils.pull_images()
    utils.update_charm_status()
コード例 #8
0
def config_changed():
    if config.changed("install-sources") or config.changed("install-keys"):
        configure_sources(True, "install-sources", "install-keys")
        apt_update(fatal=True)
        apt_upgrade(fatal=True, dist=False)

    if is_leader():
        _configure_metadata_shared_secret()
コード例 #9
0
def config_changed():
    # Charm doesn't support changing of some parameters that are used only in
    # install hook.
    for key in ("remove-juju-bridge", "physical-interface"):
        if config.changed(key):
            raise Exception(
                "Configuration parameter {} couldn't be changed".format(key))

    write_configs()
    if config.changed("control-network"):
        reprovision_vrouter()
コード例 #10
0
def config_changed():
    if config.changed("install-sources") or config.changed("install-keys"):
        configure_sources(True, "install-sources", "install-keys")
        apt_update(fatal=True)
        apt_upgrade(fatal=True, dist=False)
        _notify_neutron()

    if is_leader():
        res = _configure_metadata_shared_secret()
        if res:
            _notify_controller()
コード例 #11
0
def config_changed():
    if config.changed("control-network"):
        settings = {'private-address': get_ip()}
        rnames = ("contrail-analyticsdb", "analyticsdb-cluster")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)

    if config.changed("docker-registry"):
        apply_docker_insecure()
    if config.changed("docker-user") or config.changed("docker-password"):
        docker_login()

    update_charm_status()
コード例 #12
0
def config_changed():
    # Charm doesn't support changing of some parameters that are used only in
    # install hook.
    for key in ("remove-juju-bridge", "physical-interface", "dpdk"):
        if config.changed(key):
            raise Exception("Configuration parameter {} couldn't be changed"
                            .format(key))

    if config["dpdk"]:
        if (config.changed("dpdk-main-mempool-size") or config.changed("dpdk-pmd-txd-size")
                or config.changed("dpdk-pmd-rxd-size") or config.changed("dpdk-coremask")):
            set_dpdk_options()
        configure_hugepages()

    write_configs()
コード例 #13
0
def config_changed():
    if config.changed("control-network"):
        settings = {'private-address': get_ip()}
        rnames = ("contrail-analyticsdb", "analyticsdb-cluster")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)

    update_charm_status()
コード例 #14
0
def config_changed_flask_port():
    if config.changed('flask-port') and config["nginx"]:
        hookenv.log("Port change detected")
        hookenv.log("Restarting API")
        remove_state('flask.nginx.installed')
        #remove old port connections
        stop_port_app(config.previous('flask-port'))
        #remove new port connections
        stop_port_app(config['flask-port'])
        #start api again
        restart_api(config['flask-port'])
コード例 #15
0
ファイル: flask.py プロジェクト: IBCNServices/tengu-charms
def config_changed_flask_port():
	if config.changed('flask-port') and config["nginx"]:
		hookenv.log("Port change detected")
		hookenv.log("Restarting API")
		remove_state('flask.nginx.installed')
		#remove old port connections
		stop_port_app(config.previous('flask-port'))
		#remove new port connections
		stop_port_app(config['flask-port'])
		#start api again
		restart_api(config['flask-port'])
コード例 #16
0
def config_changed():
    utils.update_nrpe_config()
    # Charm doesn't support changing of some parameters.
    if config.changed("dpdk"):
        raise Exception("Configuration parameter dpdk couldn't be changed")
    if config.changed("l3mh-cidr"):
        raise Exception(
            "Configuration parameter l3mh-cidr couldn't be changed")

    if not config["dpdk"]:
        utils.prepare_hugepages_kernel_mode()
    docker_utils.config_changed()
    utils.pull_images()
    utils.update_charm_status()

    # leave it as latest - in case of exception in previous steps
    # config.changed doesn't work sometimes...
    if config.get("saved-image-tag") != config["image-tag"]:
        utils.update_ziu("image-tag")
        config["saved-image-tag"] = config["image-tag"]
        config.save()
コード例 #17
0
def check_for_sysctl() -> Result:
    """

    :return:
    """
    if config.changed("sysctl"):
        config_path = os.path.join(os.sep, "etc", "sysctl.d",
                                   "50-gluster-charm.conf")
        sysctl_dict = config("sysctl")
        if sysctl_dict is not None:
            sysctl.create(sysctl_dict, config_path)
    return Ok(())
コード例 #18
0
def config_changed():
    changed = False
    if config.changed("http_proxy") or config.changed(
            "https_proxy") or config.changed("no_proxy"):
        _render_config()
        changed = True
    if config.changed("docker-registry") or config.changed(
            "docker-registry-insecure") or config.changed("docker-opts"):
        _update_docker_settings()
        changed = True
    if config.changed("docker-user") or config.changed("docker-password"):
        _login()
        changed = True
    return changed
コード例 #19
0
def config_changed():
    utils.update_nrpe_config()
    # Charm doesn't support changing of some parameters.
    if config.changed("dpdk"):
        raise Exception("Configuration parameter dpdk couldn't be changed")

    config[
        "config_analytics_ssl_available"] = common_utils.is_config_analytics_ssl_available(
        )
    config.save()

    docker_utils.config_changed()
    utils.update_charm_status()
コード例 #20
0
def config_changed():
    changed = False
    if config.changed("http_proxy") or config.changed("https_proxy") or config.changed("no_proxy"):
        _render_config()
        changed = True
    if config.changed("docker-registry") or config.changed("docker-registry-insecure"):
        _apply_insecure()
        changed = True
    if config.changed("docker-user") or config.changed("docker-password"):
        _login()
        changed = True
    return changed
コード例 #21
0
def config_changed():
    notify_nova = False
    changed = docker_utils.config_changed()
    if changed or config.changed("image-tag"):
        notify_nova = True
        _notify_neutron()
        _notify_heat()

    if is_leader():
        _configure_metadata_shared_secret()
        notify_nova = True
        _notify_controller()

    if notify_nova:
        _notify_nova()
コード例 #22
0
def check_for_upgrade() -> Result:
    """
    If the config has changed this will initiated a rolling upgrade

    :return:
    """
    config = hookenv.config()
    if not config.changed("source"):
        # No upgrade requested
        log("No upgrade requested")
        return Ok(())

    log("Getting current_version")
    current_version = get_glusterfs_version()

    log("Adding new source line")
    source = config("source")
    if not source.is_some():
        # No upgrade requested
        log("Source not set.  Cannot continue with upgrade")
        return Ok(())
    add_source(source)
    log("Calling apt update")
    apt_update()

    log("Getting proposed_version")
    apt_pkg.init_system()
    proposed_version = get_candidate_package_version("glusterfs-server")
    if proposed_version.is_err():
        return Err(proposed_version.value)
    version_compare = apt_pkg.version_compare(a=proposed_version.value,
                                              b=current_version)

    # Using semantic versioning if the new version is greater
    # than we allow the upgrade
    if version_compare > 0:
        log("current_version: {}".format(current_version))
        log("new_version: {}".format(proposed_version.value))
        log("{} to {} is a valid upgrade path.  Proceeding.".format(
            current_version, proposed_version.value))
        return roll_cluster(proposed_version.value)
    else:
        # Log a helpful error message
        log(
            "Invalid upgrade path from {} to {}. The new version needs to be \
                            greater than the old version".format(
                current_version, proposed_version.value), ERROR)
        return Ok(())
コード例 #23
0
def config_changed():
    utils.update_nrpe_config()
    if config.changed("control-network"):
        settings = {'private-address': common_utils.get_ip()}
        rnames = ("contrail-analyticsdb", "analyticsdb-cluster")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)

    config[
        "config_analytics_ssl_available"] = common_utils.is_config_analytics_ssl_available(
        )
    config.save()

    docker_utils.config_changed()
    utils.update_charm_status()
コード例 #24
0
def install():
    if db.get("repo") != config["repo"]:
        status_set("maintenance", "Installing app")
        apt_install(APT_PKGS)
        tmp_dir = install_remote(config["repo"], dest="/tmp", depth=1)
        shutil.rmtree(APP_DIR, ignore_errors=True)
        log("Moving app source from {} to {}".format(tmp_dir, APP_DIR))
        shutil.move(tmp_dir, APP_DIR)
        subprocess.check_call("make .venv".split(), cwd=APP_DIR)
        shutil.copyfile(UPSTART_SRC, UPSTART_DEST)
        chownr(APP_DIR, APP_USER, APP_GROUP)
        db.set("repo", config["repo"])

    if config.changed("port"):
        open_port(config["port"])
        if config.previous("port"):
            close_port(config.previous("port"))
コード例 #25
0
def config_changed():
    utils.update_nrpe_config()
    if config.changed("control-network"):
        _update_cluster()
        if is_leader() and _address_changed(local_unit(),
                                            common_utils.get_ip()):
            _update_analyticsdb()

    docker_utils.config_changed()
    utils.update_charm_status()

    # leave it as latest - in case of exception in previous steps
    # config.changed doesn't work sometimes (when we saved config in this hook before)
    if config.get("saved-image-tag") != config["image-tag"]:
        utils.update_ziu("image-tag")
        config["saved-image-tag"] = config["image-tag"]
        config.save()
コード例 #26
0
def config_changed():
    utils.update_nrpe_config()
    if config.changed("control-network"):
        settings = {'private-address': common_utils.get_ip()}
        rnames = ("contrail-analytics", "contrail-analyticsdb",
                  "analytics-cluster", "http-services")
        for rname in rnames:
            for rid in relation_ids(rname):
                relation_set(relation_id=rid, relation_settings=settings)

    docker_utils.config_changed()
    utils.update_charm_status()

    # leave it as latest - in case of exception in previous steps
    # config.changed doesn't work sometimes...
    if config.get("saved-image-tag") != config["image-tag"]:
        utils.update_ziu("image-tag")
        config["saved-image-tag"] = config["image-tag"]
        config.save()
def set_up():
    if not config.get('fqdn'):
        return
    reverseproxy = endpoint_from_flag('reverseproxy.available')
    services = reverseproxy.services()
    if not data_changed('sslterm.http', services) and \
       not config.changed('credentials'):
        return
    print('New http relation found, configuring proxy.')
    clean_nginx('/etc/nginx/sites-available/http')
    cert = lets_encrypt.live()

    upstreams = []
    for service in services:
        upstreams.extend(service['hosts'])

    create_nginx_config("/etc/nginx/sites-available/http/http-config",
                        [config.get("fqdn")], upstreams, "http-upstream", cert,
                        config.get("credentials", ""), "htaccess_http")
    update_nginx()
    set_flag('ssl-termination-http.setup')
    status_set('active', 'Ready')
コード例 #28
0
def http_set_up():
    if not config.get('fqdn'):
        status.blocked("Found http relation, waiting for fqdn config.")
        return
    reverseproxy = endpoint_from_flag('reverseproxy.available')
    services = reverseproxy.services()
    if not data_changed('sslterm.http', services) and \
       not config.changed('credentials'):
        return
    print('New http relation found, configuring proxy.')
    NginxConfig().delete_all_config(NginxModule.HTTP, 'http')
    cert = lets_encrypt.live()

    # There is only support for 1 http service, block if there are more
    if len(services) > 1:
        status.blocked(
            'More than 1 http relation found,' +
            ' please remove one or use ssl-termination-fqdn subordinates.')

    create_nginx_config(services[0]['service_name'], [config.get("fqdn")],
                        services[0]['hosts'], cert,
                        config.get("credentials", ""), 'htaccess_http', 'http')
    set_flag('ssl-termination.http-setup')
    set_flag('ssl-termination.report')
コード例 #29
0
def config_changed():
    if config.changed("nested_mode"):
        raise Exception('Nested mode cannot be changed after deployment.')
    # TODO: analyze other params and raise exception if readonly params were changed

    utils.update_nrpe_config()
    if config.changed("control-network"):
        _notify_cluster()
        if is_leader():
            _address_changed(local_unit(), common_utils.get_ip())

    _notify_contrail_kubernetes_node()
    if (config.changed("kubernetes_api_hostname")
            or config.changed("kubernetes_api_secure_port")
            or config.changed("cluster_name")
            or config.changed("pod_subnets")):
        _notify_controller()

    docker_utils.config_changed()
    utils.update_charm_status()
コード例 #30
0
def config_changed():
    if config.changed("install-sources") or config.changed("install-keys"):
        configure_sources(True, "install-sources", "install-keys")
        apt_update(fatal=True)
        apt_upgrade(fatal=True, dist=False)
コード例 #31
0
def config_changed():
    if config.changed('s3-url'):
        _notify_neutron()
コード例 #32
0
ファイル: flask.py プロジェクト: tengu-team/layer-flask
def config_changed_flask_port():
    if config.changed('flask-port') and config["nginx"]:
        hookenv.log("Port change detected")
        hookenv.log("Restarting API")
        remove_state('flask.nginx.installed')
        restart_api(config['flask-port'])
コード例 #33
0
ファイル: flask.py プロジェクト: tengu-team/layer-flask
def config_changed_workers():
    if config.changed('workers') and config["nginx"]:
        hookenv.log('Workers change detected')
        hookenv.log("Restarting API")
        set_workers()