Happy New Year! 🥳
I wanted kick off 2021 with something I had just learned about right at the end of 2020 which I think this will be useful going into the new year for a number of different use cases. Back in 2017, I wrote about a new and lighter weight version of the vCenter Simulator (vcsim) which had been developed as part of the govmomi (vSphere SDK for Go) project. Since then, the govmomi project has grown exponentially and is now integral to a number of popular open source projects such as Packer builder for vSphere, Terraform provider for vSphere and Kubernetes Cluster API for vSphere (CAPV) to just name a few.
Govmomi is also heavily used internally by VMware for both development and testing purposes. In fact, it has been used to build a number of new VMware features such as the vSphere Integrated Containers (VIC) solution and most recently the vSphere with Tanzu capability that was introduced in vSphere 7.0.
Getting back to vcsim, this has been an invaluable tool for both our VMware developers but also the general VMware community. The ability to "simulate" a mocked vSphere environment with a basic inventory can be extremely useful for learning about the vSphere API and interacting with this endpoint using any vSphere SDK including PowerCLI. For automation folks, this can be useful for designing and creating your scripts in an offline mode before testing it against a real environment. For folks building 3rd party solutions that includes a visual interface, this is an easy way to test out your UI and ensure that there are no issues for large vSphere inventories which can be difficult to validate in a development environment.
Simulating a fake vSphere inventory is great, but it also has its limitations. There are so many unrealized use cases if you could capture a real vSphere inventory and then replay that back using vcsim. Just think about a bug reproduction use case and being able to share a real vSphere inventory with a development or QA team without needing to provide them direct access to the production environment?
In my opinion, this was the missing key feature from the original vcsim. To my surprise, this functionality was actually added to govc/vcsim earlier last year and I was quite happy with its implementation! Let's now take a closer look at how the record and replay functionality of govc/vcsim works.
Step 1 - Install golang on your system
Step 2 - You need to define the GOPATH environmental variable which tells go where your go workspace will be. In my example, I created a directory called gocode under my username and then then ran the following command to export:
Note: To ensure that the GOPATH is always defined, you can add this to your shell (Bash/Zsh) configuration
Step 3 - Run the following two commands which will download the latest source code and build both the govc and vcsim binaries.
go get github.com/vmware/govmomi/govc
go get github.com/vmware/govmomi/vcsim
If the command was successful, you can now access govc and vcsim using the respective paths $GOPATH/bin/govc and $GOPATH/bin/vcsim
Note: To ensure that you do not have to specify the full go bin path, you can add $GOPATH/bin to your $PATH variable
Record vSphere Inventory
Now that both govc and vcsim has been setup, we are ready to capture and save our vSphere inventory.
Step 1 - We first need to define the following environmental variables which will be used by govc to authenticate into our vSphere environment. These variables is also required for general govc usage and is not specific to recording your vSphere inventory.
export GOVC_USERNAME=*protected email*
Step 2 - To capture and save our vSphere inventory, just run the following command:
If the operation was successful, you should see a message like the one above detailing the name of the directory that contains your recording along with high level summary of the vSphere inventory objects that have been saved.
Note: By default, the directory name is vcsim-[vcenter-hostname]. If you wish to change that to a different name, simply use the -d option and the name you wish to use (e.g. $GOPATH/bin/govc object.save -d my-saved-inventory)
Replay vSphere Inventory
Once our vSphere inventory recording has been saved, we can now replay it using the vcsim utility.
Step 1 - Run the following command and specify the directory of your vSphere inventory recording:
$GOPATH/bin/vcsim -load vcsim-vcenter.sddc-35-167-62-16.vmwarevmc.com
Once started, vcsim will load our recorded vSphere inventory and will listen on localhost and port 8989 by default.
Step 2 - At this point, we now interact with vcsim and our recorded vSphere inventory using ANY vSphere SDK including govc but also tools like PowerCLI. There are no credentials for vcsim, so you can pass in any value like the example shown below:
Connect-VIServer -Server localhost -Port 8989 -User Foo -Password Bar
After successfully connecting to vcsim, I can now run any PowerCLI command like the Get-VirtualNetwork cmdlet and it will return information from my recorded session.
Community vSphere Inventory Recordings
Given how useful this record/replay feature is and the fact that you can easily share a recording with another user gave me an idea. What if we had a place where other folks in the VMware community could contribute and share their own vSphere Inventory? Imagine if we had different 3rd party solutions that have been deployed to vSphere or maybe a particular configuration such as VMware Cloud Foundation or VMware Cloud on Dell EMC, Azure VMware Solution, etc. The possibilities and use cases are endless!
With that, I have created a new Github repo called govc-recordings where I have already submitted two of my own setups, my personal homelab which was recently rebuilt with vSphere 7.0 Update 1c and a VMware Cloud on AWS 1.13 environment. If you are interested in contributing your own vSphere environment, please take a look at the Github repository and follow the instructions to create a pull request.
If you have any feedback or feature requests for govc/vcsim, be sure to file a Github Issue in the Govmomi repo, both Doug and other VMware developers are very active and working on the improving the project.
Chris Noon says
Fantastic! I sincerely hope an NSX version is developed. As a customer facing architect, I would find it incredibly useful.
There is any way to connect VMware Orchestrator to vcsim?