Beispiel #1
0
    def get_cache_tables(cls, sync_version=False):
        """returns tables used for cache purpose"""

        db = get_db_handle()
        db_tables = db.registered_tables

        # Get calm version from api only if necessary
        calm_version = CALM_VERSION
        if sync_version or (not calm_version):
            context = get_context()
            server_config = context.get_server_config()
            client = get_client_handle_obj(
                server_config["pc_ip"],
                server_config["pc_port"],
                auth=(server_config["pc_username"], server_config["pc_password"]),
            )
            res, err = client.version.get_calm_version()
            if err:
                LOG.error("Failed to get version")
                sys.exit(err["error"])
            calm_version = res.content.decode("utf-8")

        cache_tables = {}
        for table in db_tables:
            if hasattr(table, "__cache_type__") and (
                LV(calm_version) >= LV(table.feature_min_version)
            ):
                cache_tables[table.__cache_type__] = table
        return cache_tables
Beispiel #2
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()
Beispiel #3
0
def _set_config(
    host,
    port,
    username,
    password,
    project_name,
    db_location,
    log_level,
    config_file,
    local_dir,
):
    """writes the configuration to config files i.e. config.ini and init.ini

    \b
    Note: Cache will be updated if supplied host is different from configured host.
    """

    # Fetching context object
    ContextObj = get_context()

    server_config = ContextObj.get_server_config()

    # Update cache if there is change in host ip
    update_cache = host != server_config["pc_ip"] if host else False
    host = host or server_config["pc_ip"]
    username = username or server_config["pc_username"]
    port = port or server_config["pc_port"]
    password = password or server_config["pc_password"]

    project_config = ContextObj.get_project_config()
    project_name = project_name or project_config.get("name") or "default"

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

    log_config = ContextObj.get_log_config()
    log_level = log_level or log_config.get("level") or "INFO"

    # Take init_configuration from user params or init file
    init_config = ContextObj.get_init_config()
    config_file = (config_file or ContextObj._CONFIG_FILE
                   or init_config["CONFIG"]["location"])
    db_location = db_location or init_config["DB"]["location"]
    local_dir = local_dir or init_config["LOCAL_DIR"]["location"]

    # Set the dsl configuration
    set_dsl_config(
        host=host,
        port=port,
        username=username,
        password=password,
        project_name=project_name,
        db_location=db_location,
        log_level=log_level,
        local_dir=local_dir,
        config_file=config_file,
    )
    LOG.info("Configuration changed successfully")

    # Updating context for using latest config data
    init_context()
    if update_cache:
        sync_cache()
Beispiel #4
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)