Example #1
0
def main(ctx, config_file, sync):
    """Calm CLI

\b
Commonly used commands:
  calm get apps   -> Get list of apps
  calm get bps   -> Get list of blueprints
  calm launch bp --app_name Fancy-App-1 MyFancyBlueprint   -> Launch a new app from an existing blueprint
  calm create bp -f sample_bp.py --name Sample-App-3   -> Upload a new blueprint from a python DSL file
  calm describe app Fancy-App-1   -> Describe an existing app
  calm app Fancy-App-1 -w my_action   -> Run an action on an app
  calm get runbooks  -> Get list of runbooks
  calm describe runbook MyFancyRunbook   -> Describe an existing runbook
  calm create runbook -f sample_rb.py --name Sample-RB  -> Upload a new runbook from a python DSL file
  calm run runbook MyFancyRunbook -> Runs the existing runbook MyFancyRunbook
  calm run runbook -f sample_rb.py -> Runs the runbook from a python DSL file
  calm get execution_history  -> Get list of runbook executions
  calm get endpoints -> Get list of endpoints
  calm create endpoint -f sample_ep.py --name Sample-Endpoint -> Upload a new endpoint from a python DSL file
"""
    ctx.ensure_object(dict)
    ctx.obj["verbose"] = True
    try:
        validate_version()
    except Exception:
        LOG.debug("Could not validate version")
        pass
    if config_file:
        update_config_file_location(config_file=config_file)
    if sync:
        Cache.sync()
Example #2
0
def update_cache():
    """Update the data for dynamic entities stored in the cache"""

    Cache.sync()
    Cache.show_data()
    LOG.info(
        highlight_text("Cache updated at {}".format(datetime.datetime.now())))
Example #3
0
def compile_blueprint(bp_file, no_sync=False):

    # Sync only if no_sync flag is not set
    if not no_sync:
        LOG.info("Syncing cache")
        Cache.sync()

    user_bp_module = get_blueprint_module_from_file(bp_file)
    UserBlueprint = get_blueprint_class_from_module(user_bp_module)
    if UserBlueprint is None:
        return None

    bp_payload = None
    if isinstance(UserBlueprint, type(SimpleBlueprint)):
        bp_payload = UserBlueprint.make_bp_dict()
    else:
        UserBlueprintPayload, _ = create_blueprint_payload(UserBlueprint)
        bp_payload = UserBlueprintPayload.get_dict()

        # Note - Install/Uninstall runbooks are not actions in Packages.
        # Remove package actions after compiling.
        cdict = bp_payload["spec"]["resources"]
        for package in cdict["package_definition_list"]:
            if "action_list" in package:
                del package["action_list"]

    return bp_payload
Example #4
0
def update_cache(obj, entity_type):
    """Update the data for dynamic entities stored in the cache"""

    click.echo(highlight_text("Updating cache ..."))
    Cache.sync(entity_type)
    show_cache(obj)
    click.echo(
        highlight_text("Cache updated at {}".format(datetime.datetime.now())))
Example #5
0
def update_cache(obj, entity_type):
    """Update the data for dynamic entities stored in the cache"""

    LOG.debug("Updating cache")
    Cache.sync(entity_type)
    LOG.debug("Success")
    show_cache(obj)
    LOG.info(highlight_text("Cache updated at {}".format(datetime.datetime.now())))
Example #6
0
def update_cache(entity_type):
    """Update the data for dynamic entities stored in the cache"""

    LOG.debug("Updating cache")
    # Update api cache
    Cache.sync(entity_type)
    # Update version cache
    Version.sync()
    LOG.debug("Success")
    show_cache()
    LOG.info(highlight_text("Cache updated at {}".format(datetime.datetime.now())))
