Plugin parameterization

How Cloud Management Platform (CMP) turns template variables in plugin code into action inputs

When you upload a plugin file or point at one by URL, CMP scans its contents for template variables such as {{ variable }} and creates an action input for each one it finds. See Action input parameters for more on generated inputs, and Action context for the objects available in each context.

CMP prompts users for those inputs and renders them into the action before it runs. Input values are escaped so they cannot execute arbitrary code while still rendering as expected.

File upload inputs

An action input can be of type File Upload, allowing users to pick a file when they run the action. It is supported for plugins used as blueprint build items, resource actions, and server actions. Use it to let someone choose a file to push to an S3 bucket, or onto a server being provisioned as part of a blueprint deployment.

CMP uploads the file to the appliance as part of the ordering process. What happens to it after that is up to your plugin code.

This sample shows how to resolve the uploaded file’s path and confirm it arrived:

from django.conf import settings
from os import path
from common.methods import set_progress


def run(job, blueprint_context, **kwargs):
    file = "{{ file }}"
    if file.startswith(settings.MEDIA_URL):
        set_progress("Converting relative URL to filesystem path")
        file_full_path = file.replace(settings.MEDIA_URL, settings.MEDIA_ROOT)
    else:
        file_full_path = f"{settings.MEDIA_ROOT}{file}"
    set_progress(f"File full path is: {file_full_path}")
    if path.exists(file_full_path):
        return "SUCCESS", "File upload successful!", ""
    else:
        return "FAILURE", "The file was not uploaded!", ""

After adding the plugin, edit the generated action input and change its type to File Upload.