I started a discussion a couple of days ago http://communities.vmware.com/message/840165 and my question as written was answered. However what I am actually trying to do is create a VM from scratch where I define the following
Name
CPUs
Memory
Location
OS
Disksize
Everything works except the creation of the disks. I can get the SCSI controller to create but when I try to create and add the disks in the same operation I get an error - Incompatible device backing specified for device '1'
Here is a snippet of the relevant code
Public Function create_controller()
'define the controller
Dim controller As New VirtualLsiLogicController
controller.key = "1000"
controller.busNumber = "0"
controller.sharedBus = VirtualSCSISharing.noSharing
'define the config Spec of the controller device to add
Dim controlSpec As New VirtualDeviceConfigSpec
controlSpec.device = controller
controlSpec.operation = VirtualDeviceConfigSpecOperation.add
controlSpec.operationSpecified = True
Return controlSpec
End Function
Public Function Create_virtual_disk(ByVal path As String, ByVal dsize As Integer, ByVal dstoreRef As ManagedObjectReference)
Dim disk As New VirtualDisk
disk.key = "2000"
disk.controllerKey = "1000"
disk.controllerKeySpecified = True
disk.unitNumber = "0"
disk.unitNumberSpecified = True
'Define the description
Dim devInfo As New Description
devInfo.label = "CDrive"
devInfo.summary = "something"
disk.deviceInfo = devInfo
'define the Backing Info
Dim diskBacking As New VirtualDiskFlatVer2BackingInfo
diskBacking.diskMode = "persisitent"
diskBacking.fileName = path
diskBacking.datastore = dstoreRef
diskBacking.thinProvisioned = False
diskBacking.thinProvisionedSpecified = True
diskBacking.writeThrough = False
diskBacking.writeThroughSpecified = True
disk.backing = diskBacking
'Define the disk size
Dim disksize As Integer = dsize * 1024
disk.capacityInKB = disksize
'define the config Spec of the disk device to add
Dim disk_vm_configSpec As New VirtualDeviceConfigSpec
disk_vm_configSpec.device = disk
disk_vm_configSpec.fileOperation = VirtualDeviceConfigSpecFileOperation.create
disk_vm_configSpec.fileOperationSpecified = True
disk_vm_configSpec.operation = VirtualDeviceConfigSpecOperation.add
disk_vm_configSpec.operationSpecified = True
Return disk_vm_configSpec
End Function
'MAIN BIT OF CODE THAT CALLS THE FUNCTIONS
Dim controlVMSpec As New VirtualDeviceConfigSpec()
Dim diskVMSpec As New VirtualDeviceConfigSpec()
Dim path As String = "[storage1]Test/Test.vmdk"
controlVMSpec = create_controller()
diskVMSpec = Create_virtual_disk(path, "1", datastoreRef)
'******************************************************************************************
'The next bit works if I omit diskVMSpec - the controller is created successfully
'If I specify the diskVMSpec I get an error about Incompatible device backing specified for device '1'
configSpec.deviceChange = New VirtualDeviceConfigSpec() {controlVMSpec, diskVMSpec}
Dim hostRef As ManagedObjectReference = Nothing
Dim createTask As ManagedObjectReference = service.CreateVMTask(vmFolderRef, configSpec, resourcePoolRef,hostRef)
Help please before I go mad!!
Hi!
Just a minor issue found in your code:
diskBacking.diskMode = "persisitent"
means persistent, well?
Tos2k
Hi!
Just a minor issue found in your code:
diskBacking.diskMode = "persisitent"
means persistent, well?
Tos2k
Well done
Now that I have spelt 'persistent' correctly everything work fine.
How embarassing - killed by a typo! :smileyshocked:
I will go and hide now....
ISYS
If you ask me, it is a shame that VMware is not predefining all the constants used in the VimApi.
Regards, Tos2k
Good point - well made.
Some constants are and some aren't.
While they are resolving they constants issue they could also write an accurate reference guide so that it doesnt put the little red asterisk next to some properties with a note that says *Need not be set - when they plainly do.
ISYS
They could also add more info to methods and constants they have (popping up as a info in Visual Studio), a little description what the stuff is used for... they really could...
Tos2k
Hello,
For changing a diskmode to persistent can i use this code as well ?
Or do i need to modify something?
Thanks in advance
Hello
What you would have to do is define a new diskBacking with the diskmode set as persistent.
Then in the section that starts
Dim disk_vm_configSpec as New VirtaulDeviceConfigSpec
amend the 3rd line to end VirtualDeviceConfigSpecFileOperation.amend
amend the 5th line to end VirtualDeviceConfigSpecOperation.edit
This should do it
Regards
ISYS
Thanks,
Will try..
Regards
Steve