VMware Cloud Community
vcpguy
Expert
Expert

VM life Cycle

Hi, I was wondering how can we use orchestrator to define VM life cycle. Ideally there should be a de-commission date OR a date where-in we need to look at a particular VM and decide, whether we still need this VM.

I am keeping a open mind. Any suggestions/ideas are most welcome.

Thanks

----------------------------------------------------------------------------- Please don't forget to reward Points for helpful hints; answers; suggestions. My blog: http://vmwaredevotee.com
0 Kudos
1 Reply
tschoergez
Leadership
Leadership

Hi!

Of course this is possible with vCO!

The main question is: Where do you want to place the logic and this decommission-date?

You could use custom attributes in vCenter, or custom attributes in vCO. (see http://www.vcoportal.de/2011/06/vco-custom-attributes/ ).

You can do this in an own database, using the JDBC or the brand-new SQL-Plugin.

When you have the date, you can create a workflow, which is designed to run by the task scheduler (for example once a day): It checks the decommissioning-date of each VM against the current date, and if a VM is "out-dated", then you can send an email to the owner of the VM (and/or the operations team).

For using the cuistom fields in vCenter, see the attached action to get an idea how to do this: It gets the date from a custom  field in vCenter, and compares it to current date. If the difference is smaller than the given treshold, than the action returns TRUE (and you workflow can do further stuff, like warning the VM-owner).

(For a sneak peek, find the source code below...)

Cheers,

Joerg

return-type: Boolean

Parameters: vm:VCVirtualMachine, custfield:String, tresholdDays:number

var curVMExpirationDate = new Date();

var isCloseOrBehind = false;

//Get expiration date string, cast/parse to date
var datStr = System.getModule("com.vmware.library.vc.customattribute").getCustomField(vm, custfield);
System.debug("datStr: " + datStr);
try {
    var curVMExpirationDate = new Date(Date.parse(datStr));
    System.debug("isDate: " + (curVMExpirationDate instanceof Date));
    System.debug("value: " + curVMExpirationDate);
    if (!curVMExpirationDate) {
        System.log("No valid expiration date in custom fields for " + vm.name + "\n returning FALSE");
        return false;
    }
}
catch (ex) {
        System.log("No valid expiration date in custom fields for " + vm.name + ": returning false");
        return false;
}

var currentDate = System.getCurrentTime();
//System.debug("current Date: " + currentDate);
var difference = curVMExpirationDate - currentDate;
if (!difference) {
        System.log("No valid expiration date in custom fields for " + vm.name + "\n returning FALSE");
        return false;
}
   
System.debug("difference between expire and current date: " + (difference / (24 *60 *60 *1000)) + " days" );
if (difference < (tresholdDays * 24 *60 *60 *1000)) {
    System.debug("VM " + vm.name + " expiration date in warning days! (" + (difference / (24 *60 *60 *1000)) + " days remaining)");
    isCloseOrBehind = true;
}

return isCloseOrBehind;

0 Kudos