def _update_charm_status(ctx): 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 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 len(ctx.get("analyticsdb_servers")) < config.get("min-cluster-size"): status_set('blocked', 'Count of cluster nodes is not enough ({} < {}).'.format( len(ctx.get("analyticsdb_servers")), config.get("min-cluster-size") )) 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 # TODO: what should happens if relation departed? changed_dict = _render_configs(ctx) changed = changed_dict["common"] or changed_dict["analytics-database"] docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml", changed) common_utils.update_services_status(MODULE, SERVICES.get(ctx["contrail_version"], SERVICES.get(9999)))
def _update_charm_status(ctx, services_to_run=None): # services to run: config-api, control, config-database, webui, redis 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 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 len(ctx.get("controller_servers")) < config.get("min-cluster-size"): status_set( 'blocked', 'Count of cluster nodes is not enough ({} < {}).'.format( len(ctx.get("controller_servers")), config.get("min-cluster-size"))) return if not ctx.get("cloud_orchestrator"): status_set('blocked', 'Missing cloud orchestrator info in relations.') return if "openstack" in ctx.get( "cloud_orchestrators") 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_dict = _render_configs(ctx) changed = changed_dict["common"] service_changed = changed_dict["config-api"] docker_utils.compose_run(CONFIG_API_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = changed_dict["config-database"] docker_utils.compose_run( CONFIG_DATABASE_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = changed_dict["control"] docker_utils.compose_run(CONTROL_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = changed_dict["webui"] 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 = changed_dict["redis"] docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) common_utils.update_services_status(MODULE, SERVICES) if _has_provisioning_finished(): config['apply-defaults'] = False
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 ziu_restart_db(stage): ctx = get_context() _render_configs(ctx) docker_utils.compose_run(CONFIGS_PATH + "/docker-compose.yaml") result = common_utils.update_services_status(MODULE, SERVICES.get(ctx["contrail_version"], SERVICES.get(9999))) if result: signal_ziu("ziu_done", stage)
def ziu_restart_control(stage): ctx = get_context() _render_configs(ctx) docker_utils.compose_run(CONTROL_CONFIGS_PATH + "/docker-compose.yaml") result = common_utils.update_services_status(MODULE, SERVICES) if result: signal_ziu("ziu_done", stage)
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 _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(ctx): missing_relations = [] if not ctx.get("controller_servers"): missing_relations.append("contrail-controller") if ctx.get("analyticsdb_enabled") and not ctx.get("analyticsdb_servers"): missing_relations.append("contrail-analyticsdb") if missing_relations: status_set('blocked', 'Missing relations: ' + ', '.join(missing_relations)) return if len(ctx.get("analytics_servers")) < config.get("min-cluster-size"): status_set( 'blocked', 'Count of cluster nodes is not enough ({} < {}).'.format( len(ctx.get("analytics_servers")), config.get("min-cluster-size"))) 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 # TODO: what should happens if relation departed? changed_dict = _render_configs(ctx) changed = changed_dict["common"] service_changed = changed_dict["analytics"] docker_utils.compose_run(ANALYTICS_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) if ctx["contrail_version"] >= 510 and ctx.get("analyticsdb_enabled"): service_changed = changed_dict["analytics-alarm"] docker_utils.compose_run( ANALYTICS_ALARM_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) service_changed = changed_dict["analytics-snmp"] docker_utils.compose_run( ANALYTICS_SNMP_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) # redis is a common service that needs own synchronized env service_changed = changed_dict["redis"] docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml", changed or service_changed) services = SERVICES.get(ctx["contrail_version"], SERVICES.get(9999)).copy() if not ctx.get("analyticsdb_enabled"): services.pop("analytics-alarm") services.pop("analytics-snmp") common_utils.update_services_status(MODULE, services)
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 ziu_stage_2(ziu_stage, trigger): # start API services ctx = get_context() _render_configs(ctx) docker_utils.compose_run(ANALYTICS_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml") if ctx["contrail_version"] >= 510: docker_utils.compose_run(ANALYTICS_ALARM_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(ANALYTICS_SNMP_CONFIGS_PATH + "/docker-compose.yaml") result = common_utils.update_services_status( MODULE, SERVICES.get(ctx["contrail_version"], SERVICES.get(9999))) if result: signal_ziu("ziu_done", ziu_stage)
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 ziu_stage_2(ziu_stage, trigger): # start API services ctx = get_context() _render_configs(ctx) docker_utils.compose_run(CONFIG_API_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(WEBUI_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml") result = common_utils.update_services_status(MODULE, SERVICES) if result: signal_ziu("ziu_done", ziu_stage)
def ziu_stage_2(ziu_stage, trigger): # start API services ctx = get_context() _render_configs(ctx) docker_utils.compose_run(ANALYTICS_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(REDIS_CONFIGS_PATH + "/docker-compose.yaml") if ctx["contrail_version"] >= 510 and ctx.get("analyticsdb_enabled"): docker_utils.compose_run(ANALYTICS_ALARM_CONFIGS_PATH + "/docker-compose.yaml") docker_utils.compose_run(ANALYTICS_SNMP_CONFIGS_PATH + "/docker-compose.yaml") services = SERVICES.get(ctx["contrail_version"], SERVICES.get(9999)).copy() if not ctx.get("analyticsdb_enabled"): services.pop("analytics-alarm") services.pop("analytics-snmp") result = common_utils.update_services_status(MODULE, services) if result: signal_ziu("ziu_done", ziu_stage)
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)