Beispiel #1
0
def set_server_details(ip, port, username, password, project_name):

    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")

    click.echo("\nChecking if Calm is enabled on Server ... ", nl=False)
    # Get temporary client handle
    client = get_client_handle(host,
                               port,
                               auth=(username, password),
                               temp=True)
    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"]
    click.echo("[{}]".format(service_enablement_status))

    db_location = os.path.join(os.path.expanduser("~"), ".calm", "dsl.db")

    # Default user config file
    user_config_file = get_default_user_config_file()

    click.echo("Writing config to {} ... ".format(user_config_file), nl=False)
    init_config(host, port, username, password, project_name, db_location)
    click.echo("[Success]")

    # Update client handle with new settings if no exception occurs
    update_client_handle(host, port, auth=(username, password))
Beispiel #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(host,
                               port,
                               auth=(username, password),
                               temp=True)
    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)

    # Updating init file data
    update_init_config(config_file=config_file,
                       db_file=db_file,
                       local_dir=local_dir)

    LOG.info("Writing config to {}".format(config_file))
    init_config(host, port, username, password, project_name, log_level)

    # Update client handle with new settings if no exception occurs
    update_client_handle(host, port, auth=(username, password))