I also posted this in the CLI forum, but this area seems to have more activity.
Help!!!! Please!!
I am trying to automate the testing of iSCSI NIC cards, and am stumped at one spot. I can automate the creation of LUNs on the storage device, I can add them to the ESX host, and I can create an RDM, but I cannot figure out how to attach that RDM to a VM.
Creating the RDM is simple and straight forward.
vmkfstools -r /vmfs/devices/disks/naa.60060160cd103300b2678da7b981e211 /vmfs/volumes/datastore3/Linux1Auto1/Linux1Auto1_3.vmdk
This creates:
-rw------- 1 root root 5368709120 Mar 4 10:24 Linux1Auto1_3-rdm.vmdk
-rw------- 1 root root 487 Mar 4 10:24 Linux1Auto1_3.vmdk
If I use the vSphere GUI then it is easy to attach the exisiting drive (just created) to a VM.
Obviously, that is unacceptable for automation.
Googling this subject shows a lot of people asking the same question, but no satisfactory answer.
For example, one answer says to edit the appropriate .vmx file.
Obviously, that is unacceptable for automation.
Other answers point to perl scripts, so that indicates this is a doable task. We use Python for our automation, but all the automation work is command line on a vMA guest.
So, the question is what is the CLI command to attach this RDM to a VM.
It can be a vmware-cmd, or esxcli, or vmkfstools, or vicfg-user, or something else. I just need it to work with a vMA 5.1
Thanks.
Maybe this will help you get on the path:
create RDM KB: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=102625...
Add Disk to VM KB: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=100668...
Hope this helps.
SL
Thanks, but that does not work. The documentation specifically states:
Note: You cannot use these commands to add RDMs because vim-cmd does not support it.
and it gives a nice error message when one does try to do it.
Hence my cry for help in accomplishing this task.
http://www.vm-help.com/esx40i/manage_without_VI_client_6.php
vim-cmd vmsvc/device.diskaddexisting 272 /vmfs/volumes/datastore1/IOMETER/IOMETER.vmdk 0 1
I tried in my infra, it worked for me.
Thank you for your answer, but you DID NOT create an RDM. Your example creates a virtual disk.
from link: http://www.vm-help.com/esx40i/manage_without_VI_client_6.php
"vmkfstools -c 255G -d eagerzeroedthick -a lsilogic IOMETER.vmdk "
With that type of virtual disk then the command
"vim-cmd vmsvc/device.diskaddexisting 272 /vmfs/volumes/datastore1/IOMETER/IOMETER.vmdk 0 1"
does work.
However, I am creating an RDM, which is needed for our testing of I/O traffic. I use the command
vmkfstools -r /vmfs/devices/disks/naa.60060160cd103300b2678da7b981e211 /vmfs/volumes/datastore3/Linux1Auto1/Linux1Auto1_3.vmdk
This creates the RDM vmdk files:
-rw------- 1 root root 5368709120 Mar 6 10:10 Linux1Auto1_3-rdm.vmdk
-rw------- 1 root root 487 Mar 6 10:10 Linux1Auto1_3.vmdk
However, when trying to add the disk to a VM this is what occurs.
vim-cmd vmsvc/device.diskaddexisting 2 /vmfs/volumes/datastore3/Linux1Auto1/Linux1Auto1_3.vmdk 0 1
Reconfigure failed
This corresponds to the vim-cmd documentation that states it does not work with RDMs
So, once again I ask VMware. How do you add an RDM disk to a VM with a CLI command?
Thank you.
Create a Raw Device Mapping
Suppose you want to create a disk as a raw device mapping named Barney.vmdk in a VMFS volume named Vmfs1. You want to map to LUN 12 on target 2 from HBA 0. You want to attach this mapping to a virtual machine named /vm/Rubble.vmx, and you want physical compatibility mode for the guest. In the service console, type:
vmkfstools -r vmhba0:2:12 /vmfs/Vmfs1/Barney.vmdk
Edit the configuration file for the virtual machine and add lines similar to these:
scsi0:0.name = “Vmfs1:Barney.vmdk”
scsi0:0.deviceType = “scsi-passthru-rdm”
The value scsi-passthru-rdm specifies physical compatibility mode.
Note: This example assumes you have no other virtual disk attached to the virtual machine.
Hope this helps.
Thanks
SL
--------------- Please score if this post help int any way answer your questions ----------------------------------
Thanks, but editing files is not acceptable for automation. There can be no human intervention once the script starts. Adding code to edit files, and then editing again to remove the lines will not work.
Also, I just tried creating a virtual disk, and then converting it to an RDM.
vmkfstools -i L1A1.vmdk -d rdmp:/vmfs/devices/disks/naa.60060160cd10330057dc59aeb981e211 /vmfs/volumes/datastore3/Linux1Auto1/L1_rdm.vmdk
That works, but you still get the same error trying to attach it.
If you attach the virtual disk first, and then try to convert it, you get this error message.
Linux1Auto1 # vmkfstools -i L1A1.vmdk -d rdmp:/vmfs/devices/disks/naa.60060160cd10330057dc59aeb981e211 /vmfs/volumes/datastore3/Linux1Auto1/L1_rdm.vmdk
Failed to open 'L1A1.vmdk': Failed to lock the file (16392).
I do have a question on this part.
Edit the configuration file for the virtual machine and add lines similar to these:
scsi0:0.name = “Vmfs1:Barney.vmdk”
scsi0:0.deviceType = “scsi-passthru-rdm”
The value scsi-passthru-rdm specifies physical compatibility mode.
Out of courisity I am trying this manually to see what happens. After adding the lines then what? At this point nothing is different. Does the VM have to be rebooted for it to take effect? Is there a CLI command to make it take effect?
Thanks.
This is an interesting one. I used to do the same thing - removing and adding the rdm on the fly with this command:
So you need powercli (or perl SDK) for this. You need to create a devicechange spec and apply the spec with "ReconfigVM_task call.
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] ($numberOfdisks)
Then goes through a loop and add all disks:
$spec.deviceChange[$i] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[$i].operation = "add"
$spec.deviceChange[$i].device = New-Object VMware.Vim.VirtualDisk
$spec.deviceChange[$i].device.backing = New-Object VMware.Vim.$backing
$spec.deviceChange[$i].device.backing.fileName = "$Diskfile"
$spec.deviceChange[$i].device.backing.diskMode = "independent_persistent"
$spec.deviceChange[$i].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
$spec.deviceChange[$i].device.connectable.startConnected = $true
$spec.deviceChange[$i].device.connectable.allowGuestControl = $false
$spec.deviceChange[$i].device.connectable.connected = $true
$spec.deviceChange[$i].device.controllerKey = $ctrlKey
$spec.deviceChange[$i].device.unitNumber = $unit
finally, make the API call:
$vm.ReconfigVM_Task($spec)
Thanks. I guess I need to keep this in mind. It is disappointing that the esxcli commands are not complete and only provide a subset of funtionality needed to manage a VMware environment. Perl is out of the question since we use Python for automation. It would be nice if VMware provided a Python SDK.
In regard to PowerCLI, does this mean that instead of having the VMware VMA guest installed on an ESXi host one should install a Windows guest, and run the PowerCLI from that machine?
VC and vsphere API give you way more power in term of infrastructure management. Once you have the view of the object (get-view), you can do a lot of things on it, all through API call. One immediate challenge with managing vms via the host shell is that you always have to figure out where the vm is running at any moment. That is not an easy task if you have to rely on querying the hosts.
You do have to spawn up a windows VM to use powershell/powercli. VMware does not have a python SDK for vsphere API yet, so that is out of the question. To run it from a unix/linux system, I think your best bet is perl at this moment.
I am trying to accomplish the same task as budbueacham. I was able to set up physical RDM's through PowerCLI; however, we are running Linux and as such we would like to keep it that way all throughout. Perl seemed like the best option, but my Perl scripting abilities are severely limited. I've been working with the sample Perl scripts that come with the packages but none of them seem like they can be salvaged for this particular function (RDM creation).