Increase a virtual machine's hard disk
To increase a virtual machine's hard disk using VMware vRealize Automation (vRA) and vRealize Orchestrator (vRO), you can follow these general steps:
-
Create a vRO Workflow: Develop a workflow in vRO that performs the disk expansion. This workflow should include:
- Identifying the target virtual machine.
- Locating the specific hard disk to be expanded.
- Executing the disk size modification.
- Rescanning the storage adapter to recognize the new disk size.
- Extending the filesystem within the guest OS to utilize the additional space.
var devices = vm.config.hardware.device;
//var match = diskInfo.match(/\w+\s+\w+\s+(\d+)\s+.+?:\s*(\d+)\s*GB/);
var totalsize = increaseSizeGB + Number(Size)
var newDiskSizeKb = totalsize * 1024 * 1024;
//var diskName = 'Hard disk ' + match[1];
configSpec = new VcVirtualMachineConfigSpec();
configSpec.changeVersion = vm.config.changeVersion;
for (i in devices){
if (devices[i].deviceInfo.label == disknames.toString()){
var disk = devices[i]
System.debug("Found '" + disk.deviceInfo.label + "'");
}
}
var deviceChanges = new Array();
var deviceChange = new VcVirtualDeviceConfigSpec();
deviceChange.operation = VcVirtualDeviceConfigSpecOperation.edit;
deviceChange.device = disk;
deviceChange.device.capacityInKB = newDiskSizeKb;
deviceChanges.push(deviceChange);
configSpec.deviceChange = deviceChanges
//var actionResult = new Array();
//actionResult.push(configSpec);
task = vm.reconfigVM_Task(configSpec);
Create a vRO action for returnharddisknames
var disknames = new Array();
var devices = vm.config.hardware.device;
for (i in devices){
var disk = devices[i]
if(disk.deviceInfo.label.indexOf("Hard disk") == "0"){
System.log("----"+devices[i].deviceInfo.label.indexOf("Hard disk"));
System.log("----"+devices[i].deviceInfo.label);
disknames.push(String(disk.deviceInfo.label));
}
}
return disknames;
Create a vRO action for returnharddisksize
if(diskString != ""){
var disknames = new Array();
var devices = vm.config.hardware.device;
for (i in devices){
if (devices[i].deviceInfo.label == diskString){
var disk = devices[i]
return String((disk.capacityInKB / 1024 / 1024));
}
}
}
return "";
Comments
Post a Comment