Posts

Showing posts from December, 2018

On-Demand CPU Count Change for Virtual Machines with vRA

Image
Use Case The goal is to allow users to increase or decrease CPU count of their virtual machines (VMs) on-demand using vRA, with backend automation handled by vRO.  High-Level Workflow User Request in vRA User selects the VM and specifies the new vCPU count (increase or decrease). vRO Workflow Triggered vRA Event Broker or Day-2 Action calls the vRO workflow. Workflow Steps in vRO Find the VM in vCenter via API. Check Power Status : If Powered On → Check if CPU Hot-Add is enabled. If enabled → Update CPU count live. If not enabled → Shutdown VM, apply changes. Apply the requested vCPU change . If VM was shutdown → Power it back on. Status Update Workflow updates back to vRA, showing success/failure status Flow Diagram Benefits Self-Service – Users can request CPU changes anytime without admin involvement. Non-Disruptive – If hot-add is enabled, CPUs are added while VM is powered on. Governance – All changes tracked and co...

On-demand change the memory size of the virtual machine

/* Purpose: This workflow is used on-demand change the memory size of the virtual machine. Parameters: – memorySize (string) – vm (VC:VirtualMachine) */ try {               if (vm != null){                              var currentMemory = vm.summary.config.memorySizeMB;                              System.log( "Current Memory - " +currentMemory);                              // Getting the Memory that is being increased/decreased to the VM     ...

Change Lease Date - Day2 Operation by vCVM

System.log( "\n================================" ); System.log( "\n START: Lease Day Configuration." ); System.log( "\n================================" ); //var machine=payload.get("machine"); //System.log("VM name: "+machine.get("name")); //System.log("VM MoRef: "+machine.get("externalReference")); //vmName = machine.get("name"); vmName = vcvm.name; // Number days to Add (Lease days). var numberOfDaysToAdd = 10; var myResources = Server.findAllForType( "VCACCAFE:CatalogResource" , vmName); for each (resource in myResources){               if (resource.getName() == vmName){                              catalogResourceName = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost,resource.getId());         ...

How to Change Owner Day2 Operation by vm name

System.log("\n================================"); System.log("\n START: Change Owner Configuration."); System.log("\n================================"); var myResources = Server.findAllForType( "VCACCAFE:CatalogResource" , vmName); for each (resource in myResources){               if (resource.getName() == vmName){                              catalogResourceName = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost,resource.getId());                              catalogResourceMachine = catalogResourceName = vCACCAFEEntitiesFinder.getCatalogResource(cafeHost, catalogResourceName.parentResourceRef.getId());   ...

vRealize Orchestrator: Standardised Logger Action

Below is the logger action that I am using (this is the only action I have that does not conform to my template). /* Purpose: This action is used to provide consistent logging output for the calling actions/workflows. This allows greater visibility into what code is executing and where, which makes troubleshooting easier. Parameters: – logType (string) – logName (string) – logLevel (string) – logMessage (Any) Return Type : void */ switch (logLevel) {     case "log":         System.log("[" + logType + ": " + logName + "]: " + logMessage);         break;     case "debug":         System.debug("[" + logType + ": " + logName + "]: " + logMessage);         break;     case "error":         System.error("[" + logType + ": "...

How to find the type of object

helpers find type of object function typeOf (obj) {   return {}.toString.call(obj).split(' ')[1].slice(0, -1); }

How to get date format using vro

get date var date = new Date(),   yy=date.getFullYear().toString().substr(2,2);   mm=(date.getMonth() < 10 ? "0" : "" ) + (date.getMonth()+1);   dd=(date.getDate() < 10 ? "0" : "" ) + date.getDate();   HH=(date.getHours() < 10 ? "0" : "" ) + date.getHours();   MM=(date.getMinutes() < 10 ? "0" : "" ) + date.getMinutes(); Example: var myTimestamp = System.getCurrentTime(); var myDate = new Date(); myDate.setTime(myTimestamp); System.log("getYear from DateObject: "+(myDate.getYear()+1900)); System.log(System.formatDate(myDate, "YYYY-MM-dd HH:mm:ss")); Add Days: timerDate = new Date(); System.log( "Current date : '" + timerDate + "'" ); timerDate.setTime( timerDate.getTime() + (86400 * 1000) ); System.log( "Timer will expire at '" + timerDate + "'" ); The preceding exampl...

how to read write the file using vRO

file handling write file var tempDir = System.getTempDirectory() ; var fileWriter = new FileWriter(tempDir + "/readme.txt" ) ; System.log(tempDir + "/readme.txt" ); fileWriter.open() ; fileWriter.writeLine( "File written at : " +new Date()) ; fileWriter.writeLine( "Another line" ) ; fileWriter.close() ; read file var tempDir = System.getTempDirectory() ; var fileReader = new FileReader(tempDir + "/readme.txt" ) ; fileReader.open() ; var fileContentAsString = fileReader.readAll(); fileReader.close() ; System.log(fileContentAsString);

how to push vm into bios next boot

push vm into bios next boot var spec = new VcVirtualMachineConfigSpec() ; spec.bootOptions= new VcVirtualMachineBootOptions() ; spec.bootOptions.enterBIOSSetup = true; task=vcvm.reconfigVM_Task(spec);

how to get vcVms by regex expression

get vcVms by regex var vmPattern= "[a-z]{5}[0-9] [3]" var allVms = VcPlugin.getAllVirtualMachines();   var foundVms = new Array (); // Check if the VM match the regexp for (var i in allVms) {    if (allVms[i].name.match(vmPattern)) {       foundVms.push(allVms[i]);       System.log( "found Vm: " +allVms[i].name);    } }             return foundVms;

How to Get Folder of VM

vcVm parent folder name vcVmFolderName = vcVm.parent.name;

How to Get resource pool of VM

vcVm resource pool resourcePool = vcVm.runtime.host.parent.resourcePool;

How to Get Cluster of VM

vcVm cluster computeResource = vcVm.runtime.host.parent;

How to Get VMHost (Esxi host) of VM

vcVm esxi host hostSystem = vcVm.runtime.host;

How to get property of vcacVm properties from Payload

get vcacVm properties from Payload Create the vRO workflow with a single input name( Payload ) with a type Properties. Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Requested Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineProvisioned Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.BuildingMachine Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Disposing Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineActivated Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.UnprovisionMachine Make the value __*,Virtual* (two underscore) for each of the properties. var executionContext = System.getContext(); var owner = executionContext.getParameter( "__asd_requestedBy" ); var requestFor = executionContext.getParameter( "__asd_requestedFor" ); var machine = payload.get( "machine" ) ; var computerName = machine.get( "name" ); var vRAVmProperties = machine.get( ...

How to get property of vCAC virtual machine

get vcacVm properties var entity = vCACVm.getEntity(); var managed = entity.getProperty( "IsManaged" ); if (managed){               var currentVMName = entity.getProperty( "VirtualMachineName" );               vcacVmProperties = new Properties();               var virtualMachinePropertiesEntities = entity.getLink(vcacHost, "VirtualMachineProperties" );               for each (var virtualMachinePropertiesEntity in virtualMachinePropertiesEntities) {                              var propertyName = virtualMachinePropertiesEntity.getProperty( "PropertyName" );  ...

How to read property of vCAC virtual machine

read property of vCAC virtual machine var vcVm= var vcVmName = vcVm.name; var vcacHost = Server.findAllForType( "vCAC:VCACHost" )[0]; var vcVmProperty="bitbull.monitoring.sla"; var vcVmPropertyValue = null; System.log ( "vcVm.config.instanceUuid : " + vcVm.config.instanceUuid); var vcacVMEntity = System.getModule( "com.vmware.library.vcac" ).getVirtualMachineByExternalRefId(vcacHost, vcVm.config.instanceUuid); var properties = vcacVMEntity.getLink(vcacHost, "VirtualMachineProperties" ); for ( var i = 0 ;i < properties.length; i++){     var PropertyName = properties[i].getProperty( "PropertyName" );    var PropertyValue = properties[i].getProperty( "PropertyValue" );    if (PropertyName == vcVmProperty){       vcVmPropertyValue = PropertyValue;       System.log( "found " +vcVmProperty+ " : " +vcVmPropertyValue);       break;  ...

How to get owner of vcacVm

vRA/vCAC VM examples update property of vCAC virtual machine action var prop= "org.ezdc.monitoring.kumar" ; var val= "7x24" ; var vcacHost=Server.findAllForType( "vCAC:VCACHost" )[0]; var vcacVM= actionResult = System.getModule( "com.vmware.library.vcac" ).addUpdatePropertyFromVirtualMachineEntity(vcacHost, vcacVM.getEntity(),prop,val,false,false,false,false); return actionResult;

How to get owner of vcacVm get owner of vcacVm(cafeVm)

get owner of vcacVm(cafeVm) var cafeVmOwnerName=cafeVM.getOwners()[0].getValue(); var cafeVmOwnerAccount=cafeVM.getOwners()[0].getRef();

How to get Vm type (Template/vcVM/vcacVM) using vro

find vm type for later case decision var vmType = null; var vcacVm = new vCACVirtualMachine() ; vcacVm =Server.findAllForType( "vCAC:VirtualMachine" , "IsDeleted eq false and ExternalReferenceId eq '" + vcVm.id + "'" )[0]; if (vcVm.config.template == true){               vmType = "VcTemplate" ;               System.log(vcVm.name+ " is VcTemplate" ); } if (vcacVm != null && vmType == null){ // only search for managed flag if vcacVm is found (avoid error)               if (vcacVm.isManaged == true){                              vmType = "vCACVirtualMachine";          ...

How to get vcVm by vcacVm using vro

get vcVm by vcacVm var sdkConnections = VcPlugin.allSdkConnections; System.log(sdkConnections.length + " sdk Connections found..." ); for each ( var sdkConnection in sdkConnections) {   try {   vCenterVm = sdkConnection.searchIndex.findByUuid(null, vCACVm.vmUniqueID, true, false);   } catch (e) {System.log( "Error for SDK connection " + sdkConnection.name + " : " + e);}   if (vCenterVm != null) {   System.log( "Resolved vCenter VM " + vCenterVm.name);   return vCenterVm;   break;   } }

How to get vcacVm by vm.ID using vro

get vcacVm by vcVm var vcacVm=Server.findAllForType( "vCAC:VirtualMachine" , "IsDeleted eq false and ExternalReferenceId eq '" + vcVm.id + "'" [0]);

How to get cafevm by name string using vro

get cafeVm by name var cafeVm = vCACCAFEEntitiesFinder.findCatalogResources(cafeHost,vcVm.name)[0];

How to get vcaccafe host using vro

get cafeHost var cafeHost = Server.findAllForType( "VCACCAFE:VCACHost" )[0]; System.log( "cafeHost found by type: " +cafeHost.displayName); // cafeHost = null; var cafeHost = vCACCAFEEntitiesFinder.getHostForEntity(catalogItem); System.log( "cafeHost found by catalogItem: " +cafeHost.displayName); // cafeHost = null; var tenantName = "lab" ; var cafeHosts = Server.findAllForType( "VCACCAFE:VCACHost" ); if (!cafeHosts[0]){ throw "ERROR - Unable to find an IaaS Host" ;} for each ( var cafeHost in cafeHosts){   if (cafeHost.tenant == tenantName){      var tenantCafeHost = cafeHost;      break ;   } } if (!tenantCafeHost){               throw "ERROR - Unable to find a CAFE Host for: " + tenantName; } else {               System.log( "found cafeHost for te...