VMware Cloud Community
sastre
Enthusiast
Enthusiast

Cannot deploy VM from template to different vCenter Server (in same SSO domain)

Hi,

I'm trying to deploy a VM from a template stored in one vCenter server, to another vCenter server. I can do this using the Web Client successfully.

Whilst connected to both vCenter servers, the code I am using to test deploying is like so:

$SourceVC = 'pocappprod'

$DestinationVC = 'pocappdev'

$VmName = 'CloneTest001'

New-VM -Name $VmName -Template (Get-Template -Name 'W2K12-Clone' -Server $sourceVC) -Datastore (Get-Datastore -Server $destinationVC | Select -first 1) -VMHost (Get-vmhost -Server $destinationVC | Select -first 1) -Server $destinationVC

So, get the template from the source VC, target the New-VM command at the destination VC, with both host and datastore objects from the destination VC also.

I get the error:

writeErrorStream      : True

Exception             : VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 13/05/2016 14:44:23    New-VM        The object has already been

                        deleted or has not been completely created     ---> VMware.Vim.VimException: The object has already been deleted or has not been

                        completely created ---> System.Web.Services.Protocols.SoapException: The object has already been deleted or has not been completely

                        created

                           at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream

                        responseStream, Boolean asyncCall)

                           at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

                           at VimApi_60.VimService.RetrieveProperties(ManagedObjectReference _this, PropertyFilterSpec[] specSet)

                           at VMware.Vim.PropertyCollector.RetrieveProperties(PropertyFilterSpec[] specSet)

                           --- End of inner exception stack trace ---

                           at VMware.Vim.PropertyCollector.RetrieveProperties(PropertyFilterSpec[] specSet)

                           at VMware.Vim.ViewBase.UpdateViewData(String[] properties)

                           at VMware.VimAutomation.ViCore.Impl.V1.Service.VmServiceImpl.NewVM(TemplateInterop template, VMHostInterop vmHost, String name,

                        VIContainerInterop resourceContainer, FolderInterop location, StorageResourceInterop datastore, Nullable`1 diskStorageFormat,

                        OSCustomizationSpecInterop customization, Boolean allowNested, Boolean isRequestedAsync, String description, Nullable`1

                        haRestartPriority, Nullable`1 haIsolationResponse, Nullable`1 drsAutomationLevel, AdvancedOption[] options)

                           at VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM.DoWork(VIAutomation client, List`1 moList)

                           at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.DoWork(VIConnection connection, List`1 moList)

                           at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.DoWorkEx(VIConnection connection, List`1 moList)

                           at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ConnectionDispatchHelper.ExecuteRunlist(Dictionary`2 runlist, DoWorkDelegate

                        doWorkDelegate, UidDispatchHelper uidDispatchHelper, List`1 result)

                           --- End of inner exception stack trace ---

TargetObject          :

CategoryInfo          : NotSpecified: (:) [New-VM], VimException

FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

ErrorDetails          :

InvocationInfo        : System.Management.Automation.InvocationInfo

ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

PipelineIterationInfo : {0, 1}

PSMessageDetails      :

I am running vSphere 6 Update 2 for both vCenter and ESXi. The vCenter servers are setup using the following architecture, with one vCenter connected to a singular platform services controller, and replication between them:

vcar.PNG

Any ideas? I'm aware I can install the Onyx fling but

1) This is unlikely to spit out a New-VM command but rather a more complex code structure.

2) I don't know if the fling will gather commands across multiple vCenter instances.

Thanks!

Tags (1)
7 Replies
LucD
Leadership
Leadership

I suspect this might be due to the way you address the destination.

As William showed for vMotion accross vCenters, see Did you know of an additional cool vMotion capability in vSphere 6.0?, you might try to use the addressing for the target in that way.

But you would also have to revert to calling the API directly, I don't think the New-VM cmdlet already supports this.

Perhaps Onyx would show how the addressing is done


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

sastre
Enthusiast
Enthusiast

Interesting, thanks LucD. These vCenter servers *are* part of the same SSO domain though and William's article is about vMotion between vCenters in different SSO domains.

My post-posting here(!) thinking was that the quickest way to solve the problem was to write a function which simply removes the template from the source vCenter and reimports it on the destination vCenter, and then the New-VM would run fine. Not ideal, but it'd work.

Nevertheless I'll give Onyx a go though and see what it spits out for a "cross-vCenter same SSO domain, New-VM clone template task".

As an aside, do you know how we report bugs to VMware? I'm familiar with the process for doing this with Cisco and Microsoft, but not VMware.

Thank you.

Reply
0 Kudos
LucD
Leadership
Leadership

I normally go via MyVMware, but you need an account for that and valid Support contract afaik.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
sastre
Enthusiast
Enthusiast

The Onyx client returned the following for a same SSO domain, cross vCenter "clone template to VM" operation:

$folder = New-Object VMware.Vim.ManagedObjectReference

$folder.value = 'group-v22'

$folder.type = 'Folder'

$name = 'DeployedVM'

$spec = New-Object VMware.Vim.VirtualMachineCloneSpec

$spec.template = $false

$spec.powerOn = $false

$spec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.location.folder = New-Object VMware.Vim.ManagedObjectReference

$spec.location.folder.value = 'group-v22'

$spec.location.folder.type = 'Folder'

$spec.location.host = New-Object VMware.Vim.ManagedObjectReference

$spec.location.host.value = 'host-28'

$spec.location.host.type = 'HostSystem'

$spec.location.pool = New-Object VMware.Vim.ManagedObjectReference

$spec.location.pool.value = 'resgroup-27'

$spec.location.pool.type = 'ResourcePool'

$spec.location.disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator[] (3)

$spec.location.disk[0] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[0].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[0].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[0].diskBackingInfo.fileName = ''

$spec.location.disk[0].diskBackingInfo.diskMode = ''

$spec.location.disk[0].datastore = New-Object VMware.Vim.ManagedObjectReference

$spec.location.disk[0].datastore.value = 'datastore-29'

$spec.location.disk[0].datastore.type = 'Datastore'

$spec.location.disk[0].diskId = 2000

$spec.location.disk[1] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[1].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[1].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[1].diskBackingInfo.fileName = ''

$spec.location.disk[1].diskBackingInfo.diskMode = ''

$spec.location.disk[1].diskId = 2001

$spec.location.disk[2] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[2].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[2].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[2].diskBackingInfo.fileName = ''

$spec.location.disk[2].diskBackingInfo.diskMode = ''

$spec.location.disk[2].diskId = 2002

$spec.location.service = New-Object VMware.Vim.ServiceLocator

$spec.location.service.instanceUuid = '6d6939a7-6c28-4bdf-8f56-479e7e96a55a'

$spec.location.service.sslThumbprint = 'F4:1C:AC:B8:CE:8E:DF:22:A8:A3:34:CE:D9:F6:E3:38:19:6B:62:44'

$spec.location.service.url = 'https://pocappprod.mydomain.com:443/sdk'

$spec.location.service.credential = New-Object VMware.Vim.ServiceLocatorSAMLCredential

$spec.location.service.credential.token = 'https://pocpscprod.mydomain.com/websso/SAML2/Metadata/vsphere.localZt5nOoOBL3u8vjrFYqlB8IlcOnGg9nVwh...'

$spec.location.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (0)

$_this = Get-View -Id 'VirtualMachine-vm-24'

$_this.CloneVM_Task($folder, $name, $spec)

with (.token property stripped down for readability).

The trickiest part appears to be '$spec.location.service' which is an instance of VMware.Vim.ServiceLocator. From the code above, the .credential property is set as an instance of VMware.Vim.ServiceLocatorSAMLCredential, but the VMware.Vim.ServiceLocator document states we can also use VMware.VimServiceLocatorNamePassword. So, taking the Onyx code with a slight modification you get:

New-VICredentialStoreItem -Host pocappprod -User 'mydomain\myusername' -Password '<pass>'

$folder = New-Object VMware.Vim.ManagedObjectReference

$folder.value = 'group-v22'

$folder.type = 'Folder'

$name = 'DeployedVM'

$spec = New-Object VMware.Vim.VirtualMachineCloneSpec

$spec.template = $false

$spec.powerOn = $false

$spec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.location.folder = New-Object VMware.Vim.ManagedObjectReference

$spec.location.folder.value = 'group-v22'

$spec.location.folder.type = 'Folder'

$spec.location.host = New-Object VMware.Vim.ManagedObjectReference

$spec.location.host.value = 'host-28'

$spec.location.host.type = 'HostSystem'

$spec.location.pool = New-Object VMware.Vim.ManagedObjectReference

$spec.location.pool.value = 'resgroup-27'

$spec.location.pool.type = 'ResourcePool'

$spec.location.disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator[] (3)

$spec.location.disk[0] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[0].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[0].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[0].diskBackingInfo.fileName = ''

$spec.location.disk[0].diskBackingInfo.diskMode = ''

$spec.location.disk[0].datastore = New-Object VMware.Vim.ManagedObjectReference

$spec.location.disk[0].datastore.value = 'datastore-29'

$spec.location.disk[0].datastore.type = 'Datastore'

$spec.location.disk[0].diskId = 2000

$spec.location.disk[1] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[1].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[1].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[1].diskBackingInfo.fileName = ''

$spec.location.disk[1].diskBackingInfo.diskMode = ''

$spec.location.disk[1].diskId = 2001

$spec.location.disk[2] = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator

$spec.location.disk[2].diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$spec.location.disk[2].diskBackingInfo.thinProvisioned = $true

$spec.location.disk[2].diskBackingInfo.fileName = ''

$spec.location.disk[2].diskBackingInfo.diskMode = ''

$spec.location.disk[2].diskId = 2002

$spec.location.service = New-Object VMware.Vim.ServiceLocator

$spec.location.service.instanceUuid = '6d6939a7-6c28-4bdf-8f56-479e7e96a55a'

$spec.location.service.sslThumbprint = 'F4:1C:AC:B8:CE:8E:DF:22:A8:A3:34:CE:D9:F6:E3:38:19:6B:62:44'

$spec.location.service.url = 'https://pocappprod.mydomain.com:443/sdk'

$spec.location.service.credential = New-Object VMware.Vim.ServiceLocatorNamePassword

$spec.location.service.credential.username = (Get-VICredentialStoreItem -Host 'pocappprod').user

$spec.location.service.credential.password = (Get-VICredentialStoreItem -Host 'pocappprod').password

$spec.location.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (0)

$_this = Get-View -Id 'VirtualMachine-vm-24'

$_this.CloneVM_Task($folder, $name, $spec)

but this throws the error:

Exception calling "CloneVM_Task" with "3" argument(s): "

Required property datastore is missing from data object of type VirtualMachineRelocateSpecDiskLocator

while parsing serialized DataObject of type vim.vm.RelocateSpec.DiskLocator

at line 1, column 1080

while parsing property "disk" of static type ArrayOfVirtualMachineRelocateSpecDiskLocator

while parsing serialized DataObject of type vim.vm.RelocateSpec

at line 1, column 361

while parsing property "location" of static type VirtualMachineRelocateSpec

while parsing serialized DataObject of type vim.vm.CloneSpec

at line 1, column 355

while parsing call information for method CloneVM_Task

at line 1, column 218

while parsing SOAP body

at line 1, column 207

while parsing SOAP envelope

at line 1, column 38

while parsing HTTP request for method clone

on object of type vim.VirtualMachine

at line 1, column 0"

At line:1 char:1

+ $_this.CloneVM_Task($folder, $name, $spec)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

Looking closer, the .datastore property is missing for $spec.location.disk[1] and $spec.location.disk[2]. Replicating $spec.location.disk[0] for these additional disks (with [1] and [2] of course), the code submits without error and spits back a Task object. Unfortunately I get but in the Web Client we get 'A specified parameter was not correct: spec.location.datastore'.

Somewhat stuck now. I think I might have to resort to just moving the template between vCenter servers before cloning, unless lamw‌ can identify the problem!

For the record, i'm using VMware vSphere PowerCLI 6.0 Release 3 build 3205540.

Reply
0 Kudos
sastre
Enthusiast
Enthusiast

For completeness, vpxd.log contains:

[Originator@6876 sub=Default opID=1d3e062f-a4] [VpxLRO] -- ERROR task-internal-89906 --  -- VmprovWorkflow: vmodl.fault.InvalidArgument:

--> Result:

--> (vmodl.fault.InvalidArgument) {

-->    faultCause = (vmodl.MethodFault) null,

-->    invalidProperty = "spec.location.datastore",

-->    msg = ""

--> }

--> Args:

-->

[Originator@6876 sub=Default opID=1d3e062f] [VpxLRO] -- ERROR task-91 -- vm-24 -- vim.VirtualMachine.clone: vmodl.fault.InvalidArgument:

--> Result:

--> (vmodl.fault.InvalidArgument) {

-->    faultCause = (vmodl.MethodFault) null,

-->    invalidProperty = "spec.location.datastore",

-->    msg = ""

--> }

--> Args:

-->

--> Arg folder:

--> 'vim.Folder:group-v22'

--> Arg name:

--> "DeployedVM"

--> Arg spec:

--> (vim.vm.CloneSpec) {

-->    location = (vim.vm.RelocateSpec) {

-->       service = (vim.ServiceLocator) {

-->          instanceUuid = "6d6939a7-6c28-4bdf-8f56-479e7e96a55a",

-->          url = "https://pocappprod.mydomain.com:443/sdk",

-->          credential = (vim.ServiceLocator.NamePassword) {

-->             username = "mydomain\myusername",

-->             password = (not shown)

-->          },

-->          sslThumbprint = "F4:1C:AC:B8:CE:8E:DF:22:A8:A3:34:CE:D9:F6:E3:38:19:6B:62:44"

-->       },

-->       folder = 'vim.Folder:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:group-v22',

-->       datastore = <unset>,

-->       diskMoveType = <unset>,

-->       pool = 'vim.ResourcePool:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:resgroup-27',

-->       host = 'vim.HostSystem:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:host-28',

-->       disk = (vim.vm.RelocateSpec.DiskLocator) [

-->          (vim.vm.RelocateSpec.DiskLocator) {

-->             diskId = 2000,

-->             datastore = 'vim.Datastore:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:datastore-29',

-->             diskMoveType = <unset>,

-->             diskBackingInfo = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) {

-->                fileName = "",

-->                datastore = <unset>,

-->                backingObjectId = <unset>,

-->                diskMode = "",

-->                split = <unset>,

-->                writeThrough = <unset>,

-->                thinProvisioned = true,

-->                eagerlyScrub = <unset>,

-->                uuid = <unset>,

-->                contentId = <unset>,

-->                changeId = <unset>,

-->                parent = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) null,

-->                deltaDiskFormat = <unset>,

-->                digestEnabled = <unset>,

-->                deltaGrainSize = <unset>,

-->                deltaDiskFormatVariant = <unset>,

-->                sharing = <unset>

-->             },

-->          },

-->          (vim.vm.RelocateSpec.DiskLocator) {

-->             diskId = 2001,

-->             datastore = 'vim.Datastore:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:datastore-29',

-->             diskMoveType = <unset>,

-->             diskBackingInfo = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) {

-->                fileName = "",

-->                datastore = <unset>,

-->                backingObjectId = <unset>,

-->                diskMode = "",

-->                split = <unset>,

-->                writeThrough = <unset>,

-->                thinProvisioned = true,

-->                eagerlyScrub = <unset>,

-->                uuid = <unset>,

-->                contentId = <unset>,

-->                changeId = <unset>,

-->                parent = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) null,

-->                deltaDiskFormat = <unset>,

-->                digestEnabled = <unset>,

-->                deltaGrainSize = <unset>,

-->                deltaDiskFormatVariant = <unset>,

-->                sharing = <unset>

-->             },

-->          },

-->          (vim.vm.RelocateSpec.DiskLocator) {

-->             diskId = 2002,

-->             datastore = 'vim.Datastore:6d6939a7-6c28-4bdf-8f56-479e7e96a55a:datastore-29',

-->             diskMoveType = <unset>,

-->             diskBackingInfo = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) {

-->                fileName = "",

-->                datastore = <unset>,

-->                backingObjectId = <unset>,

-->                diskMode = "",

-->                split = <unset>,

-->                writeThrough = <unset>,

-->                thinProvisioned = true,

-->                eagerlyScrub = <unset>,

-->                uuid = <unset>,

-->                contentId = <unset>,

-->                changeId = <unset>,

-->                parent = (vim.vm.device.VirtualDisk.FlatVer2BackingInfo) null,

-->                deltaDiskFormat = <unset>,

-->                digestEnabled = <unset>,

-->                deltaGrainSize = <unset>,

-->                deltaDiskFormatVariant = <unset>,

-->                sharing = <unset>

-->             },

-->          }

-->       ],

-->       transform = <unset>,

-->    },

-->    template = false,

-->    config = (vim.vm.ConfigSpec) null,

-->    customization = (vim.vm.customization.Specification) null,

-->    powerOn = false,

-->    snapshot = <unset>,

-->    memory = <unset>

--> }

Reply
0 Kudos
LucD
Leadership
Leadership

Did you already try it as William did in his .ps1 script (lines 148-156) ?

See my earlier answer for a link to the post


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

GrantBrunton
Enthusiast
Enthusiast

I have a similar problem as detailed here:

Need help updating script to work with new vSphere 6 environment

I've managed to get the clone to work from one vCenter to another now and it did require adding in the ServiceLocation spec as LucD indicated in his previous post.

The final code I am currently using to clone a server from vc01 to vc02 within the same SSO domain is below.

# Virtual Centre server parameters

$aryVIServer = @("vc01.domain.com", "vc02.domain.com")

$strDestVC = "vc02"

$strDestVCThumbprint = "11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11"

$strVCUsername

$strVCPassword

# Load VMware environment

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null

$VIServer = Connect-VIServer $aryVIServer

# Server cluster group to deploy to

$strVMCluster = "DestCluster"

# Datastore for storage

$strDatastore = "DestCluster-VMFS1"

# Destination Folder

$strFolder = "Folder1"

# Define source server to clone from

$CloneServer = "Server1"

# Define name of new server including environment prefix

$vmName = "$($CloneServer)-Clone"

# Select Host with least memory consumption

$selectedHostObj = Get-VMHost -Location $strVMCluster | Sort-Object -Property MemoryUsageGB | Select-Object -First 1

# Select folder to place VM guest into

$folderObj = Get-Datacenter -Cluster $strVMCluster | Get-Folder $strFolder

# Select datastore with most available space

$selectedDatastoreObj = Get-DataStore -VMHost $selectedHostObj | Sort-Object -Property FreeSpaceGB -descending | Select-Object -First 1

# Select destination cluster

$selectedClusterObj = Get-Cluster $selectedHostObj.Parent.Name

$ Select source VM to clone

$origVM = Get-VM -Name $CloneServer

$ Create clone spec

$spec = New-Object VMware.Vim.VirtualMachineCloneSpec

# Relocate spec for clone

$spec.Location = New-Object VMware.Vim.VirtualMachineRelocateSpec

$spec.Location.Datastore = $selectedDatastoreObj.Id

$spec.Location.Host = $selectedHostObj.Id

$spec.Location.Pool = $selectedClusterObj.ExtensionData.ResourcePool

$spec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]::sparse

# New Service Locator required for Destination vCenter Server

$service = New-Object VMware.Vim.ServiceLocator

$credential = New-Object VMware.Vim.ServiceLocatorNamePassword

$credential.username = $strVCUsername

$credential.password = $strVCPassword

$service.credential = $credential

$service.instanceUuid = ($VIServer | where { $_.Name -match $strDestVC }).instanceUuid

$service.sslThumbprint = $strDestVCThumbprint

$service.url = (($VIServer | where { $_.Name -match $strDestVC }).ServiceUri) -replace "/sdk",""

$spec.Location.service = $service

# Final settings

$spec.PowerOn = $false

$spec.Template = $false

$newVM = $origVM.ExtensionData.CloneVM($folderObj.ExtensionData.MoRef,$vmName,$spec)

$newVM = Get-VM -Id $newVM

# Configure network adapter to selected network

$newVM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $selectedNetwork -Confirm:$false

Reply
0 Kudos