abbuggy
Contributor
Contributor

how to add a hard disk using reconfig command.

i am reconfiging a vm server using vim25 java api.

what i need to do is adding a hard disk to a vm.

i use reconfigVM_Task(virtualMachine, spec) method

then i organized the spec in which i set the para of new hard disk in,some of the fields the spec required i did not have. Such as "fileName","unitNumber" etc.

who can tell me where to find some documents to study with.

thanks in advance.

0 Kudos
6 Replies
vijayagce
Enthusiast
Enthusiast

Hi,

I think attached file will useful to u. Also check the "mo/samples/vm" folder for sample code for vm reconfiguration.

Thanks,

abbuggy
Contributor
Contributor

@vijaya Thanks for your reply

I had the sample code,and browsed it so many times.

But the code dosen't help.

For example the file name is generated by

String fileName = "["+dsName+"] "+ clp.get_option("vmname") + "/" + clp.get_option("value") + ".vmdk";

But i don't think it is the very format what i have already had.The disk file name of my virtual machine hard disk 1 is

[mydatastore] xbianTest3_1/xbianTest3.vmdk

"mydatastore" is the name of my data store.

"xbianTest3" is the name of my vm.

but how dose "xbianTest3_1" come?

0 Kudos
vijayagce
Enthusiast
Enthusiast

Hi,

We used vsphere sdk in c#. In that we make a filename as follows:

string dspath = "[mydatastore] xbianTest3_1/xbianTest3.vmdk";

String vmName = dspath.Substring(dspath.LastIndexOf("/") + 1);
vmName = vmName.Substring(0, vmName.IndexOf(".")) + "_" + unitNumber + ".vmdk";
Now it will have filename as "xbianTest3_1.vmdk" if its the second disk going to add.
It may help u to find the equivalent in java.
Thanks,

abbuggy
Contributor
Contributor

@vijayagce Thank you for your reply

In the logic of your code,the new vmName based on

[mydatastore] xbianTest3_1/xbianTest3.vmdk

will be

xbianTest3_1000

and then the disk file name will be

[mydatastore] xbianTest3_1/xbianTest3_1000.vmdk

but how did the xbianTest3_1 come?

And I want to know that how the logic come,from some documents by VMWare?

0 Kudos
vijayagce
Enthusiast
Enthusiast

Hi,

It will work..u thought unitnumber as controllerkey..controllerkey will be 1000 and it will have unitnumber as 0 for first harddisk in vm which has OS in it and we can add second hard disk with name as vmname_unitnumber.vmdk. Just try and let me know the result..what it get 1000 or 1.

I think u dont have code to find unitnumber. Please find below code in c# for unitnumber calculation:

VirtualDevice[] test = vmConfigInfo.hardware.device;
                int controllerKey = 0;
                int[] numdisks = null;
                int unitNumber = -99;
                for (int k = 0; k < test.Length; k++)
                {
                    if (test[k].deviceInfo.label.ToLower().Equals("scsi controller 0"))
                    {
                        controllerKey = test[k].key;
                        numdisks = ((Vim25Api.VirtualController)(test[k])).device;
                        unitNumber = numdisks.Length;
                        break;
                    }
                }

Thanks,

0 Kudos
vijayagce
Enthusiast
Enthusiast

for better understanding..try to connect with esx as "https://ESXIP/mob" in browser using esx username and password. it will give some clarification..because i got this ideas from that oneonly... mob is managedObjects..

some info:

after connect with link..u will get homepage as follow..

home-page-mob.png

then to get vm details give link name as follows

https://192.168.10.140/mob/?moid=ha-folder-vm

now u can get the page as follow

vmdetails.png

now click on number of ur VM or change link as follows "https://192.168.10.140/mob/?moid=96"

the window will be like this

vminfo.png

from this u can go to config and then hardware then u will get list of hardware for VM.

In that page 1000 will be controllerkey. When u click on controller key it will show how many vmdk disks are added for VM. If has only one vmdk file for VM then we will get one integervalue as 2000 in below image.

first-harddisk.png

then u have to go back and click the number what u seen in previous screenshot..like 2000

if u click that link then u can get unitnumbet as 0.

it may not understandable..let me know ur doubts to make clear in it..

Thanks,

0 Kudos