WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Scripts to Extract vCloud Director Chain Length and Linked Clone Mappings

Scripts to Extract vCloud Director Chain Length and Linked Clone Mappings

04.09.2012 by William Lam // 18 Comments

There were some questions this week about extracting the chain length for a virtual machine as well as figuring out which Linked Clones were mapped to a particular vAppTemplate and/or shadowVM in vCloud Director. If you are not familiar with the concept of a Linked Clone (Fast Provisioning in vCloud Director 1.5 leverages Linked Clones) and their relationship to chain length, there is a very good white paper called VMware vCloud Director 1.5 Performance and Best Practices that goes into detail about Linked Clones and some of the things to be aware of from a performance standpoint.

Depending on how you deploy a new vApp whether that is from a vAppTemplate in your catalog or copying from an existing vApp, the chain length of a Linked Clone tree will grow either breadth wise or length wise.
The chain length can grow much faster when copying from an existing vApp and that can impact the performance of your virtual machines. Below is a diagram between deploying from a vAppTemplate in a catalog (breadth wise) and consecutive copies from an existing vApp (length wise).

vCloud Director limits the chain length to 30 and automatically spins up a full clone (called a shadow VM) when the maximum is hit and all sub-sequent Linked Clones will be based off of this new shadow VM. A shadow VM can also spin up automatically if the current datastore is getting to full capacity or if the VM needs to exists on a different vCenter Server as Linked Clones do not span datastores or different vCenter Servers.

To view the current chain length of a given virtual machine, you will need to login with a System Administrator account and this can be seen using the vCloud UI at the VM level. You can also get the chain length using the vCloud API which is part of the VCloudExtension property called VirtualDisksMaxChainLength and can be viewed by performing a GET operation on a VM.

Note: Though the property has "MaxChainLength" in the name, this property represents the current chain length and it is not configurable, as the system max is 30.

To be able to quickly get a summary of the chain length of all VMs that include vAppTemplates and Shadow VMs, I wrote a vCloud SDK for PHP script called vcloudVMChainLength.php. The script provides a few pieces of information: VM name as shown in vCloud Director, name of the vApp the VM is part of in vCloud Director, whether it is a vAppTemplate, the vCenter Server hosting the VM, the MoRef of the VM and chain length.

Before I provide the sample output, let me give you some background about my lab environment. I have two vAppTemplates called "Application Server" and "Database Server". The "Application Server" is currently residing on a datastore with close to full capacity and I will be deploying 3 new vApps from this vAppTemplate called "App-Test-1", "App-Test-2" and "App-Test-3". I will also be deploying 3 new vApps from "Database Server" but only the first clone will be from the vAppTemplate, the remainder will be a clone of the previous vApp in the workspace.

Here is a diagram of the 9 VMs (2 vAppTemplates, 1 shadow VM and 6 vApps):

Here is the sample output of the environment above:

We can see that during the deployment of the "App-Test-*" vApps, the datastore capacity was low and vCloud Director automatically spun up a shadow VM which is a full copy and created the 3 new Linked Clones off of that image and the chain length is max of 2. With the "DB-Test-*", we started out with deploying from the vAppTemplate, but all subsequent copies was from the previous vApp which grew the chain length to 4. If we continue to copy from the vApp length wise, we will quickly reach the maximum chain length and possibly degrade the performance of the VMs as the deepest node will need to traverse back to the parent to perform it's disk read operations. 

The other question I had was about mapping the Linked Clones back to their parent VMs. This is not something you can really do in vCloud Director nor using the vCloud API. However, with a little bit of creativity and information from vCloud Director, you can leverage the vSphere API to help you get a list of VMs that are linked off of a given VM. I wrote a vSphere SDK for Perl script called vCloudVMLinkedClonesMapping.pl that can help you get this information. 

Note: This was tested in my lab which had a minimal configuration, ensure you do additional validation before making any decisions based on the output.

To use the script, you will need to provide the MoRef ID for a VM that is either a vAppTemplate, shadow VM or just a regular VM which may have Linked Clones. You can get this information by using the script that was shown earlier.

Let's take a look at our "Application-Server" VM which has MoRef ID 677 and see if there are any Linked Clones:

As we expected, there are no Linked Clones as the datastore it is currently residing on is getting to full capacity and a shadow VM was spun up for the new 3 deployments.

Let's take a look at the shadow VM "shadow-App-VM" with MoRef ID 721 which is automatically prefix with "shadow-" of the source VM name:

Just as we expected, we can see that our 3 vApps are linked off of the Shadow VM that we just checked.

Note: The output includes the display name and URN ID of the vApp in vCloud Director so you can easily identify it.

Finally, let's take a look at our "Database-Server" VM which has MoRef ID 675 and we should also see the 3 Linked Clones:

You might ask if it is necessary to keep track of all this information and the answer is yes/no. Though it is good to understand how vApps are being deployed by your consumers and ensure they are efficiently doing so by deploying from a catalog. vCloud Director has built in mechanisms to automatically handle deep chain lengths or low datastore space by deploying additional shadow VMs to ensure users are still able to request new vApps without any impact.

More from my site

  • vCloud Director Report 1.0.0
  • Quick Tip - Using ovftool to connect to vCloud Director behind a 2-Factor Authentication portal
  • Creating your own 3rd Party Content Library for vSphere 6.0 & vCloud Director 5.x
  • How to deploy vSphere 6.0 (VCSA & ESXi) on vCloud Director and vCloud Air?
  • Configuring a "Whitelist" for VM advanced settings in vCloud Director

