As part of building, testing (and breaking!) Enterprise Hybrid Cloud, we had the need for reusable, virtual instances of the entire vRealize stack and all the supporting components both beneath it (vCenter, PSC etc) and above it (Avamar and such). So we made extensive use of VMware vCloud Director (vCD) to create templates we could deploy, burn, redeploy whenever we needed to.
It can take quite a bit of time to power up an entire cloud platform after a template deployment, especially when a lot of the virtual machines are nested inside a vCenter instance and there is a nested vSAN datastore on virtual ESXi hosts that are in maintenance mode when the template is deployed.
Enter PowerShell to save us a bucketload of time waiting
Script Properties
- There is a user configurable parameters section up top that you can populate to suit your environment
- Its designed to present a user driven menu so that you can control startup and shutdown of the CMP
- The Avamar Virtual Edition functions rely on you editing the sudoers configuration on the AVE to permit the functions to be called. Up to you if you want to do that or not – this was a lab.
- It could do with a bit of error handling, which I’ve not gotten around to as this was a template, and we knew what would work and what wouldn’t.
- It reaches out to vCD at the start to see if the name of the vAPP is valid and then checks to see if there is a snapshot of the domain controller (so that you can get a snapshot of the domain controller that ~matches the time of the nested snapshots of the stack components.
Functions
The below script has loads of interesting nuggets and functions:
- Function ConnectVIServer ($VIHost, $User, $Password)
- Function DisconnectVIServer ($VIHost)
- Function ConnectvCD
- Function DisconnectvCD
- Function ChangeDRSLevel ($Level)
- Function MoveVMs
- Function EnterMaintenanceMode
- Function ExitMaintenanceMode
- Function StartVMs ($VMs)
- Function ShutdownVM ($VMs)
- Function ShutdownESXiHosts ($hosts_to_shutdown)
- Function PollvCenter
- Function ListDCSnapshot
- Function ValidateDCSnapshot
- Function CreateDCSnapshot
- Function RevertDCSnapshot
- Function ListSnapshots
- Function CreateVMSnapshot
- Function RevertVMSnapshot
- Function DeleteAllNestedSnapshots
- Function anyKey
- Function StopDPA ($VM)
- Function StopAVE ($ave_list)
- Function sleeper_agent ($seconds)
- Function Menu
Script Location
https://github.com/feardamhan/powershell-scripts/blob/master/manage_cmp.ps1
Feel free to use as you see fit, but be sure to test it before you do. No warranty remember!
Shout out to Brian O’Connell over at LifeOfBrianOC my ‘PowerShell buddy’ who contributed some of the functions. Generates an immediate mental image of the below, I’ll let him decide which one of us is the bear 🙂
Leave a Reply