VMware {code} Community
roshugee
Contributor
Contributor
Jump to solution

how to set unit Number and its maximum value in RDM

Hi,

I am trying to add RDM using vsphere sdk using the below code to return the controller Key and the unitNumber :

public static int[] getFreeDevice(VirtualMachine vMachine ,String deviceName ) {

VirtualDevice[] vDevice = vMachine.getConfig().getHardware().getDevice();

//System.out.println("DPS----->"+dps.length);

int retVal[] = new int[2];

for (VirtualDevice vd : vDevice) {

if (vd instanceof VirtualSCSIController) {

VirtualSCSIController vscsic = (VirtualSCSIController)vd;

retVal[0] = vscsic.getKey();

retVal[1] = vscsic.getDevice().

length+1 ;

if(retVal[1]==7)

retVal[1]=retVal[1]+1;

return retVal;

}

}

return null;

}

can anyone please tell me :

1. how to get the available units, say for eg : 0-15

2. how to get/set the limit (15)

3. how to do RDM once the unitNumber reaches 15

4. how to do RDM with the next value like SCSI1:0 after it reaches SCSI0:15

Thanks in advance.

Rohit

Reply
0 Kudos
1 Solution

Accepted Solutions
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,

Did u try manually in your environment to add new scsi controller as "scsi controller 1" for VM? First, try manually then make sure scsi controller option is enable to add one more scsi controller for VM.

And In your code

scsiCtrl.setBusNumber(0); // I think scsi controller 0 is already attached. So here it will be like this  scsiCtrl.setBusNumber(1);


scsiCtrl.setControllerKey(1000); // this line will not come because after adding scsi controller it will generate controller key. It is not depends with user option

other than this, I think some description and label is not necessary.

Thanks,

View solution in original post

Reply
0 Kudos
8 Replies
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,
I am not familiar with java but i am using c# for vsphere sdk.
I have used below code to get unit number. I think u can findout equivalent objects and methods in java.
VirtualDevice[] test = vmConfigInfo.hardware.device;
for (int k = 0; k < test.Length; k++)
{
    if (test[k].deviceInfo.label.ToLower().Equals("scsi controller 0"))
    {
        int[] numdisks = ((Vim25Api.VirtualController)(test[k])).device;
        int unitNumber = numdisks.Length;
        break;
    }
}
In this code, First i will find the number of disks added to VM. then set the unitnumber as increment of the number of disks there.
And I think u can use this concept and can verify whether the number of disks in "scsi controller 0" is reached 15 then u can add another scsi controller into it then add the disk as scsi1:0.
Thanks,
Reply
0 Kudos
roshugee
Contributor
Contributor
Jump to solution

Hi Vijaya,

Thanks for the reply and it really helped me.

Any idea on how to create a new SCSI controller incase there are no SCSI controllers enabled.

Any help appreciated.

Thanks again.

Reply
0 Kudos
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,

I think below c# code may help: This code for "scsi controller 1":

    int diskCtlrKey = 1;
                 VirtualDeviceConfigSpec scsiCtrlSpec = new VirtualDeviceConfigSpec();
                 scsiCtrlSpec.operation = VirtualDeviceConfigSpecOperation.add;
                 scsiCtrlSpec.operationSpecified = true;
                 VirtualLsiLogicController scsiCtrl = new VirtualLsiLogicController();
                 scsiCtrl.busNumber = 1;
                 scsiCtrlSpec.device = scsiCtrl;
                 scsiCtrl.key = diskCtlrKey;
                 scsiCtrl.sharedBus = VirtualSCSISharing.physicalSharing;
                 String ctlrType = scsiCtrl.GetType().Name;
                 vdiskSpec.device.controllerKey = scsiCtrl.key;
                 VirtualDeviceConfigSpec[] vdiskSpecArray = { scsiCtrlSpec, vdiskSpec };
                 vmConfigSpec.deviceChange = vdiskSpecArray;
Reply
0 Kudos
roshugee
Contributor
Contributor
Jump to solution

