cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2737
Views
1
Helpful
0
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task NameUltimate naming convention (Rolodex)
Description
  1. Create VM name depending on many different variables
Prerequisites
  1. Tested on 5.1
CategoryWorkflow
ComponentsvSphere 5.x
User Inputs
  1. The variables are all listed in workflow properties.
  2. Custom drop down variables are also used

Instructions for Regular Workflow Use:

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. 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:

Screen Shot 2015-05-18 at 7.33.51 AM.png

Screen Shot 2015-05-18 at 7.33.58 AM.png

Screen Shot 2015-05-18 at 7.34.05 AM.png

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");

                }

}

Getting Started

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:

Quick Links