VMware Cloud Community
jswager1
Contributor
Contributor

Pro grammatically deploying a virtual machine to Data Center A from a template in Data Center B

I've seen several discussions saying that it's not possible to deploy a virtual machine to a particular data center from a template that was stored in a separate data center - even though both data centers were managed by the same Virtual Center. The error most often associated with this failure was "the input arguments had entities that did not belong to the same datacenter"

However, we've been doing this exact thing for some time using Virtual Center 2.5 and ESX 3.5 hosts using the VI Client. One data center (call it A) has our templates hosted on a SAN device. We've got a number of ESX 3.5 hosts in a separate data center (call it B). We routinely deploy from A to B using the VI Client. And it doesn't have any errors. It does have some warnings when a deployment is made concerning the networks may not be the same. We work around that by making sure that the networks under both data centers that have the same name are physically attached to the same network, so the warning can be safely ignored.

The problem occurred when we tried to automate this process using the PowerCLI (actually, the .NET interface). When we tried that for the first time, we encountered the "the input arguments had entities that did not belong to the same datacenter" error that everyone else sees. So, how does the VI Client do it? Both VI Client and the PowerCLI interface are using the same SDK at some level. Is there some extra command, some extra parameter that needs to be performed to get this to work?

Tags (2)
0 Kudos
3 Replies
LucD
Leadership
Leadership

Could you perhaps include some code that shows us how you are trying to do this ?


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

0 Kudos
jswager1
Contributor
Contributor

I'm not include ALL the code, but here's a general approach to what I'm doing in C#. Not all lines of code are present - there are gaps:

VimClient Client = new VimClient();

VirtualMachine template = (VirtualMachine)Client.GetView(morTemplate, null);

Folder folder = (Folder)Client.GetView(morFolder, null);

Datastore datastore = (Datastore)Client.GetView(morDatastore, null);

ResourcePool pool = (ResourcePool)Client.GetView(morResourcePool, null);

VirtualMachineCloneSpec clonespec = new VirtualMachineCloneSpec();

clonespec.Location = new VirtualMachineRelocateSpec();

clonespec.Location.Datastore = datastore.MoRef;

clonespec.Location.Pool = pool.MoRef;

clonespec.Template = false;

ManagedObjectReference morVM = template.CloneVM(folder.MoRef, "NewSession", clonespec);

This last line is the one that generates the error. The template if from Data Center B, while the folder, datastore, and resource pool are all in Data Center A.

0 Kudos
jswager1
Contributor
Contributor

Well, this is embarrassing. After I had posted this code snippet, I went back and did some more testing. I found that one of the references - the storage - had some transposed characters in the database. The incorrect value referred to a storage device on the wrong data center. So, all in all, the error message was absolutely correct. After I fixed the data error, the Clone method call worked just like it does when called via the VI Client.

0 Kudos