Example #7
0
def compile_blueprint(bp_file, no_sync=False):

    # Sync only if no_sync flag is not set
    if not no_sync:
        Cache.sync()

    user_bp_module = get_blueprint_module_from_file(bp_file)
    UserBlueprint = get_blueprint_class_from_module(user_bp_module)
    if UserBlueprint is None:
        return None

    bp_payload = None
    if isinstance(UserBlueprint, type(SimpleBlueprint)):
        bp_payload = UserBlueprint.make_bp_dict()
    else:
        UserBlueprintPayload, _ = create_blueprint_payload(UserBlueprint)
        bp_payload = UserBlueprintPayload.get_dict()

    return bp_payload
Example #8
0
def init_bp(bp_name, dir_name, provider_type):

    bp_name = bp_name.strip().split()[0].title()
    bp_dir, local_dir, key_dir, script_dir = make_bp_dirs(dir_name, bp_name)

    # sync cache
    LOG.info("Syncing cache")
    Cache.sync()
    LOG.info("Success")

    # Creating keys
    LOG.info("Generating keys for credentials")
    create_cred_keys(key_dir)
    LOG.info("Success")

    # create scripts
    create_scripts(script_dir)

    create_bp_file(bp_dir, bp_name, provider_type)
Example #9
0
def init_bp(service_name, dir_name, provider_type):

    bp_name = "{}Blueprint".format(service_name, )

    bp_dir, local_dir, key_dir, script_dir = make_bp_dirs(dir_name, bp_name)

    # sync cache
    LOG.info("Syncing cache")
    Cache.sync()
    LOG.info("Success")

    # Creating keys
    LOG.info("Generating keys for credentials")
    create_cred_keys(key_dir)
    LOG.info("Success")

    # create scripts
    create_scripts(script_dir)

    create_bp_file(bp_dir, service_name, provider_type)
Example #10
0
def main(ctx, config_file, sync):
    """Calm CLI

\b
Commonly used commands:
  calm get apps   -> Get list of apps
  calm get bps   -> Get list of blueprints
  calm launch bp --app_name Fancy-App-1 MyFancyBlueprint   -> Launch a new app from an existing blueprint
  calm create bp -f sample_bp.py --name Sample-App-3   -> Upload a new blueprint from a python DSL file
  calm describe app Fancy-App-1   -> Describe an existing app
  calm app Fancy-App-1 -w my_action   -> Run an action on an app
"""
    ctx.ensure_object(dict)
    ctx.obj["verbose"] = True
    try:
        validate_version()
    except Exception:
        LOG.debug("Could not validate version")
        pass
    if config_file:
        get_config(config_file=config_file)
    if sync:
        Cache.sync()
Example #11
0
def init_bp(service_name, dir_name, provider_type):

    bp_name = "{}Blueprint".format(service_name, )

    bp_dir, local_dir, key_dir, script_dir = make_bp_dirs(dir_name, bp_name)

    # sync cache
    Cache.sync()

    # Getting the subnet registered to the project
    client = get_api_client()
    config = get_config()

    project_name = config["PROJECT"].get("name", "default")
    project_uuid = Cache.get_entity_uuid("PROJECT", project_name)

    res, err = client.project.read(project_uuid)
    if err:
        raise Exception("[{}] - {}".format(err["code"], err["error"]))

    res = res.json()

    subnets = res["status"]["project_status"]["resources"].get(
        "subnet_reference_list", [])
    if not subnets:
        raise Exception("no subnets registered !!!")

    default_subnet = subnets[0]["name"]

    create_bp_file(bp_dir, service_name, default_subnet, provider_type)

    # Creating keys
    create_cred_keys(key_dir)

    # create scripts
    create_scripts(script_dir)
Example #12
0
def sync_cache():
    Cache.sync()
Example #13
0
def sync_cache():
    click.echo("Updating Cache ... ", nl=False)
    Cache.sync()
    click.echo("[Success]")
Example #14
0
def sync_cache():
    LOG.info("Updating Cache")
    Cache.sync()
    LOG.info("Success")