Example #1
0
def set_server_details(
    ip,
    port,
    username,
    password,
    project_name,
    db_file,
    local_dir,
    config_file,
):

    if not (ip and port and username and password and project_name):
        click.echo("Please provide Calm DSL settings:\n")

    host = ip or click.prompt("Prism Central IP", default="")
    port = port or click.prompt("Port", default="9440")
    username = username or click.prompt("Username", default="admin")
    password = password or click.prompt(
        "Password", default="", hide_input=True)
    project_name = project_name or click.prompt("Project", default="default")

    # Default log-level
    log_level = "INFO"

    # Do not prompt for init config variables, Take default values for init.ini file
    config_file = config_file or get_default_config_file()
    local_dir = local_dir or get_default_local_dir()
    db_file = db_file or get_default_db_file()

    LOG.info("Checking if Calm is enabled on Server")

    # Get temporary client handle
    client = get_client_handle_obj(host, port, auth=(username, password))
    Obj = get_resource_api("services/nucalm/status", client.connection)
    res, err = Obj.read()

    if err:
        click.echo("[Fail]")
        raise Exception("[{}] - {}".format(err["code"], err["error"]))

    result = json.loads(res.content)
    service_enablement_status = result["service_enablement_status"]
    LOG.info(service_enablement_status)

    LOG.info("Verifying the project details")
    project_name_uuid_map = client.project.get_name_uuid_map(
        params={"filter": "name=={}".format(project_name)})
    if not project_name_uuid_map:
        LOG.error("Project '{}' not found !!!".format(project_name))
        sys.exit(-1)
    LOG.info("Project '{}' verified successfully".format(project_name))

    # Writing configuration to file
    set_dsl_config(
        host=host,
        port=port,
        username=username,
        password=password,
        project_name=project_name,
        log_level=log_level,
        config_file=config_file,
        db_location=db_file,
        local_dir=local_dir,
    )

    # Updating context for using latest config data
    LOG.info("Updating context for using latest config file data")
    init_context()
Example #2
0
def set_server_details(
    ip,
    port,
    username,
    password,
    project_name,
    db_file,
    local_dir,
    config_file,
    use_custom_defaults,
):

    if not (ip and port and username and password and project_name):
        click.echo("Please provide Calm DSL settings:\n")

    host = ip or click.prompt("Prism Central IP", default="")
    port = port or click.prompt("Port", default="9440")
    username = username or click.prompt("Username", default="admin")
    password = password or click.prompt("Password", default="", hide_input=True)
    project_name = project_name or click.prompt("Project", default="default")

    # Default log-level
    log_level = "INFO"

    if use_custom_defaults:
        # Prompt for config file
        config_file = config_file or click.prompt(
            "Config File location", default=get_default_config_file()
        )

        # Prompt for local dir location  at initializing dsl
        local_dir = local_dir or click.prompt(
            "Local files directory", default=get_default_local_dir()
        )

        # Prompt for db file location at initializing dsl
        db_file = db_file or click.prompt(
            "DSL local store location", default=get_default_db_file()
        )

    else:
        config_file = config_file or get_default_config_file()
        local_dir = local_dir or get_default_local_dir()
        db_file = db_file or get_default_db_file()

    LOG.info("Checking if Calm is enabled on Server")

    # Get temporary client handle
    client = get_client_handle_obj(host, port, auth=(username, password))
    Obj = get_resource_api("services/nucalm/status", client.connection)
    res, err = Obj.read()

    if err:
        click.echo("[Fail]")
        raise Exception("[{}] - {}".format(err["code"], err["error"]))

    result = json.loads(res.content)
    service_enablement_status = result["service_enablement_status"]
    LOG.info(service_enablement_status)

    # Writing configuration to file
    set_dsl_config(
        host=host,
        port=port,
        username=username,
        password=password,
        project_name=project_name,
        log_level=log_level,
        config_file=config_file,
        db_location=db_file,
        local_dir=local_dir,
    )

    # Updating context for using latest config data
    LOG.info("Updating context for using latest config file data")
    config_obj = get_context()
    config_obj.update_config_file_context(config_file=config_file)