Task Name | Ultimate naming convention (Rolodex) |
Description | - Create VM name depending on many different variables
|
Prerequisites | - Tested on 5.1
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs | - The variables are all listed in workflow properties.
- Custom drop down variables are also used
|
Instructions for Regular Workflow Use:
- Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
- Unzip the file on your computer. Should end up with a .WFD file.
- Log in to UCS Director as a user that has "system-admin" privileges.
- Navigate to "Policies-->Orchestration" and click on "Import".
- Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
- Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
- Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
- Click "Submit".
- A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.
The host name is assembled from 3 List of Value Fields:
The code:
// Full Script
importPackage(java.util);
importPackage(java.lang);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
// Assume the names of the Input Variables as below
var CATALOG_ID = "Catalog1";
var VDC_ID = "vDC1";
var PROVISION_QTY = "Provision Quantity1";
var VM_COMMENT = "VMComment";
var VM_NAME = "VM Name";
var VCPUS = "vCPU";
var MEMORY_MB = "Memory"
var ENV = "ENV"
var ROLE = "ROLE"
var OS = "OS"
var StartCounter = "StartCounter";
// Set the duration of the VMs as -1 (or number of hours)
var duration = -1;
// set begin time to now
var beginTime = -1;
var catId = ctxt.getInput(CATALOG_ID);
var vdcId = ctxt.getInput(VDC_ID);
var quantity = ctxt.getInput(PROVISION_QTY);
var vmcomment = ctxt.getInput(VM_COMMENT);
var StartCounter = ctxt.getInput(StartCounter);
var vmName1 = ctxt.getInput(VM_NAME);
var vcpus = ctxt.getInput(VCPUS);
var memorymb = ctxt.getInput(MEMORY_MB);
var ENV = ctxt.getInput(ENV);
var ROLE = ctxt.getInput(ROLE);
var OS = ctxt.getInput(OS);
var delaySecondsBetweenInvocation = 30;
var vdc = VDCUtil.getVDC(vdcId);
var vdcName = vdc.getVdcName();
var cat = VDCUtil.getVDCCatalogItem(catId);
var catName = cat.getCatalogItemName();
logger.addInfo("CatalogName: " + catName + " vdcName: " + vdcName);
logger.addInfo("Provision Qty ="+quantity);
var qty = 1;
try {
qty = Integer.valueOf(quantity);
} catch(e) {
logger.addWarning("Invalid quantity specified:"+quantity+ " provisioning VM");
}
var SC = 1;
try {
SC = Integer.valueOf(StartCounter);
} catch(e) {
logger.addWarning("Invalid StartCounter specified:"+StartCounter+ " provisioning VM");
}
var childSrIdArray = [];
for (var ctr = 0; ctr < qty; ctr = ctr + 1)
{
logger.addInfo("ctr ="+ (ctr));
logger.addInfo("SC ="+ (SC));
logger.addInfo("qty ="+ (qty));
var fincount = Number(SC) + Number(ctr);
logger.addInfo("fincount ="+ (fincount));
// Origional way the vars get assembled
// var comment = vmcomment + fincount;
// var vmName = vmName1 + ENV + ROLE + OS + fincount;
// var comment = vmcomment + fincount;
// var vmName = ENV + ROLE + OS + fincount;
// Counter comes from Service delivery
var vmName = ENV + ROLE + OS;
var comment = vmName;
logger.addInfo("vmcomment ="+ (vmcomment));
logger.addInfo("comment ="+ (comment));
logger.addInfo("vmName ="+ (vmName));
// var srId = ctxt.getAPI().userAPISubmitServiceRequestCustom(catName, vdcName , vmName,vcpus,memorymb,-1, -1, 2, comment);
var srId = ctxt.getAPI().userAPIVMWareProvisionRequest(catName, vdcName, vmName, comment, vcpus, memorymb, "", "");
childSrIdArray[ctr] = srId;
// Allow some delay between provisioning
sleep();
}
function sleep()
{
var milliseconds = delaySecondsBetweenInvocation * 1000;
Thread.sleep(milliseconds);
}
for (var i=0; i<childSrIdArray.length; i++)
{
var childSrId = childSrIdArray[i];
var status = ctxt.waitForCompletion(childSrId, 5600000);
if (status == 0)
{
logger.addInfo("Provisioned SR ID ="+ childSrId+ " successfully.");
} else {
logger.addError("SR ID ="+ childSrId+ " failed");
}
}