VMware Cloud Community
Pyrochaser
Contributor
Contributor
Jump to solution

Multiple vCenter Cloning from vCenter to vCenter

I hope I can articulate this question well, so please forgive me if I am unable to fully explain the scenario, but here goes:

We originally had a single vCenter Server (Physical Mahcine) with two datacenters visible in it, one in NJ and one in SC. We decided to make two new virtual vCenters One with a Datacenter called NJ and one with a Datacenter called SC. In our old vcenter we had an automated Power CLI script that cloned a machine in the SC datacenter, removed the NIC adapter, converted it to template, and then cloned it to the NJ datacenter side across the WAN. The script looked a bit like this:

######################

Connect-VIServer vCenter

######################

$Temp = Get-Template -Name "SERVER_CLONE_TODAYSDATE" <---This exists in the SC Datacenter

$VMHOSTNJ = "hostname1-1.domainname.com

######################

New-Template -Template $(get-template $Temp) -Name "SERVER_CLONE_TODAYSDATE" -Location NJ -VMHost $VMHOSTNJ -Datastore NJ_DS_04 -DiskStorageFormat Thin -Confirm:$false

So in the past when this script would run being on a single vcenter which managed both Datacenters, it would clone the Template up to the NJ Datacenter at the root folder. Now with the new set up being a vCenter in NJ and a vCenter in SC working in linked mode I can not get the script to deploy the Template across the WAN. I get the error:

New-Template : 10/30/2013 11:05:19 AMNew-Template    Arguments must be from the same server.

I have Connect-VIServer njvcenter -AllLinked and Connect-VIServer scvcenter -AllLinked in the script now, but still can not get over this hurdle of cloning the template across the WAN. I have enabled Set-PowerCLIConfiguration -Scope User -DefaultVIServerMode Multiple.

Is there a way in any act of scripting brilliance someone can provide that might allow for me to continue with this automated process again across these two linked vcenters?

I have tried settings few variables like:

$VMHOSTNJ = Get-VMHost "hostname.domainname.com" -server njvcenter

$NJDATASTORE = Get-Datastore NJ_DS_05 -Server njvcenter

$NJFOLDER = Get-Folder "~SC to NJ Cloning" -Server njvcenter

And then placed them in my script in an effort for the script to run the clone from the scvcenter but know to look to the njvcenter for the -Location -Datastore -VMHost

If this is confusing I apologize, if you have questions ask away, we really want to get to a two vcenter environment for fail-over purposes, however the script reduces the time by more then an hour on what would take almost 4 hours to complete manually. Any help would be greatly appreciated!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you don't have shared storage between the vCenters, take note of KB2013516


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

One possibility could be to export the VM on one vCenter as an OVA file, transfer that file to the other center, and there import the OVA file.

At that point you can "move" the VM out of the vApp, and create your template

You can create such an OVA something like this

$vm = Get-VM -Name VM
$vapp = New-VApp -Name TempApp -Location (Get-Cluster -Name Cluster)
Move-VM -VM $vm -Destination $vapp

Export-VApp -Destination C:\Folder -VApp TempApp -Force


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

Pyrochaser
Contributor
Contributor
Jump to solution

LucD,

I appreciate the fact you are always so helpful with scripting :smileyplus:. I have thought about this option, however is it possible to copy the OVA without having to use local storage on my PC? Can the Export-VApp -Destination point to a network UNC path or a Datastore for that matter?

Curious though it be, why did it work when all hosts on all datacenters were in the same vcenter yet now when there are two in linked mode they "appear" to not want to talk with one another like they used to? Sorry if my questions appear clueless, going to be honest I have no CLI background, what I have used I have learned in passing or looking at various script sources and poking and prodding until I got the results I needed.

Another question is this, if I was in a vcenter interface I could manually clone this from one datacenter to another, shouldn't those manual "Mouse click" processes translate into some sort of CLI script language? I mean vcenter is really nothing more then an advanced GUI that runs processes and tasks (command lines) in the background is it not?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you can use an UNC path on the Destination parameter.

Get-VApp -Name TempApp |
Export-VApp -Destination "\\server\share\temp.ova" -Force -Format ova

Some of the PowerCLI cmdlets have restrictions builtin to avoid errors or impossible actions.

For downward compatibility it is not easy to add new vSphere features to such cmdlets.

The functionality you are looking for is available in the API directly, but the functionality hasn't been exposed through a cmdlet (yet).

The Export-VApp cmdlet is just a handy bypass to avoid having to use the API.


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

Pyrochaser
Contributor
Contributor
Jump to solution

After reviewing our environment I noticed that our new vcenters in linked mode don't have a vMotion switch in place like our single vcenter environment used to. I reached out to our VMWare Engineer and am hopeful that if this switch can be added (not sure if it will work in linked mode or not) we may be able to fine tune the old scripts and continue with business as usual. We shall see. Thanks again for all your help! I will look into the OVA options as well. Appreciate the input.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you don't have shared storage between the vCenters, take note of KB2013516


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

0 Kudos