VMware Cloud Community
Amadeus1756
Contributor
Contributor
Jump to solution

Details of snapshots on templates

I can't find a way of finding out about the hard disks associated with a snapshot of a template.

I can do it with a VM easily enough.  I have tried using Get-Template, Get-Snapshot and Get-HardDisk but to no avail.

Could someone post some code showing how it's done?

Many thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this, that should give you details about template snapshots.

&{foreach($template in Get-Template){
    if($template.ExtensionData.LayoutEx.Snapshot){
      $fileTab = @{}
      $template.ExtensionData.LayoutEx.File | %{
        $fileTab.Add($_.Key,$_)
      }
      $hdTab = @{}
      $template.ExtensionData.Config.Hardware.Device |
      where {$_ -is [VMware.Vim.VirtualDisk]} | %{         $hdTab.Add($_.Key,$_.DeviceInfo.Label)       }       $template.ExtensionData.LayoutEx.Snapshot | %{         $snap = Get-View $_.Key
       
foreach($hd in $_.Disk){           $hd.Chain | %{             $_.FileKey | Select @{N="Template";E={$template.Name}},
            @{N="Snapshot";E={$snap.Config.Annotation}},
            @{N="Size";E={$fileTab[$_].Size}},
           
@{N="Harddisk";E={$hdTab[$hd.Key]}},
            @{N="Path";E={$fileTab[$_].Name}}           }         }       }     }   }} | ft -AutoSize


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

View solution in original post

0 Kudos
9 Replies
CRad14
Hot Shot
Hot Shot
Jump to solution

Hmm I am confused. I don't think templates can have snapshots. Atleast for my templates I don't have the option to create snapshots, and I can't create a template from a vm that has a snapshot...

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
0 Kudos
Amadeus1756
Contributor
Contributor
Jump to solution

Hi Conrad,

Thanks for the input.  Let me explain.

To create a template, I will create a VM, make sure it works, then convert to a template.  If there are snapshots associated with the VM, these will exist (and be required) for the template.  It is these snapshots I want to identify.

Rgds

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this, that should give you details about template snapshots.

&{foreach($template in Get-Template){
    if($template.ExtensionData.LayoutEx.Snapshot){
      $fileTab = @{}
      $template.ExtensionData.LayoutEx.File | %{
        $fileTab.Add($_.Key,$_)
      }
      $hdTab = @{}
      $template.ExtensionData.Config.Hardware.Device |
      where {$_ -is [VMware.Vim.VirtualDisk]} | %{         $hdTab.Add($_.Key,$_.DeviceInfo.Label)       }       $template.ExtensionData.LayoutEx.Snapshot | %{         $snap = Get-View $_.Key
       
foreach($hd in $_.Disk){           $hd.Chain | %{             $_.FileKey | Select @{N="Template";E={$template.Name}},
            @{N="Snapshot";E={$snap.Config.Annotation}},
            @{N="Size";E={$fileTab[$_].Size}},
           
@{N="Harddisk";E={$hdTab[$hd.Key]}},
            @{N="Path";E={$fileTab[$_].Name}}           }         }       }     }   }} | ft -AutoSize


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

0 Kudos
CRad14
Hot Shot
Hot Shot
Jump to solution

Luc,

I can't find the reference for those underlying api's that are in extensiondata...what is the link for that?

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In this case it is the VirtualMachine object.


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

Amadeus1756
Contributor
Contributor
Jump to solution

As always, thanks very much Luc - that seems to give the information that I'm looking for.  There is more to it than I expected (propably more than I need) but I'll work out what it's all doing and come back if I have any further questions.

Many thanks

0 Kudos
Amadeus1756
Contributor
Contributor
Jump to solution

I've looked at what this script outputs and have identified what I think is a problem but I've yet to understand what's going wrong.

When I run it, I get a load of output, but the bit I'm interested in is:

Template                                     Snapshot        Size Harddisk    Path
--------                                     --------        ---- --------    ----
Win7x64Templ                                                  525 Hard disk 1 [VMFS-VB-S08] Win7x64Templ/Win7x64Templ.vmdk
Win7x64Templ                                          20006830080 Hard disk 1 [VMFS-VB-S08] Win7x64Templ/Win7x64Templ-flat.vmdk

If I browse my datastore and look in the folder Win7x64Templ, I have 2 VMDK files:

Win7x64Templ.vmdk - 19,537,920.00KB

Win7x74Templ-000001.vmdk - 8,192.00KB

So the issues are the size shown (of lesser importance to me right now), but the name of the file which doesn't actually seem to exist

Win7x64Templ.jpg

Before I spend ages going through the script in detail, is there anything obvious that I'm not aware of (e.g. some kind of name mapping that is done behind the scenes which is being shown by your script)?  if there is nothing obvious that springs to mind, I'll gladly investigate in detail.

As an aside, I'm not actually convinced it's picked up all templates with snapshots, but that's a little more time-consuming to confirm (I have a lot) - I'll do that over the next few days when I get a minute.

rgds

0 Kudos
Amadeus1756
Contributor
Contributor
Jump to solution

Actually, don't bother spending time answering my question - I think I can see the data that I need ($template.ExtensionData.LayoutEx.File - all of type diskExtent), tho I don't understand how your script has provided different information - I'll look further into that, but I think I can get the relevent data in the mean time.

thanks again

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just for info, the .vmdk files that you see in the Datastore browser are a logical representation of the virtualdisk.

In fact there are 2 files, the file with the .vmdk type is a header. It contains information about the virtualdisk file.

The file that has -flat in the name is the actual data part of the virtualdisk.

Have a look at my UML diagram your VM, vdisks and snapshots post.

A picture says more than 1K words Smiley Wink


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

0 Kudos