VMware Cloud Community
Pyrochaser
Contributor
Contributor
Jump to solution

Clone a Template across Multiple Datacenters

So here is the scenario:

Within my vcenter there are two datacenters. In one (B)Datacenter we have our development systems and the other (A)Datacenter are our production environments. We often have to take a clone of a (B)VM and clone it over to an (A)VM. We have a method process that we use to move our VMs. I am trying to powerCLI the whole process in order to save on some manual cloning time. Below is our process:

1. Clone a live (B)VM and take it from the  (B)Datacenter under the "DEV" Folder, under that is a subfolder "AppServer" where the vm "DevAPP" exists and clone it from that subfolder to another subfolder also in "AppServer" called  "~DEV (B) to (A) Clone Staging".

2. Once the clone "DevApp_today's date" is completed in the "~DEV (B) to (A) Clone Staging" we remove the network adapter 1 from it and then convert it to a template.

3. Once it is converted to a template with the name "DevApp_today's date" we clone it over from the (B)Datacenter folder "~DEV (B) to (A) Clone Staging" to (A)Datacenter folder "(B) to (A) Clone Staging".

4. Once the Template "DevApp_today's date" is in the (A) Datacenter we convert it back to a VM and and add the network adapter back to it, set it to the appropriate VLAN and then enable connected at power on.

5. Once the Network Adpater is back on the VM we then convert it back to a Template and deploy 11 VMs from it with customization files to configure the VM.

For the most part steps 1 and 2 I can script fairly easily, as well as 4 and 5, my biggest problem is the step 3. What I have been trying is using the New-Template command.

Example: New-Template -Template "DevApp_today's date" -Location A(Datacenter Name) -VMHost $HostA(a host in the A Datacenter) -Datastore $Data(a storage in the A Datacenter) -DiskStorageFormat Thin -RunAsync -Confirm:$false

This works to get the Template from (B)Datacenter to (A)Datacenter but it drops it in the root of the (A)Datacenter. I know this is because in -Location I put "A" there however I don't know anyway to break it down from there to drill down to the subfolders of (A)Datacenter. If I put the subfolder (A) "(B) to (A) Clone Staging" it just makes a stink about how I already have a Template by that name and it must be cloned across the same datacenter. In the meantime once it reaches the root of (A) I just run a Move-Inventory on the Template to move it to "(B) to (A) Clone Staging".

I don't necessarily need a whole script created for me, I just want to know how to move the template from (B) to (A) without it needing to be dropped in Root (A) and then Move-Inventory

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdjones82
Expert
Expert
Jump to solution

Not sure on the quotes or not, but may be necessary

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

0 Kudos
9 Replies
Pyrochaser
Contributor
Contributor
Jump to solution

-Location A(Datacenter Name)

Could it be possible to put this in the -Location A/B to A CloneStaging/  ? Going to hate myself if that's all I needed to do. lol

0 Kudos
markdjones82
Expert
Expert
Jump to solution

Slightly confused on your naming of your folders, but do you actually ahve the name (A) and (B) in your folder names? Just trying to wrap my head around what you are asking

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Pyrochaser
Contributor
Contributor
Jump to solution

Yeah my environment was created before I came on staff so it is a bit confusing. A and B just represent the datacenter. The Datacenter B folder containing the VM is in B/DEV/~DEV B to A Clone Staging/ it is going to the A Datacenter under the folder A/~B to A Clone Staging/

Does this any more sense?

VM is Cloned to the folder in B Datacenter, once complete the NIC adapter is removed, VM is converted to a template, the template is then cloned to the A datacenter to the specified folder marked above. I am just trying to figure out the New-Template command line structure to get it from the B Datacenter into the right folder in A.

0 Kudos
markdjones82
Expert
Expert
Jump to solution

In theory yes you should be able to specify the folder name in -location and it shoudl clone it to there.  I can't actually test it myself though.

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
Pyrochaser
Contributor
Contributor
Jump to solution

That's the command Line I am trying to get from this post. I know it likely can be done, I am just not sure how to approach it syntax wise.

Currently my command line looks like this:

New-Template -Template $(get-template $Temp) -Location A (What goes after this to get it to copy to the folder under A) -VMHost $VMHOST -Datastore SIDEADATA -DiskStorageFormat Thin -RunAsync -Confirm:$false -whatif

I just don't know the appropriate syntax parameters to tell it how to get there is all Smiley Happy

0 Kudos
markdjones82
Expert
Expert
Jump to solution

So, it would should be

new-template -Location (A)Datacenter folder (B) to (A) Clone Staging

(or whatever the folder name is)

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
Pyrochaser
Contributor
Contributor
Jump to solution

Ok so in my case:

New-Template -Location A(Datacenter Name) ~B to A Clone Staging(Folder in the Datacenter)

since there is a "to" in the folder name does it need quotes?

I will give this a try 

0 Kudos
markdjones82
Expert
Expert
Jump to solution

Not sure on the quotes or not, but may be necessary

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
glau1234
Contributor
Contributor
Jump to solution

The -Location params will usually be smart enough to determine the location you need based on the name of the folder and the object type you're attempting the operation.  If it's a VM, it'll use VM folders, if it's a host, it'll use host folders.  Provided your folder names are all unique, you should only have to specify the name of the folder, not the entire tree.  It's for that reason I try to employ folder names that build (I hope this keeps the indentation):

DataCenter

Folder1

Folder2

Folder2.Subfolder1

Folder2.Subfolder1.AnotherSubfolder1

If that fails, the Location param also accepts a VIContainer object.  You can get the correct folder using 'Get-Folder', store that in a variable and then use the variable when you call 'New-Template'.