def update_issu_state(issu_relation_data): ctx = {'old': issu_relation_data} ctx["new"] = get_cassandra_connection_details() ctx["new"].update(get_rabbitmq_connection_details()) ctx["new"].update(get_zookeeper_connection_details()) common_utils.render_and_log("contrail-issu.conf", BASE_CONFIGS_PATH + "/contrail-issu.conf", ctx)
def update_charm_status(): tag = config.get('image-tag') cver = '5.1' if '5.0' in tag: cver = '5.0' for image in IMAGES[cver]: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return for image in IMAGES_OPTIONAL: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load optional image {}".format(e)) if config.get("maintenance"): return ctx = get_context() missing_relations = [] if not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if not ctx.get("analytics_servers"): missing_relations.append("contrail-analytics") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if not ctx.get("cloud_orchestrator"): status_set( 'blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if ctx.get("cloud_orchestrator" ) == "openstack" and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return # TODO: what should happens if relation departed? changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log( cver + "/analytics-database.env", BASE_CONFIGS_PATH + "/common_analyticsdb.env", ctx) if ctx["contrail_version"] >= 2002: changed |= common_utils.render_and_log( cver + "/defaults.env", BASE_CONFIGS_PATH + "/defaults_analyticsdb.env", ctx) changed |= common_utils.render_and_log( cver + "/analytics-database.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) common_utils.update_services_status(MODULE, SERVICES[cver])
def update_charm_status(): ctx = get_context() changed = common_utils.render_and_log( "cni.env", BASE_CONFIGS_PATH + "/common_cni.env", ctx) changed |= common_utils.render_and_log( "/contrail-cni.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) status_set("active", "Unit is ready")
def _render_configs(ctx): result = dict() result['common'] = common_utils.apply_keystone_ca(MODULE, ctx) result['common'] |= common_utils.render_and_log( "config.env", BASE_CONFIGS_PATH + "/common_config.env", ctx) if ctx["contrail_version"] >= 2002: result['common'] |= common_utils.render_and_log( "defaults.env", BASE_CONFIGS_PATH + "/defaults_controller.env", ctx) result['config-api'] = common_utils.render_and_log( "config-api.yaml", CONFIG_API_CONFIGS_PATH + "/docker-compose.yaml", ctx) result['config-database'] = common_utils.render_and_log( "config-database.yaml", CONFIG_DATABASE_CONFIGS_PATH + "/docker-compose.yaml", ctx) result['control'] = common_utils.render_and_log( "control.yaml", CONTROL_CONFIGS_PATH + "/docker-compose.yaml", ctx) result['webui'] = common_utils.render_and_log( "webui.yaml", WEBUI_CONFIGS_PATH + "/docker-compose.yaml", ctx) result['webui'] |= common_utils.render_and_log( "web.env", BASE_CONFIGS_PATH + "/common_web.env", ctx) # redis is a common service that needs own synchronized env result['redis'] = common_utils.render_and_log( "redis.env", BASE_CONFIGS_PATH + "/redis.env", ctx) result['redis'] |= common_utils.render_and_log( "redis.yaml", REDIS_CONFIGS_PATH + "/docker-compose.yaml", ctx) return result
def _render_configs(ctx): result = dict() tfolder = '5.0' if ctx["contrail_version"] == 500 else '5.1' result["common"] = common_utils.apply_keystone_ca(MODULE, ctx) result["common"] |= common_utils.render_and_log( tfolder + "/analytics-database.env", BASE_CONFIGS_PATH + "/common_analyticsdb.env", ctx) result["analytics-database"] = common_utils.render_and_log( tfolder + "/analytics-database.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) return result
def _update_charm_status(ctx): missing_relations = [] if not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if config.get("wait-for-external-plugin", False) and "plugin_settings" not in ctx: missing_relations.append("vrouter-plugin") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if not ctx.get("analytics_servers"): status_set('blocked', 'Missing analytics_servers info in relation ' 'with contrail-controller.') return if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if ctx.get("cloud_orchestrator") == "openstack" and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return if ctx.get("cloud_orchestrator") == "kubernetes" and not ctx.get("kube_manager_token"): status_set('blocked', 'Kube manager token undefined.') return if ctx.get("cloud_orchestrator") == "kubernetes" and not ctx.get("kubernetes_api_server"): status_set('blocked', 'Kubernetes API unavailable') return # TODO: what should happens if relation departed? changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log("vrouter.env", BASE_CONFIGS_PATH + "/common_vrouter.env", ctx) if ctx["contrail_version"] >= 2002: changed |= common_utils.render_and_log("defaults.env", BASE_CONFIGS_PATH + "/defaults_vrouter.env", ctx) changed |= common_utils.render_and_log("vrouter.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) # local file for vif utility common_utils.render_and_log("contrail-vrouter-agent.conf", "/etc/contrail/contrail-vrouter-agent.conf", ctx, perms=0o440) common_utils.update_services_status(MODULE, SERVICES)
def update_charm_status(): tag = config.get('image-tag') for image in IMAGES: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return if config.get("maintenance") or config.get("ziu"): return ctx = get_context() missing_relations = [] if not ctx.get("nested_mode") and not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if not ctx.get("kubernetes_api_server"): missing_relations.append("kube-api-endpoint") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if not ctx.get("cloud_orchestrator"): status_set( 'blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if not ctx.get("kube_manager_token"): status_set( 'waiting', 'Kube manager token is absent. Wait for token from kubectl run.') return if "openstack" in ctx.get( "cloud_orchestrators") and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return changed = common_utils.render_and_log( "kubemanager.env", BASE_CONFIGS_PATH + "/common_kubemanager.env", ctx) changed |= common_utils.render_and_log( "/contrail-kubemanager.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) common_utils.update_services_status(MODULE, SERVICES)
def update_charm_status(): tag = config.get('image-tag') ctx = get_context() for image in IMAGES: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return deployer_image = "contrail-command-deployer" deploy_ccd_code(deployer_image, tag) if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud orchestrator info in relations.') return elif ctx.get("cloud_orchestrator") != "openstack": status_set('blocked', 'Contrail command works with openstack only now') return changed = common_utils.render_and_log('cluster_config.yml.j2', '/cluster_config.yml', ctx) if changed or not config.get("command_deployed"): dst = '/' + deployer_image + '/docker/deploy_contrail_command' check_call('./files/deploy_contrail_command.sh ' + dst, shell=True) config["command_deployed"] = True update_status()
def _run_services(ctx): # local file for vif utility common_utils.render_and_log( "contrail-vrouter-agent.conf", BASE_CONFIGS_PATH + "/contrail-vrouter-agent.conf", ctx, perms=0o440) changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log( "vrouter.env", BASE_CONFIGS_PATH + "/common_vrouter.env", ctx) changed |= common_utils.render_and_log("vrouter.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) if is_reboot_required(): status_set('blocked', 'Reboot is required due to hugepages allocation.') return common_utils.update_services_status(MODULE, SERVICES)
def update_charm_status(): tag = config.get('image-tag') for image in IMAGES: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return ctx = get_context() changed = common_utils.render_and_log( "cni.env", BASE_CONFIGS_PATH + "/common_cni.env", ctx) changed |= common_utils.render_and_log( "/contrail-cni.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) status_set("active", "Unit is ready")
def update_charm_status(): if config.get("maintenance") or config.get("ziu"): return ctx = get_context() missing_relations = [] if not ctx.get("nested_mode") and not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if not ctx.get("kubernetes_api_server"): missing_relations.append("kube-api-endpoint") if config.get('tls_present', False) != config.get('ssl_enabled', False): missing_relations.append("tls-certificates") if missing_relations: status_set( 'blocked', 'Missing or incomplete relations: ' + ', '.join(missing_relations)) return if not ctx.get("cloud_orchestrator"): status_set( 'blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if not ctx.get("kube_manager_token"): status_set( 'waiting', 'Kube manager token is absent. Wait for token from kubectl run.') return if "openstack" in ctx.get( "cloud_orchestrators") and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return changed = common_utils.render_and_log( "kubemanager.env", BASE_CONFIGS_PATH + "/common_kubemanager.env", ctx) changed |= common_utils.render_and_log( "/contrail-kubemanager.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) common_utils.update_services_status(MODULE, SERVICES)
def import_cluster(juju_params): if not update_status(): return False, 'Unit is not ready, try later' ctx = get_context() juju_params["juju_cluster_type"] = ctx.get("cloud_orchestrator") common_utils.render_and_log('juju_environment', '/tmp/juju_environment', juju_params) deployer_image = "contrail-command-deployer" dst = '/' + deployer_image + '/docker/deploy_contrail_command' try: check_call( '. /tmp/juju_environment ; ./files/deploy_contrail_command.sh ' + dst, shell=True) status_set('active', 'Cluster is imported') except Exception as e: return False, 'Import failed ({}). Please check logs'.format(e) return True, "Success"
def _render_configs(ctx): result = dict() tfolder = '5.0' if ctx["contrail_version"] == 500 else '5.1' result["common"] = common_utils.apply_keystone_ca(MODULE, ctx) result["common"] |= common_utils.render_and_log( tfolder + "/analytics.env", BASE_CONFIGS_PATH + "/common_analytics.env", ctx) result["analytics"] = common_utils.render_and_log( tfolder + "/analytics.yaml", ANALYTICS_CONFIGS_PATH + "/docker-compose.yaml", ctx) if ctx["contrail_version"] >= 510 and ctx.get("analyticsdb_enabled"): result["analytics-alarm"] = common_utils.render_and_log( tfolder + "/analytics-alarm.yaml", ANALYTICS_ALARM_CONFIGS_PATH + "/docker-compose.yaml", ctx) result["analytics-snmp"] = common_utils.render_and_log( tfolder + "/analytics-snmp.yaml", ANALYTICS_SNMP_CONFIGS_PATH + "/docker-compose.yaml", ctx) # TODO: think about removing analytics-alarm.yaml and analytics-snmp.yaml # redis is a common service that needs own synchronized env result["redis"] = common_utils.render_and_log( "redis.env", BASE_CONFIGS_PATH + "/redis.env", ctx) result["redis"] |= common_utils.render_and_log( "redis.yaml", REDIS_CONFIGS_PATH + "/docker-compose.yaml", ctx) return result
def update_charm_status(import_cluster=False): tag = config.get('image-tag') ctx = get_context() for image in IMAGES: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return deployer_image = "contrail-command-deployer" changed = common_utils.render_and_log("min_config.yaml", '/cluster_config.yml', ctx) env = common_utils.render_and_log("juju_environment", '/tmp/juju_environment', ctx) if changed or env or import_cluster: deploy_ccd_code(deployer_image, tag) if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud orchestrator info in relations.') import_cluster = False elif ctx.get("cloud_orchestrator") != "openstack": status_set('blocked', 'Contrail command works with openstack only now') import_cluster = False else: import_cluster = True run_contrail_command(deployer_image, import_cluster) # do not update status if no relation to contrail-controller if not import_cluster: return update_status()
def update_charm_status(): if config.get("maintenance") or config.get("ziu"): return ctx = get_context() missing_relations = [] if not ctx.get('rabbitmq_hostname'): missing_relations.append("rabbitmq-server:amqp") if config.get('tls_present', False) != config.get('ssl_enabled', False): missing_relations.append("tls-certificates") if missing_relations: status_set( 'blocked', 'Missing or incomplete relations: ' + ', '.join(missing_relations)) return if not ctx.get("cloud_orchestrator"): status_set( 'blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if "openstack" in ctx.get( "cloud_orchestrators") and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log( "openstack-ironic.env", BASE_CONFIGS_PATH + "/common_openstack_ironic.env", ctx) changed |= common_utils.render_and_log( "/contrail-openstack-ironic.yaml", CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) common_utils.update_services_status(MODULE, SERVICES)
def import_cluster(juju_params): if not update_status(): return False, 'Unit is not ready, try later' env = common_utils.render_and_log('juju_environment', '/tmp/juju_environment', juju_params) deployer_image = "contrail-command-deployer" dst = '/' + deployer_image + '/docker/deploy_contrail_command' try: check_call( '. /tmp/juju_environment ; ./files/deploy_contrail_command.sh ' + dst, shell=True) status_set('active', 'Cluster is imported') except Exception as e: return False, 'Import failed, check logs' return True, "Success"
def update_charm_status(): tag = config.get('image-tag') ctx = get_context() deployer_image = "contrail-command-deployer" deploy_ccd_code(deployer_image, tag) if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud orchestrator info in relations.') return changed = common_utils.render_and_log('cluster_config.yml.j2', '/cluster_config.yml', ctx) if changed or not config.get("command_deployed"): dst = '/' + deployer_image + '/docker/deploy_contrail_command' check_call('./files/deploy_contrail_command.sh ' + dst, shell=True) config["command_deployed"] = True update_status() version = docker_utils.get_contrail_version("contrail-command", tag) application_version_set(version)
def update_charm_status(): tag = config.get('image-tag') for image in IMAGES: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e)) status_set('blocked', 'Image could not be pulled: {}:{}'.format(image, tag)) return for image in IMAGES_OPTIONAL: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load optional image {}".format(e)) if config.get("maintenance"): return ctx = get_context() missing_relations = [] if not ctx.get("analytics_servers"): missing_relations.append("contrail-analytics") if common_utils.get_ip() not in ctx.get("controller_servers"): missing_relations.append("contrail-cluster") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud orchestrator info in relations.') return if ctx.get("cloud_orchestrator" ) == "openstack" and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-auth.') return # TODO: what should happens if relation departed? changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log( "config.env", BASE_CONFIGS_PATH + "/common_config.env", ctx) if ctx["contrail_version"] >= 2002: changed |= common_utils.render_and_log( "defaults.env", BASE_CONFIGS_PATH + "/defaults_controller.env", ctx) service_changed = common_utils.render_and_log( "config-api.yaml", CONFIG_API_CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONFIG_API_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = common_utils.render_and_log( "config-database.yaml", CONFIG_DATABASE_CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run( CONFIG_DATABASE_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = common_utils.render_and_log( "control.yaml", CONTROL_CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(CONTROL_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = common_utils.render_and_log( "webui.yaml", WEBUI_CONFIGS_PATH + "/docker-compose.yaml", ctx) service_changed |= common_utils.render_and_log( "web.env", BASE_CONFIGS_PATH + "/common_web.env", ctx) docker_utils.compose_run(WEBUI_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) # redis is a common service that needs own synchronized env service_changed = common_utils.render_and_log( "redis.env", BASE_CONFIGS_PATH + "/redis.env", ctx) service_changed |= common_utils.render_and_log( "redis.yaml", REDIS_CONFIGS_PATH + "/docker-compose.yaml", ctx) docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) common_utils.update_services_status(MODULE, SERVICES)
def _update_charm_status(ctx): missing_relations = [] if not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if config.get("wait-for-external-plugin", False) and "plugin_settings" not in ctx: missing_relations.append("vrouter-plugin") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if not ctx.get("analytics_servers"): status_set( 'blocked', 'Missing analytics_servers info in relation ' 'with contrail-controller.') return if not ctx.get("cloud_orchestrator"): status_set( 'blocked', 'Missing cloud_orchestrator info in relation ' 'with contrail-controller.') return if ctx.get("cloud_orchestrator" ) == "openstack" and not ctx.get("keystone_ip"): status_set('blocked', 'Missing auth info in relation with contrail-controller.') return if ctx.get("cloud_orchestrator" ) == "kubernetes" and not ctx.get("kube_manager_token"): status_set('blocked', 'Kube manager token undefined.') return if ctx.get("cloud_orchestrator" ) == "kubernetes" and not ctx.get("kubernetes_api_server"): status_set('blocked', 'Kubernetes API unavailable') return # TODO: what should happens if relation departed? # local file for vif utility common_utils.render_and_log("contrail-vrouter-agent.conf", "/etc/contrail/contrail-vrouter-agent.conf", ctx, perms=0o440) changed = common_utils.apply_keystone_ca(MODULE, ctx) changed |= common_utils.render_and_log( "vrouter.env", BASE_CONFIGS_PATH + "/common_vrouter.env", ctx) changed |= common_utils.render_and_log("vrouter.yaml", VROUTER_COMPOSE_PATH, ctx) changed |= common_utils.render_and_log("vrouter-init.yaml", VROUTER_INIT_COMPOSE_PATH, ctx) if is_vrouter_init_successfully_passed(): docker_utils.compose_run(VROUTER_COMPOSE_PATH, changed) else: # let's down this compose. it will not fail but this will guarantee next run docker_utils.compose_down(VROUTER_INIT_COMPOSE_PATH) docker_utils.compose_run(VROUTER_INIT_COMPOSE_PATH, True) if is_reboot_required(): status_set('blocked', 'Reboot is required due to hugepages allocation.') return common_utils.update_services_status(MODULE, SERVICES)