Hi Vijaya,

Thanks again for you kind response.

I have this code and there are no issues when the VM recongures, but I could not see this newly controller in the Edit Settings-->Hardware Devices List in the vsphere client and hence I could not assure whether the controller is actually created or not.

Can you please correct me where I am wrong :

VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualLsiLogicController scsiCtrl = new VirtualLsiLogicController();
VirtualDeviceConfigSpec scsiSpec = new VirtualDeviceConfigSpec();
scsiSpec.setOperation(VirtualDeviceConfigSpecOperation.add);

// is it necessary for this line . If I have this it throws error on some backing info : Incompatible backing device. If I dont have no errors
//scsiSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);

scsiCtrl.setKey(1000); // also tried with different keys like -1, 1, 2
scsiCtrl.setBusNumber(0);


scsiCtrl.setControllerKey(1000);
scsiCtrl.setHotAddRemove(true);
Description des=new Description();
des.setLabel("SCSI Controller 1");
des.setSummary("Logic LSI SAS");

scsiCtrl.setDeviceInfo(des);
scsiCtrl.setSharedBus(VirtualSCSISharing.noSharing);
//Add the scsi controller to SCSi device
scsiSpec.setDevice(scsiCtrl);

VirtualDeviceConfigSpec [] vdiskSpecArray = {scsiSpec};        
vmConfigSpec.setDeviceChange(vdiskSpecArray);

Task task = vMachine.reconfigVM_Task(vmConfigSpec);
String mapState = CommonAPI.waitForTask(task);
System.out.println("New controller key--->"+scsiCtrl.getKey());

Please let me know :

1. is there anything I am missing in the above code that results in the controller being not displayed in the devices list?

2. is it necessary to have scsiSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);  and if so how to set the backing onfo. Any working sample piece of code would help me.

Thanks in advance.

Reply
0 Kudos
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,

As per my understanding, below code will be helpful for scsi controller addition:
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
int ckey = 1000;
VirtualDeviceConfigSpec scsiSpec =
      new VirtualDeviceConfigSpec();
    scsiSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    VirtualLsiLogicController scsiCtrl =
        new VirtualLsiLogicController();
    scsiCtrl.setKey(cKey);
    scsiCtrl.setBusNumber(1);
    scsiCtrl.setSharedBus(VirtualSCSISharing.noSharing);
    scsiSpec.setDevice(scsiCtrl);
vmConfigSpec.setDeviceChange(scsiSpec);
Task task = vm.reconfigVM_Task(vmConfigSpec);
Thanks,
Reply
0 Kudos
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,

Did u try manually in your environment to add new scsi controller as "scsi controller 1" for VM? First, try manually then make sure scsi controller option is enable to add one more scsi controller for VM.

And In your code

scsiCtrl.setBusNumber(0); // I think scsi controller 0 is already attached. So here it will be like this  scsiCtrl.setBusNumber(1);


scsiCtrl.setControllerKey(1000); // this line will not come because after adding scsi controller it will generate controller key. It is not depends with user option

other than this, I think some description and label is not necessary.

Thanks,

Reply
0 Kudos
roshugee
Contributor
Contributor
Jump to solution

Hi Vijaya,

You are great!! thats was the exact problem with my code. Now I could pass the bus number dynamically using some logic. And is there a maximum value for the bus numbers that can be set. In vsphere UI I could see total 4 (0,1,2,3). Is this the default maximum or it can vary.

Anways, Thanks a lot for your prompt and immediate turn around Vijaya.

Thanks again..

Reply
0 Kudos
vijayagce
Enthusiast
Enthusiast
Jump to solution

Hi,

Thanks for marking as correct answer..

As per my understanding, bus number will available if any of the disk is free to add as RDM or virtualdisk. So could you check how many disks available when u check in vSphere UI. And its my assumption only. I think some maximum value for bus number may be there..Sorry, I am not aware abt it..

Thanks,

Reply
0 Kudos