示例#1
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()
示例#2
0
def pull_images():
    tag = config.get('image-tag')
    for image in IMAGES + (IMAGES_DPDK if config["dpdk"] else IMAGES_KERNEL):
        try:
            common_utils.container_engine().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:
            common_utils.container_engine().pull(image, tag)
        except Exception as e:
            log("Can't load optional image {}".format(e))
示例#3
0
def stop_agent(stop_agent=True):
    path = CONFIGS_PATH + "/docker-compose.yaml"
    services_to_wait = None
    if stop_agent:
        services_to_wait = ["vrouter-agent"]
    common_utils.container_engine().compose_down(path, services_to_wait=services_to_wait)
    # remove all built vrouter.ko
    modules = '/lib/modules'
    for item in os.listdir(modules):
        path = os.path.join(modules, item, 'updates/dkms/vrouter.ko')
        try:
            os.remove(path)
        except Exception:
            pass
示例#4
0
def install():
    status_set('maintenance', 'Installing...')

    # TODO: try to remove this call
    common_utils.fix_hostname()

    if not config["dpdk"]:
        utils.prepare_hugepages_kernel_mode()
        if utils.is_reboot_required():
            utils.reboot()

    common_utils.container_engine().install()
    if config["dpdk"]:
        utils.fix_libvirt()
    utils.update_charm_status()
示例#5
0
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)
    common_utils.container_engine().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)
示例#6
0
def compile_kernel_modules():
    modules = '/lib/modules'
    need_to_compile = False
    for item in os.listdir(modules):
        # vrouter doesn't support kernels version 5, remove check after fix
        if item.split('.')[0] == '5':
            continue
        path = os.path.join(modules, item, 'updates/dkms/vrouter.ko')
        if not os.path.exists(path):
            need_to_compile = True
            break
    contrail_version = common_utils.get_contrail_version()
    if not need_to_compile or contrail_version < 2008:
        return

    path = CONFIGS_PATH + "/docker-compose.yaml"
    state = common_utils.container_engine().get_container_state(path, "vrouter-kernel-init")
    if state and state.get('Status', '').lower() != 'running':
        common_utils.container_engine().restart_container(path, "vrouter-kernel-init")
示例#7
0
def get_context():
    ctx = {}
    ctx["module"] = MODULE
    ctx["ssl_enabled"] = config.get("ssl_enabled", False)
    ctx["certs_hash"] = common_utils.get_certs_hash(MODULE) if ctx["ssl_enabled"] else ''
    ctx["l3mh_cidr"] = config.get("l3mh-cidr", None)
    ctx["log_level"] = config.get("log-level", "SYS_NOTICE")
    ctx["container_registry"] = config.get("docker-registry")
    ctx["contrail_version_tag"] = config.get("image-tag")
    ctx["sriov_physical_interface"] = config.get("sriov-physical-interface")
    ctx["sriov_numvfs"] = config.get("sriov-numvfs")
    ctx["max_vm_flows"] = config.get("max-vm-flows")
    ctx["xflow_node_ip"] = config.get("xflow-node-ip")
    ctx["vrouter_module_options"] = config.get("vrouter-module-options")
    ctx["contrail_version"] = common_utils.get_contrail_version()
    ctx["container_runtime"] = config.get("container_runtime")

    # NOTE: charm should set non-fqdn hostname to be compatible with R5.0 deployments
    ctx["hostname"] = socket.getfqdn() if config.get("hostname-use-fqdn", True) else socket.gethostname()
    iface = config.get("physical-interface")
    ctx["physical_interface"] = iface
    gateway_ip = config.get("vhost-gateway")
    if gateway_ip == "auto":
        gateway_ip = _get_iface_gateway_ip(iface)
    ctx["vrouter_gateway"] = gateway_ip if gateway_ip else ''

    ctx["agent_mode"] = "dpdk" if config["dpdk"] else "kernel"
    if config["dpdk"]:
        ctx["dpdk_additional_args"] = _get_dpdk_args()
        ctx["dpdk_driver"] = config.get("dpdk-driver")
        ctx["dpdk_coremask"] = config.get("dpdk-coremask")
        ctx["dpdk_service_coremask"] = config.get("dpdk-service-coremask")
        ctx["dpdk_ctrl_thread_coremask"] = config.get("dpdk-ctrl-thread-coremask")
        cpuset = _convert2cpuset(config.get("dpdk-ctrl-thread-coremask"))
        if cpuset:
            ctx["agent_containers_cpuset"] = cpuset
        ctx["dpdk_hugepages"] = _get_hugepages()
    else:
        ctx["hugepages_1g"] = config.get("kernel-hugepages-1g")
        ctx["hugepages_2m"] = config.get("kernel-hugepages-2m")

    ctx.update(tsn_ctx())

    info = common_utils.json_loads(config.get("orchestrator_info"), dict())
    ctx.update(info)
    if not ctx.get("cloud_orchestrators"):
        ctx["cloud_orchestrators"] = [ctx.get("cloud_orchestrator")] if ctx.get("cloud_orchestrator") else list()

    ctx["controller_servers"] = common_utils.json_loads(config.get("controller_ips"), list())
    ctx["control_servers"] = common_utils.json_loads(config.get("controller_data_ips"), list())
    ctx["analytics_servers"] = common_utils.json_loads(config.get("analytics_servers"), list())
    ctx["config_analytics_ssl_available"] = common_utils.is_config_analytics_ssl_available()
    if "plugin-ips" in config:
        plugin_ips = common_utils.json_loads(config["plugin-ips"], dict())
        my_ip = unit_get("private-address")
        if my_ip in plugin_ips:
            ctx["plugin_settings"] = plugin_ips[my_ip]

    ctx["pod_subnets"] = config.get("pod_subnets")

    if config.get('maintenance') == 'issu':
        ctx["controller_servers"] = common_utils.json_loads(config.get("issu_controller_ips"), list())
        ctx["control_servers"] = common_utils.json_loads(config.get("issu_controller_data_ips"), list())
        ctx["analytics_servers"] = common_utils.json_loads(config.get("issu_analytics_ips"), list())
        # orchestrator_info and auth_info can be taken from old relation

    ctx["logging"] = common_utils.container_engine().render_logging()
    log("CTX: " + str(ctx))

    ctx.update(common_utils.json_loads(config.get("auth_info"), dict()))
    return ctx