Creating a catalog item to resize existing instances

The following steps will show you how to create a catalog item that will allow a user who has full access to an instance to be able to resize the instance with a different plan.

Options List

  1. Create Options List to load Morpheus Groups as shown below:

Translation Script

for(var x=0;x < data.length; x++) {
  results.push({name: data[x].name,value:data[x].id});
}

  1. Create an option list to load available clouds filtered by group as shown below.

Translation Script

for(var x=0;x < data.length; x++) {
  newVal = data[x].zoneType.code.concat("-", data[x].id);
  results.push({name: data[x].name,value:newVal});
}

Request Script

results.siteId = input.myGroups
  1. Create an option list that contains list of provision types filtered by cloud as shown below. Make sure you specify your source URL and API access token.

Translation Script

for(var x=0;x < data.provisionTypes.length; x++) {
  cloudCode = data.provisionTypes[x].code;
  myCloudCode = String(input.myClouds).split("-")[0];
  if (myCloudCode == cloudCode){
    results.push({name: data.provisionTypes[x].name,value:data.provisionTypes[x].id});
  }
}

  1. Create an option list that contains list of plans filtered by cloud and provision type as shown below.

Translation Script

for(var x=0;x < data.length; x++) {
  results.push({name: data[x].name,value:data[x].id});
}

Request Script

myCloudId = String(data.myClouds).split("-")[1];
provisionTypeId = data.provisionTypes

//prevent option list from loading all the plans when provision type is not set
if (myCloudId > 0 && provisionTypeId > 0 )
{
    results = {zoneId: myCloudId, provisionTypeId:provisionTypeId}
}

  1. Create an option list that contains list of instances filtered by cloud.

Translation Script

for(var x=0;x < data.length; x++) {
  planName = data[x].plan.name;
  newInstanceName = data[x].name.concat(" Plan:", planName);
  results.push({name: newInstanceName,value:data[x].id});
}

Request Script

myCloudId = String(data.myClouds).split("-")[1];

if (myCloudId > 0){
    results = {zoneId:myCloudId}
}
else{//Force to load no instances when cloud is not selected
  results = {tagName:"N/A"}
}

  1. Create a select input for groups.

  1. Create a select input for clouds.

8.Create a select input for provision types.

  1. Create a select input for plans.

  1. Create a select input for instances.

Creating a task to resize the instance via API

We will be using Python task to resize the VM so please make sure python is already installed and virtualenv is already configured on your Morpheus appliance

  1. Create a python task with the settings shown below:

Task Content

import requests

serverUrl=morpheus['morpheus']['applianceUrl']
accessToken=morpheus['morpheus']['apiAccessToken']
instanceId=morpheus['customOptions']['instances']
newPlan=morpheus['customOptions']['myPlans']
url = serverUrl+"/api/instances/"+str(instanceId)+"/resize"

payload = {
    "instance": {"plan": {"id": newPlan}},
    "deleteOriginalVolumes": False
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "Authorization": "Bearer "+accessToken,
}

response = requests.put(url, json=payload, headers=headers,verify = False)

print(response.text)

Creating Workflow

  1. Create an operational workflow to resize the instances as shown below. Attach the Python task and the inputs we created on the previous steps as shown below.

Creating workflow catalog item

  1. Create a workflow catalog item and select the operational workflow we created on the previous step as shown below.

The resize instance catalog item is now ready for use.

Curious the use of the provision type list. You should be able to pass the cloud and instance information to filter available plans to select from. Either way love the contributions!