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
- 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});
}
- 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
- 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});
}
}
- 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}
}
- 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"}
}
- Create a select input for groups.
- Create a select input for clouds.
8.Create a select input for provision types.
- Create a select input for plans.
- 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
- 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
- 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
- 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.