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 update_charm_status(): tag = config.get('image-tag') for image in IMAGES + (IMAGES_DPDK if config["dpdk"] else IMAGES_KERNEL): 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"): log("Maintenance is in progress") common_utils.update_services_status(MODULE, SERVICES) return fix_dns_settings() ctx = get_context() _update_charm_status(ctx)
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"): log("ISSU Maintenance is in progress") status_set('maintenance', 'issu is in progress') return if int(config.get("ziu", -1)) > -1: log("ZIU Maintenance is in progress") status_set( 'maintenance', 'ziu is in progress - stage/done = {}/{}'.format( config.get("ziu"), config.get("ziu_done"))) return ctx = get_context() _update_charm_status(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 pull_images(): 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), level=ERROR) raise Exception('Image could not be pulled: {}:{}'.format( image, tag))
def update_services_status(module, services): try: output = check_output( "export CONTRAIL_STATUS_CONTAINER_NAME=contrail-status-{} ; contrail-status" .format(module), shell=True).decode('UTF-8') except Exception as e: log("Container is not ready to get contrail-status: " + str(e)) status_set("waiting", "Waiting services to run in container") return False statuses = dict() group = None for line in output.splitlines()[1:]: words = line.split() if len(words) == 4 and words[0] == "==" and words[3] == "==": group = words[2] continue if len(words) == 0: group = None continue if group and len(words) >= 2 and group in services: srv = words[0].split(":")[0] statuses.setdefault(group, dict())[srv] = (words[1], " ".join(words[2:])) for group in services: if group not in statuses: status_set("waiting", "POD " + group + " is absent in the contrail-status") return False for srv in services[group]: if srv not in statuses[group]: status_set("waiting", srv + " is absent in the contrail-status") return False status, desc = statuses[group].get(srv) if status not in ["active", "backup"]: workload = "waiting" if status == "initializing" else "blocked" status_set( workload, "{} is not ready. Reason: {}".format( srv, desc if desc else status)) return False status_set("active", "Unit is ready") try: tag = config.get('image-tag') docker_utils.pull("contrail-base", tag) version = docker_utils.get_contrail_version("contrail-base", tag) application_version_set(version) except CalledProcessError as e: log("Couldn't detect installed application version: " + str(e)) return True
def pull_images(): tag = config.get('image-tag') for image in IMAGES + (IMAGES_DPDK if config["dpdk"] else IMAGES_KERNEL): try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e), level=ERROR) raise Exception('Image could not be pulled: {}:{}'.format( image, tag)) for image in IMAGES_OPTIONAL: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load optional image {}".format(e))
def _pull_images(): tag = config.get('image-tag') for image in IMAGES + (IMAGES_DPDK if config["dpdk"] else IMAGES_KERNEL): 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))
def pull_images(): tag = config.get('image-tag') ctx = get_context() images = IMAGES.get(ctx["contrail_version"], IMAGES.get(9999)) for image in images: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e), level=ERROR) raise Exception('Image could not be pulled: {}:{}'.format(image, tag)) for image in IMAGES_OPTIONAL: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load optional image {}".format(e))
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_services_status(module, services): contrail_version = get_contrail_version() if contrail_version > 1912: statuses = get_contrail_status_json(module, services) else: statuses = get_contrail_status_txt(module, services) if not statuses: return False for group in services: if group not in statuses: status_set("waiting", "POD " + group + " is absent in the contrail-status") return False # expected services for srv in services[group]: # actual statuses # actual service name can be present as a several workers like 'api-0', 'api-1', ... stats = [ statuses[group][x] for x in statuses[group] if x == srv or x.startswith(srv + '-') ] if not stats: status_set("waiting", srv + " is absent in the contrail-status") return False for status in stats: if status not in ["active", "backup"]: workload = "waiting" if status == "initializing" else "blocked" status_set( workload, "{} is not ready. Reason: {}".format(srv, status)) return False status_set("active", "Unit is ready") try: tag = config.get('image-tag') docker_utils.pull("contrail-node-init", tag) version = docker_utils.get_contrail_version("contrail-node-init", tag) application_version_set(version) except CalledProcessError as e: log("Couldn't detect installed application version: " + str(e)) return True
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 deploy_openstack_code(image, component, env_dict=None): tag = config.get('image-tag') docker_utils.pull(image, tag) # remove previous attempt docker_utils.remove_container_by_image(image) path = get_component_sys_paths(component) files = PLUGIN_FILES[component] name = docker_utils.create(image, tag) try: for item in files: dst = item.format(python_path=path) try: src = files[item] if isinstance(src, tuple): src = src[0] tmp_folder = os.path.join('/tmp', str(uuid.uuid4())) # docker copies content of src folder if dst folder is not present # and directory itself if dst is present # therefore we copy content from container into tmp and then content of tmp into dst docker_utils.cp(name, src, tmp_folder) copy_tree(tmp_folder, dst) shutil.rmtree(tmp_folder, ignore_errors=True) except Exception: if not isinstance(files[item], tuple): raise for folder in files[item][1]: try: docker_utils.cp(name, folder, dst) except Exception: pass finally: docker_utils.remove_container_by_image(image) try: version = docker_utils.get_contrail_version(image, tag) application_version_set(version) except CalledProcessError as e: log("Couldn't detect installed application version: " + str(e))
def pull_images(): ctx = get_context() tag = config.get('image-tag') images = IMAGES.get(ctx["contrail_version"], IMAGES.get(9999)).copy() if not ctx.get("analyticsdb_enabled"): images.pop("analytics-alarm") images.pop("analytics-snmp") for image_group in images.keys(): for image in images.get(image_group): try: docker_utils.pull(image, tag) except Exception as e: log("Can't load image {}".format(e), level=ERROR) raise Exception('Image could not be pulled: {}:{}'.format( image, tag)) for image in IMAGES_OPTIONAL: try: docker_utils.pull(image, tag) except Exception as e: log("Can't load optional image {}".format(e))
def update_services_status(module, services): tag = config.get('image-tag') contrail_version = get_contrail_version() if contrail_version > 1912: statuses = get_contrail_status_json(module, services) else: statuses = get_contrail_status_txt(module, services) if not statuses: return False for group in services: if group not in statuses: status_set("waiting", "POD " + group + " is absent in the contrail-status") return False for srv in services[group]: if not any(srv in key for key in statuses[group]): status_set("waiting", srv + " is absent in the contrail-status") return False status = next(stat[srv] for stat in statuses[group] if srv in stat) if status not in ["active", "backup"]: workload = "waiting" if status == "initializing" else "blocked" status_set(workload, "{} is not ready. Reason: {}".format(srv, status)) return False status_set("active", "Unit is ready") try: tag = config.get('image-tag') docker_utils.pull("contrail-node-init", tag) version = docker_utils.get_contrail_version("contrail-node-init", tag) application_version_set(version) except CalledProcessError as e: log("Couldn't detect installed application version: " + str(e)) return True
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(): ctx = get_context() tag = config.get('image-tag') images = IMAGES.get(ctx["contrail_version"], IMAGES.get(9999)).copy() if not ctx.get("analyticsdb_enabled"): images.pop("analytics-alarm") images.pop("analytics-snmp") for image_group in images.keys(): for image in images.get(image_group): 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"): log("ISSU Maintenance is in progress") status_set('maintenance', 'issu is in progress') return if int(config.get("ziu", -1)) > -1: log("ZIU Maintenance is in progress") status_set( 'maintenance', 'ziu is in progress - stage/done = {}/{}'.format( config.get("ziu"), config.get("ziu_done"))) return _update_charm_status(ctx)
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)