Scaling Your Tests: How to Set Up a vCenter Server Simulator

I’ve recently been testing a handful of reporting tools against vCenter Server endpoints. I have several lab instances for various major releases, which allow me to test a wide range of configurations. However, there are some tests that are hard to simulate, like what if a cluster has 100 hosts, or one host has 200 VMs?

Years ago I remember stumbling on a vCenter Server simulator. I didn’t have a specific need for it at the time but with this recent testing I checked, and the tool still exists and is actively maintained here: https://github.com/vmware/govmomi/blob/main/vcsim/README.md. There is even a container image available. This article will show how to create a single VM that can help simulate many vCenter Servers for our various reporting requirements.

Server setup

I started with an Ubuntu 24.04 virtual machine (deployed from a template previously created with Packer, as described in this previous post). I then installed docker compose and make a few configuration changes to make docker a bit easier to work with.

# install docker compose, add our active directory user & root to the docker group
sudo apt install docker-compose-v2
sudo usermod -aG docker ${USER}
sudo usermod -aG docker root
# Log off/on for new group membership to become effective

# create a folder for some of our configs, make the docker group owner of that folder
sudo mkdir /data
sudo chgrp docker /data
sudo chmod g+srw -R /data 

# configure docker to not overlap network ranges and make ranges smaller than default
echo '{"default-address-pools":[{"base":"172.17.0.0/16","size":26}]}' | sudo tee --append /etc/docker/daemon.json
sudo systemctl restart docker

# create a folder for our simulator 
mkdir vcsim
cd vcsim

Sample vCenter Inventories

William Lam maintains a github repo with recordings of some lab inventories, available here: https://github.com/lamw/govc-recordings. I downloaded this repo and extracted the contents to /data/vcsim/sims, which provides 5 different lab environments from about 4 years ago.

This repo also contains instructions on how to save an existing inventory for use in the simulator. Getting ready to do some maintenance or decommission an environment? Might as well save that point in time snapshot of the inventory we can report against later.

Docker compose.yml

Looking at this file, you’ll see 3 instances of the vcsim container running. There are two generic inventories, controlled by parameters passed to command for things like number of hosts per cluster, port groups, and listening port. The third vCenter inventory is one of the saved inventories from the govc-recordings repo. I’m running multiple saved inventories, but in the interest of saving space have only included one sample below. Each vcsim container will get a container IP and listen on port 8989. In this example, nginx is handling all of the traffic coming in — we reference a reverse_proxy.conf file as well as a certificate folder. Those will be discussed later.

In the /data/vcsim/ folder, compose.yml has the following contents:

version: '2'
services:
  # This nginx web server will terminate at a wildcard SSL certificate, then use the first label
  # of the DNS entry to send requests to port 8989 on the associated container, for example:
  # https://small.vcsim.example.com:443 --> https://small:8989
  nginx:
    image: nginx:latest
    volumes:
      - /data/vcsim/reverse_proxy.conf:/etc/nginx/conf.d/default.conf
      - /data/vcsim/cert:/etc/nginx/certs
    ports:
      - "443:443"

  # Here are a few simulated VCs with progressively larger inventories
  small:
    image: vmware/vcsim:latest
    command: -api-version "8.0.3" -cluster 1 -dc 1 -folder 5 -host 8 -standalone-host 0 -l "0.0.0.0:8989" -vm 20
    restart: unless-stopped
  medium:
    image: vmware/vcsim:latest
    command: -api-version "8.0.3" -cluster 2 -dc 2 -folder 5 -host 16 -standalone-host 0 -l "0.0.0.0:8989" -vm 100
    restart: unless-stopped

  # The following examples are from a github repo
  wlam7:
    image: vmware/vcsim
    command: -load /simdata -l "0.0.0.0:8989"
    restart: unless-stopped
    volumes:
      - /data/vcsim/sims/vcsim-vcsa.primp-industries.local:/simdata

nginx reverse_proxy.conf

This nginx configuration will extract the subdomain from the request, for example the word small from small.vcsim.example.com and store it in a $sub variable. We will then proxy the request for each subdomain to the appropriate container, for example https://small.vcsim.example.com:443/ to the individual container of https://small:8989/. In DNS we only need to create a single cname record for *.vcsim.example.com that points to our container host. Any container that gets created will automatically be available via our wildcard subdomain.

I’ve not included the certificate files, but as you can see from the compose.yml and reverse_proxy.conf files, there is a directory at /data/vcsim/cert containing a PEM formatted certificate and private key named wildcard-vcsim-example-com.pem and wildcard-vcsim-example-com.key. This allows all our requests (from PowerCLI or the like) to have a valid certificate, while we only need to maintain a single certificate file.

server {
   # Listen for any HTTPS request
   listen 443 ssl;

   # Extract the subdomain name from 'SUB.vcsim.example.com'
   server_name ~^(?<sub>[^.]+)\.vcsim\.example\.com$;

   # Define the path to the certificate and key
   ssl_certificate /etc/nginx/certs/wildcard-vcsim-example-com.pem;
   ssl_certificate_key /etc/nginx/certs/wildcard-vcsim-example-com.key;

   # For any request, proxy to the container name on port 8989
   location / {
        resolver 127.0.0.11 valid=1s;
        proxy_pass https://$sub:8989;
   }
}

Bring Up

With our compose.yml, reverse_proxy.conf, certificate files, and simulated inventories in place, we are ready to startup the service. To this we only need to run a single command:

docker compose up -d

When the system restarts, these containers will restart automatically. If we want to check stats or logs, we can do so with the following:

docker stats
docker compose logs

When running the docker compose commands we need to be in the /data/vcsim/ folder, or specify that folder via arguments.

Conclusion

Using the above steps, I have a single lab VM with ~10 vCenter inventories… using less than 2GB of RAM and 2vCPU. There are of course some caveats, like no UI and some methods that don’t exist in the simulator, but for many test scenarios when you just need the SOAP API this works great.

This entry was posted in Lab Infrastructure, Virtualization. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.