05-18-2015 11:12 AM - edited 03-01-2019 06:35 AM
Task Name | Pre and Post VM Provisioning via API Call |
Description | |
Prerequisites |
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
Instructions for Regular Workflow Use:
Enable the Developer Menu (click on Admin):
Check the check box:
The API call in question:
The API call Options:
The workflow to import:
The workflow input (the VDC and Catalog needs to be updated and the user and e-mail address):
The questions upon executions:
The workflow:
The workflow Cloupia Script:
mportPackage(com.cloupia.model.cIM);
importPackage(java.util);
importPackage(java.lang);
importPackage(java.io);
importPackage(com.cloupia.lib.util);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.cookie);
importPackage(org.apache.commons.httpclient.methods);
importPackage(org.apache.commons.httpclient.auth);
importPackage(com.cloupia.model.cEvent.notify);
importPackage(com.cloupia.lib.util.mail);
importPackage(com.cloupia.fw.objstore);
importPackage(com.cloupia.lib.util.managedreports);
//
// User input section
//
var vmName = ctxt.getInput("VM_Name");
var vmComment = ctxt.getInput("VM_Comment");
var vmCPU = ctxt.getInput("VM_CPU");
var vmMemory = ctxt.getInput("VM_Memory");
var catId = ctxt.getInput("VM_Catalog");
var vdcId = ctxt.getInput("VM_VDC");
var vmUser = ctxt.getInput("VM_USER");
var vmInputA1 = ctxt.getInput("VM_Post_Provisioning_Input_A1");
var vmInputA2 = ctxt.getInput("VM_Post_Provisioning_Input_A2");
//
//write everything to the SR log
//
logger.addInfo("vmName = "+vmName);
logger.addInfo("vmComment = "+vmComment);
logger.addInfo("vmMemory = "+vmMemory);
logger.addInfo("catId = "+catId);
logger.addInfo("vdcId = "+vdcId);
logger.addInfo("vmUser = "+vmUser);
//
//Convert the VDC and Catalog ID to a Name
//
var vdc = VDCUtil.getVDC(vdcId);
var vdcName = vdc.getVdcName();
var cat = VDCUtil.getVDCCatalogItem(catId);
var catName = cat.getCatalogItemName();
logger.addInfo("CatalogName: " + catName);
logger.addInfo("vdcName: " + vdcName);
//
// Set up the API call to provision a VM
//
var params = new APIProvisionParams();
params.setCatalogName(catName);
params.setVdcName(vdcName);
params.setUserID(vmUser);
params.setVmName(vmName);
params.setComments(vmComment);
params.setCores(vmMemory);
params.setMemoryMB(vmMemory);
//If Post Provision workflow has user inputs then the following code is required to pass user inputs to API.
//If the post provision workflow has only task inputs then skip the below code. It is not required to setPostProvWFUserInputs.
var nv1 = new APINameValue("A1",vmInputA1);
var nv2 = new APINameValue("A2",vmInputA2);
var list = new APINameValueList();
list.addNameValue(nv1);
list.addNameValue(nv2);
//Add this inputs list to provision params.
params.setPostProvWFUserInputs(list);
var childSrId = ctxt.getAPI().userAPIProvisionRequest(params);
var status = ctxt.waitForCompletion(childSrId, 1800000);
if (status == 0)
{
logger.addInfo("Provisioned SR ID ="+ childSrId+ " successfully.");
} else {
logger.addError("SR ID ="+ childSrId+ " failed");
}
The Catalog in question:
The catalog details:
The post provisioning workflow:
The details of the post provisioning workflows:
This workflow has 2 inputs:
The workflow:
The inputs:
In the "Set up the API call to provision a VM" section, please change the following in the script.
params.setCores(vmMemory); should be changed to params.setCores(vmCPU);
Note: In the existing script, memory input is getting passed as CPU input. hence, requesting to make the required changes after inporting the WF
You should use this one…
https://communities.cisco.com/docs/DOC-63923
Thanks Orf.
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: