Using Orchestration Actions to Determine the Best Execution Venue Environment

When creating or editing a blueprint, it is possible to determine that one or more Server Tier items should use an orchestration to determine the target Environment and even the OS Build* and additional Parameters. This is done by editing the Environment Selection Orchestration attribute of the Server Tier.

Keyword Arguments

The following table lists the most common keyword arguments and the context in which they are available.

Keyword Availability Context
group The Group this deployment order is for.
profile The profile of the user that requested the order.
blueprint The Blueprint being deployed.
server_tier The tier for which we are determining what Environment to use.
os_build The os_build defined on the order for this tier.
cfvs A list of custom field values representing all the parameters being used in the order for this tier.
resource The deployed resource created as part of the order, if it exists

Action Return

The Auto-Select Environment action is expected to always return a dictionary. CloudBolt understands the following keys:

Key Type Purpose
environment object the Environment object where servers for this tier should be provisioned.
parameters dict a list of key-value pairs that should be used as part of fulfilling the order. It may include environment specific parameters like instance_type if the environment returned is an AWS region for instance.
os_build object the OS Build object to use when provisioning servers for this tier. It’s the action writer’s responsibility to make sure the os_build returned is compatible with the environment returned

Developer Tip

The return dictionary is strikingly similar to the API payload for a server tier when deployng a blueprint via the CloudBolt REST API. A simple way to get started is to bring up, in the Web UI, a recent order for the blueprint and execute the following steps:

  1. Using the API button, check the payload for the order.
  2. Copy the dictionary related to the tier you are writing the orchestration for.
  3. Replace the ‘environment’ and ‘os_build’ values with actual objects instead of their api href representations

Example

In this fictional scenario, someone has decided that the evironment placement for a given server should always be the cluster with the least total of vms.

from common.methods import set_progress
from infrastructure.models import Environment
from utilities.logger import ThreadLogger
from resourcehandlers.vmware.models import VsphereResourceHandler

RESOURCE_HANDLER_ID = 7
CLUSTER_ONE = 'CORP-DEV'
CLUSTER_TWO = 'CORP-PROD'

logger = ThreadLogger(__name__)

def determine_deployment_environment_and_parameters(*args, **kwargs):

    logger.info("args are {}".format(args))
    logger.info("kwargs are {}".format(kwargs))

    # Gather the VMs for each cluster
    rh = VsphereResourceHandler.objects.get(id=RESOURCE_HANDLER_ID)
    env_one = rh.get_api_wrapper().get_vms_for_cluster(CLUSTER_ONE)
    env_two = rh.get_api_wrapper().get_vms_for_cluster(CLUSTER_TWO)

    # Choose the cluster that has less VMs
    if len(env_one) < len(env_two):
        cluster = CLUSTER_ONE
    else:
        cluster = CLUSTER_TWO

    # Use the first environment linked to the less-used cluster
    env = Environment.objects.filter(vmware_cluster=cluster).first()

    parameters = {
        "cpu_cnt": "1",
        "disk_size": "16 GB",
        "mem_size": "512 MB",
    }

    return {"environment": env, "parameters": parameters}