VMware {code} Community
sasama1997
Contributor
Contributor

Change of size of disk of existing visualization machine(SDK for Java)

Hello.

For me, English is a beginner.

Frequently I'm sorry.

I try to change the size of the disk of a virtual machine in the state of power

off now.

It refers to VMReconfig.java that exists in the sample source file at

that time.

However, it is a specification that cannot change an existing size of the

disk.

The change method of someone is understood.

Actually, I will set disk information to VirtualMachineConfigSpec as argument spec of reconfigVM_Task.

However, neither a set item nor a set value are understood.

Moreover, the method of using ExtendVirtualDsik_Task was devised.

However, use is not understood.

/*******************************************************/

//Is the state after the size of the disk is changed to VirtualMachineConfigSpec

//here put?

ManagedObjectReference tmor

= cb.getConnection().getService().reconfigVM_Task(

_virtualMachine, vmConfigSpec);

/*******************************************************/

I survive terribly if this is understood.

It asks suitably.

0 Kudos
3 Replies
admin
Immortal
Immortal

ExtendVirtualDisk_Task is a method that expands the capacity of a virtual disk to the new capacity. Please note this method is experimental in nature and should not be used for production systems.

You can see the details for the above method in the Reference Guide. You will also need to get a managed object reference to a Virtual Disk Manager, the path to the datastore or the url to the virtual disk, the managed object reference to the datacenter, if datastore path is specified. In case url has been specified, you do not require to provide the datacenter mor and last, you need to provide the new capacity in kb to which you would like your virtual disk to be extended to.

ManagedObjectReference virtualDiskMgrRef

= cb.getConnection().getServiceContent().getVirtualDiskManager();

cb.getConnection().getService().extendVirtualDisk_Task(virtualDiskMgrRef, name_datastore_path_for_disk_to_extend, mor_datacenter, newCapacityKb);

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

If you are using the ReconfigVM_Task, the changes to the disk will need to be provided in the VirtualMachineConfigSpec. If you visit the Reference Guide for Data Object VirtualMachineConfigSpec, you will note it has a property deviceChange which is a VirtualDeviceConfigSpec[]. From this array, you will need to traverse to the config spec of disk, for which you would like to change the capacity.

You can also refer the getDiskDeviceConfigSpec() in the VMReconfig.java shipped with the VI SDK.

VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();

VirtualMachineConfigInfo vmConfigInfo

= (VirtualMachineConfigInfo)cb.getServiceUtil().getDynamicProperty(

_virtualMachine,"config");

VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();

for(int k=0;k<test.length;k++){

if(test[k].getDeviceInfo().getLabel().equalsIgnoreCase(

"SCSI Controller 0")){

}

}

String fileName = "["dsName"] "+ cb.get_option("vmname")

+ "/"cb.get_option("value")".vmdk";

diskfileBacking.setFileName(fileName);

diskfileBacking.setDiskMode(cb.get_option("diskmode"));

disk.setControllerKey(ckey);

disk.setUnitNumber(unitNumber);

disk.setBacking(diskfileBacking);

int size = 1024 * (Integer.parseInt(cb.get_option("disksize")));

disk.setCapacityInKB(size);

diskSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);

diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.replace);

When you are using this method, you will need to provide all the necessary backing file's parameters, in addition to CapacityInKb.

0 Kudos
sasama1997
Contributor
Contributor

Hello.

Up to now, "Disk change" has been done by two kind of method. It is not possible

to achieve it yet.

Error message is "Message デバイス「0」では無効な構成です。".

The attached file is a source of kind two method. If possible, please teach

trouble. Or, please teach the correct method.

1."VMReconfig_01.java" of the attached file is a source made with the point.

2."VMReconfig_01.java" of the attached file is a source made with the point. First of all, former disk is gotten, and only the size of the disk is changed.

My best regards.

Thank you very much.

0 Kudos
sasama1997
Contributor
Contributor

Thank you.

It was possible to do.

The revision part is the following.

//********************************************************

VirtualDeviceConfigSpec diskSpec = new VirtualDeviceConfigSpec();

VirtualDisk disk = null;

VirtualMachineConfigInfo vmConfigInfo =

(VirtualMachineConfigInfo)cb.getServiceUtil().getDynamicProperty(_virtualMachine, "config");

VirtualDiskFlatVer2BackingInfo diskfileBacking

= new VirtualDiskFlatVer2BackingInfo();

VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();

for(int k=0;k

if(test[k].getDeviceInfo().getLabel().equalsIgnoreCase(

cb.get_option("value"))){

disk = (VirtualDisk)test[k];

}

}

if(disk != null) {

int size = 1024 * 1024 * 26;

disk.setCapacityInKB(size);

diskSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);

//diskSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.replace);

diskSpec.setDevice(disk);

}

if (diskSpec != null){

VirtualDeviceConfigSpec [] vdiskSpecArray = {diskSpec};

vmConfigSpec.setDeviceChange(vdiskSpecArray);

}

//**********************************************************

0 Kudos