I currently have a process to clone a vm but can't seem to find a way to set the Network/Vlan on the network adapter at the time it is cloned. Have found a few partial examples of it being done after a clone is complete, but would prefer it to be done all in one step if possible. If anyone has a .net example or can point me in the write direction i would be greatly appricated.
This can definitely be done in 1 step during the clone process, when you clone a VM, you're making a call to CloneVM_Task which accepts a clone spec, all you need to do is get a reference to the network device and from there specify the network in which you want to connect to and set that in the configuration spec. This clone spec allows you to change pretty much any of the settings prior to the clone and you can take a look at this vSphere SDK for Perl to give you an idea on how:
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Unfortunately for me trying to interpret perl to write .net isn't that easy. I already has a number of things in my clone process using VirtualMachineCloneSpec, including setuping up the network adapters ip and other options, but can't seem to find the write objects to set the network name. I see the VirtualDeviceConfigSpecOperation and VirtualDeviceConfigSpec objects but unfortunately the online documentation doesn't give me alot to work with.
Have you tried looking in code central for some sample code?
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Are you trying to change the network link for an existing virtual nic?
If you are trying to do the above, thenbelow steps might be helpful for you:
1. Create a virtualdeviceconfigspec data object and assign the device property of this object to the virtual device of which you are trying to change the virtual nic. You can retreive the required network device from the vm.config.hardware.device property which consists an array of virtual devices.
2. In VirtualDeviceConfigSpecOperation, you need to use edit operation as you are trying to change the network.
3. Set the the device.backing property of the VirtualDeviceConfigSpec to the type of backing you want to use, like , VirtualEthernetCardNetworkBackingInfo nic = new VirtualEthernetCardNetworkBackingInfo()
and set the deviceName property of this nic to the name of the network to which you want to connect your device to.
4. Pass this virtualdeviceconfigspec in the deviceChange property of virtualmachineconfigspec.
Thanks for the reply, put together what I thought looked correct, the code doesn't throw any errors but the Network isn't being updated. Maybe I am missing some other setting that is required?
'Nic settings Dim NicDevice As New VirtualDevice For i As Integer = 0 To oVirtualDevice.Length - 1 If oVirtualDevice(i).deviceInfo.label.ToUpper.Contains("NETWORK ADAPTER") Then NicDevice = oVirtualDevice(i) End If Next Dim nicSpec As New VirtualDeviceConfigSpec nicSpec.operation = VirtualDeviceConfigSpecOperation.edit nicSpec.device = NicDevice Dim nicBacking As New VirtualEthernetCardNetworkBackingInfo nicBacking.deviceName = "V1099" nicSpec.device.backing = nicBacking Dim vSpecArray As VirtualDeviceConfigSpec() = {nicSpec} configSpec.deviceChange = vSpecArray
To answer my own question.
nicSpec.operationSpecified = True