Yesterday I bumped into a semi-draft of code I wrote a while back and that I have never checked in into GitHub.
I spent a few hours to polish it, augmenting it with some Docker related stuff (so that it becomes “cool”) and test it a bit. The result is in this repo.
The idea behind this script was to confine a given set of workloads inside a dedicated Virtual Data Center.
Background: one of the latest capabilities of vCloud Director is to allow tenants to deploy Virtual Data Centers from VDC templates the cloud admin defines. vCloud Air OnDemand leverages this capability when you create a new VDC in a given instance of your choice.
While I have tested this sample script with vCloud Air, in theory this should also work when you point the script against a standalone vCloud Director instance with this capability enabled and properly configured (be it on-prem or in a public cloud operated by a VMware vCloud Air Network partner). However, mind I have not tested these two additional scenarios.
If you decide to test them note you will need to tweak the way login steps currently work. The version on GitHub is configured to point to vCA as a backend. If you intend to use a vCD standalone instance the login is going to be different [feel free to reach out if in doubt].
The sample code on GitHub creates a new VDC in the vCA instance of your choice and configures some network plumbing. Eventually, the code grabs an OVA file off the Internet (an image of Photon OS TP2) and deploys it in the newly created VDC. In the end, the script configures some NAT rules to allow you to SSH into the VM that has just been deployed.
For a more detailed list of things that the script does please check out the README on GitHub. The same page lists all pre-requisites you need to have in place to run the code.
In order to try to cover more broadly potential use cases I am also showing, in the code, how to inject a shell script (dockerstart.sh) into the VM before powering it on.
In my case I am just running a simple command to start the docker daemon on Photon OS guest. Consider it just a place holder for commands you may want to pass into a VM at deployment time.
For your convenience, below is the current content of the code as on GitHub: