vAppManagement.pl

Version 4

    Table of Contents

    • Author
    • Description
    • Category
    • Features
    • Requirements
    • Version Support
    • Operations
    • Sample Execution

     

    Author

    William Lam

     

    Description

     

    Motivated by this VMTN thread post:

    Re: Support for vApp snapshots...am I missing it?,  this script allows for general vApp management supporting the following  operations: querying for the VMs within a vApp, powering on a vApp,  powering off a vApp, shutting down a vApp, querying for snapshots for  VMs in the vApp, creating a common snapshot for each VM in the vApp,  committing a common snapshot for each Vm in the vApp and goto (revert)  to a common snapshot for each VM in the vApp.

     

     

    Update: Added vApp Linked Clone feature! (

    Experimental Support )

     

     

    Category

    • Miscellaneous

     

    Features

    • Supports running on both Windows and Linux

     

    Requirements

    • vCenter 4.0
    • vSphere SDK for Perl/vCLI 4.0 Windows or Linux OR vMA 4.0

     

    Version Support

    • Supports ESX(i) 4.0 hosts being managed by vCenter

     

    Operations

    • Query VMs from a vApp
    • Power On a vApp
    • Power Off a vApp
    • Shutdown a vApp
    • Query snapshots from a vApp
    • Create snapshot on a vApp
    • Commit snapshot on a vApp
    • Revert to snapshot on a vApp
    • Create Linked Clone from a vApp ( Experimental Support )

     

    Sample Execution

     

    Query VMs within a vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation query_vms
    vApp: ghettovApp-Build123
            VM: Database-Server
            VM: Application-Server
            VM: Web-Server
            vApp: ghetovApp-Build0000
    

     

     

    Poweron vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation poweron
    Powering on vApp: ghettovApp-Build123
            Sucessfully powered on vApp!
    

     

     

    Poweroff vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation poweroff
    Powering off vApp: ghettovApp-Build123
            Sucessfully powered off vApp!
    

     

     

    Shutdown vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation shutdown
    Shutting down vApp: ghettovApp-Build123
            Sucessfully shutdown on vApp!
    

     

     

    Query snapshots for VMs within a vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation query_snaps
    vApp: ghettovApp-Build123
    Database-Server           checkin-1           checkin-1 for vApp ghetto
    -------------------------------------------------------------------------------
    Application-Server        checkin-1           checkin-1 for vApp ghetto
    -------------------------------------------------------------------------------
    Web-Server                checkin-1           checkin-1 for vApp ghetto
    -------------------------------------------------------------------------------
    
    

     

     

    Create common snapshot for all VMs within a vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation create_snap --snapshotname checkin-2
    Creating snapshot for vApp: ghettovApp-Build123
    Creating snapshot "checkin-2" for "Database-Server" ...
            Sucessfully created snapshot for "Database-Server"!
    
    Creating snapshot "checkin-2" for "Application-Server" ...
            Sucessfully created snapshot for "Application-Server"!
    
    Creating snapshot "checkin-2" for "Web-Server" ...
            Sucessfully created snapshot for "Web-Server"!
    
    

     

     

    Commit common snapshot for all VMs within a vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation commit_snap --snapshotname checkin-3
    Committing snapshot for vApp: ghettovApp-Build123
    Committing snapshot "checkin-3" for "Database-Server" ...
            Sucessfully committed snapshot for "Database-Server"!
    
    Committing snapshot "checkin-3" for "Application-Server" ...
            Sucessfully committed snapshot for "Application-Server"!
    
    Committing snapshot "checkin-3" for "Web-Server" ...
            Sucessfully committed snapshot for "Web-Server"!
    
    

     

     

    Goto common snapshot for all VMs within a vApp

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp ghettovApp-Build123 --operation goto_snap --snapshotname checkin-1
    Reverting snapshot for vApp: ghettovApp-Build123
    Reverting to snapshot "checkin-1" for "Database-Server" ...
            Sucessfully reverted to snapshot for "Database-Server"!
    
    Reverting to snapshot "checkin-1" for "Application-Server" ...
            Sucessfully reverted to snapshot for "Application-Server"!
    
    Reverting to snapshot "checkin-1" for "Web-Server" ...
            Sucessfully reverted to snapshot for "Web-Server"!
    
    

     

     

    Create vApp Linked Clone (Experimental Support)

     

    Motivated by this VMTN

    thread,  as mentioned this is not something that is supported within the vSphere  API natively but with a little logic and know how from the vSphere API,  it's quite possible. This feature is experimental support, just like

    VMware's Experiemtnal Feature Support

     



    Step 1 - You'll need to start off with a powered off vApp (The  supported full clone vApp API from VMware also requires the vApp to be  powered off)

    Step 2 - Create an offline snapshot (This snapshot needs to remain while Linked Clones are linked off of the base vApp)

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp Ghetto-Cloud-App-1 --operation create_snap --snapshotname linked_clone_snapshot_DO_NOT_REMOVE
    



    step1.png

    Step 3 - Create vApp Linked Clone

    • You'll need to specify a new name for the vApp Linked Clone
    • You'll need to specify a datastore in which to store all the new Linked Clone VMs
    • You'll need to specify an offline snapshot which should have been created from the last step

     

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp Ghetto-Cloud-App-1 --operation link_clone --vapp_clone_name Ghetto-Cloud-App-2 --vapp_datastore himalaya-local-storage-2 --snapshotname linked_clone_snapshot_DO_NOT_REMOVE
    



    step2.png

    Step 4 - Power on newly create vApp Linked Clone (do not power on original)

    [vi-admin@scofield skunkworks] $ ./vAppManagement.pl --server reflex.primp-industries.com --vapp Ghetto-Cloud-App-1 --operation poweron 
    



    step3.png

    Also included in the new vApp Linked Clone is an updated "annotation"  field which provides information from which vApp this Linked Clone was  created from and also when in the form of (YYYYMMDD_HHMMSS)

    step4.png



    Notes:

    • Currently snapshots being taken do not capture memory state. If you  could like to change this, edit the script and replace "memory =>  'false'" with "memory => 'true'"
    • All snapshot operations will try to be performed, but if a common  snapshot is not found for one of the VMs within the vApp, an error  message will be displayed and proceed with the remainder VMs in the vApp
    • If you have nested vApps, the inner vApps are ignored. Operations only apply to VMs within the first vApp container
    • You can create multiple vApp Linked Clones from a single base vApp