Categories // Uncategorized Tags // chain, linked clones, php, vcd, vcloud director

Comments

  1. *protectedJason Burrell says

    05/25/2012 at 5:20 pm

    Thanks for the great article, I have been looking for a way to get the "context view" (What use to display this info in Lab Manager) ever sense linked clones were available in vCD. I can't seem to get the vCloudVMLinkedClonesMapping.pl flie to work. I have the moref ID of the VM's but when I run the vCloudVMLinkedCLonesMapping.pl file it returns:

    Can't call method "type" on an undefined value at C:/Program Files/VMware/VMware vSphere CLI/Perl/lib/VMware/VICommon.pm line 1501.

    Any clues on what might be causing this?

    The command I am using: vCloudVMLinkedClonesMapping.pl --server vcenter --username Admi
    nistrator --moref vm-2751

    Reply
    • *protectedWilliam says

      05/25/2012 at 5:26 pm

      Hi Jason,

      What version of vSphere are you using and what version of the vCLI do you have installed? In my example, it's all vSphere 5

      Reply
    • *protectedJason Burrell says

      05/25/2012 at 5:31 pm

      All vSphere 5. vCLI 5.0.0 615831

      Reply
    • *protectedWilliam says

      05/25/2012 at 5:49 pm

      Are you able to get mappings for other VMs in VCD or just this one? Unfortunately the error is a very generic one, so not sure what might be causing the problem

      Reply
    • *protectedJason Burrell says

      05/25/2012 at 5:56 pm

      Yeah when I did searches I also found the error to be generic. It is the same result regardless of the VMs I have tried. I tried three with varying chain lengths 1, 3, 10. It does run for about 3 min before failing. Cloud it be due to the size of the environment? It's not very large, probably a little over 1000 VM's and over 100 vApps.

      Reply
    • *protectedWilliam says

      05/25/2012 at 10:46 pm

      I don't believe it's the size of the inventory, but maybe related to a particular VM that the script is having some issues with checking. Are you able to see any of the chain length info or does it run and then throw the error?

      Reply
    • *protectedJason Burrell says

      05/25/2012 at 10:47 pm

      I am not able to see any of the chain length, it just runs then throws the error.

      Reply
    • *protectedWilliam says

      05/25/2012 at 10:51 pm

      If you're interested, we can quickly setup a webEx and troubleshoot? I'm interested to see what the issue is.

      Reply
    • *protectedJason Burrell says

      05/25/2012 at 11:01 pm

      This comment has been removed by the author.

      Reply
  2. *protectedJason Burrell says

    05/25/2012 at 11:39 pm

    William,

    So with a little more troubleshooting I have found that it does not make it to this line:

    # compare VM to see if we have any mapping to our parent VM
    # which means we have a Linked Clone

    But it does loop through the previous statement and lists a number of VM's.

    Hope that helps narrow it down for you.

    Reply
  3. *protectedJason Burrell says

    05/29/2012 at 4:30 pm

    William,

    I tried this on a second vCloud instance with the same result. The only thing left I have to try is a new client.

    Reply
  4. *protectedJason Burrell says

    05/29/2012 at 10:06 pm

    Thanks William for the fix!

    Changed:
    if($vm_view->{'name'} ne $parentVMName) {

    To This:
    if($vm_view->{'name'} ne $parentVMName && defined($vm_view->{'parent'})) {

    Reply
    • *protectedWilliam says

      05/30/2012 at 4:20 am

      @Jason,

      np, glad I could help resolve the problem.

      I've also pushed the changes to sourceforge.

      Thanks

      Reply
  5. *protectedJason Burrell says

    06/07/2012 at 7:58 pm

    Hey William,

    I just realized I'm having an issue with the vcloudVMChainLength.php script. It only creates a partial list of the vApps in my environment. It doesn't error out but does stop short of listing everything. Feel free to email me if you want to troubleshoot. Do you know of another way to get the moref ID without using this script?

    Reply
    • *protectedWilliam says

      06/11/2012 at 6:07 pm

      @Jason,

      You can also retrieve the MoRef ID from within the VM using the OVF runtime environment. You will need to enable a few things, but take a look at this blog post for the details http://www.virtuallyghetto.com/2012/06/ovf-runtime-environment.html

      Reply
  6. *protectedDarren says

    06/11/2016 at 12:18 pm

    Hi William. And how does one remove a ShadowVM using PowerCLI? I am able to find them with this command: Search-Cloud AdminShadowVm

    But am now unsure how to remove them?

    Thanks in advance

    Reply

Trackbacks

  1. [INFO] vCloud Director Fast Provisioned Catalog Virtual Machines | VMware vCloud Blog - VMware Blogs says:
    08/20/2014 at 5:25 am

    […] does a great job showing the linked clone aspect.  Also William Lam (@lamw) wrote up some nice scripts to find the linked chains.  However, it took me up until now to get my home lab back into a […]

    Reply
  2. vSphere 6.7 Instant Clones – Geek's Blog says:
    05/15/2019 at 2:05 am

    […] is because a new delta disk is created for each new Instant Clone, the SourceVM's disk chain depth can get deep, very quickly and incurring additional latencies due to deep traversals of the […]

    Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025