コード例 #1
0
def update_charm_status(update_config=True):
    update_config_func = render_config if update_config else None
    result = check_run_prerequisites(CONTAINER_NAME, CONFIG_NAME,
                                     update_config_func, SERVICES_TO_CHECK)
    if not result:
        return

    ctx = get_context()
    missing_relations = []
    if not ctx.get("db_user"):
        # NOTE: Charms don't allow to deploy cassandra in AllowAll mode
        missing_relations.append("contrail-controller-cluster")
    if not ctx.get("analytics_servers"):
        missing_relations.append("contrail-analytics")
    if 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 not ctx.get("keystone_ip"):
        status_set('blocked',
                   'Missing auth info in relation with contrail-auth.')
        return
    # TODO: what should happens if relation departed?

    render_config(ctx)
    for port in ("8082", "8080", "8143"):
        open_port(port, "TCP")

    run_container(CONTAINER_NAME, "contrail-control")
コード例 #2
0
def update_charm_status(update_config=True):
    update_config_func = render_config if update_config else None
    result = check_run_prerequisites(CONTAINER_NAME, CONFIG_NAME,
                                     update_config_func, SERVICES_TO_CHECK)
    if not result:
        return

    ctx = get_context()
    missing_relations = []
    if not ctx.get("controller_servers"):
        missing_relations.append("contrail-controller")
    if not ctx.get("analyticsdb_servers"):
        missing_relations.append("contrail-analyticsdb")
    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("keystone_ip"):
        status_set('blocked',
                   'Missing auth info in relation with contrail-controller.')
        return
    if not ctx.get("db_user"):
        # NOTE: Charms don't allow to deploy cassandra in AllowAll mode
        status_set(
            'blocked', 'Missing DB user/password info in '
            'relation with contrail-controller.')
        return
    if not ctx.get("rabbitmq_password"):
        # NOTE: Charms don't allow to deploy rabbitmq with guest access
        status_set(
            'blocked', 'Missing rabbitmq info in '
            'relation with contrail-controller.')
        return
    # TODO: what should happens if relation departed?

    render_config(ctx, do_check=False)
    open_port(8081, "TCP")

    run_container(CONTAINER_NAME)
コード例 #3
0
def update_charm_status(update_config=True, force=False):
    def _render_config(ctx=None, do_check=True):
        if not ctx:
            ctx = get_context()
        changed = render_and_check(ctx, "controller.conf",
                                   "/etc/contrailctl/controller.conf",
                                   do_check)
        return (force or changed)

    update_config_func = _render_config if update_config else None
    result = check_run_prerequisites(CONTAINER_NAME, CONFIG_NAME,
                                     update_config_func, SERVICES_TO_CHECK)

    # hack for 4.1 due to fat containers do not call provision_control
    _, message = status_get()
    identity = json_loads(config.get("auth_info"), dict())
    if (identity and 'contrail-control' in message
            and '(No BGP configuration for self)' in message):
        try:
            ip = get_ip()
            bgp_asn = '64512'
            # register control node to config api server (no auth)
            cmd = [
                '/usr/share/contrail-utils/provision_control.py',
                '--api_server_ip', ip, '--router_asn', bgp_asn, '--admin_user',
                identity.get("keystone_admin_user"), '--admin_password',
                identity.get("keystone_admin_password"), '--admin_tenant_name',
                identity.get("keystone_admin_tenant")
            ]
            docker_utils.docker_exec(CONTAINER_NAME, cmd, shell=True)
            # register control node as a BGP speaker without md5 (no auth)
            cmd = [
                '/usr/share/contrail-utils/provision_control.py',
                '--api_server_ip', ip, '--router_asn', bgp_asn, '--host_name',
                gethostname(), '--host_ip', ip, '--oper', 'add',
                '--admin_user',
                identity.get("keystone_admin_user"), '--admin_password',
                identity.get("keystone_admin_password"), '--admin_tenant_name',
                identity.get("keystone_admin_tenant")
            ]
            docker_utils.docker_exec(CONTAINER_NAME, cmd, shell=True)
            # wait a bit
            time.sleep(8)
            update_services_status(CONTAINER_NAME, SERVICES_TO_CHECK)
        except Exception as e:
            log("Can't provision control: {}".format(e), level=ERROR)
    # hack for contrail-api that is started at inapropriate moment to keystone
    if (identity and 'contrail-api' in message
            and '(Generic Connection:Keystone[] connection down)' in message):
        try:
            cmd = ['systemctl', 'restart', 'contrail-api']
            docker_utils.docker_exec(CONTAINER_NAME, cmd, shell=True)
            # wait a bit
            time.sleep(8)
            update_services_status(CONTAINER_NAME, SERVICES_TO_CHECK)
        except Exception as e:
            log("Can't restart contrail-api: {}".format(e), level=ERROR)

    if not result:
        return

    ctx = get_context()
    missing_relations = []
    if not ctx.get("db_user"):
        # NOTE: Charms don't allow to deploy cassandra in AllowAll mode
        missing_relations.append("contrail-controller-cluster")
    if not ctx.get("analytics_servers"):
        missing_relations.append("contrail-analytics")
    if 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 not ctx.get("rabbitmq_password"):
        status_set('blocked', 'Missing RabbitMQ info in external relations.')
        return
    if not ctx.get("keystone_ip"):
        status_set('blocked',
                   'Missing auth info in relation with contrail-auth.')
        return
    # TODO: what should happens if relation departed?

    _render_config(ctx, do_check=False)
    run_container(CONTAINER_NAME, ctx.get("cloud_orchestrator"))