Update: We've added homebrew and debian packages for
govc for your installation pleasure. See last section for instructions.
Every once in a while I run across an amazing tool which should be shared with others, we all deserve nice things.
For the last few years I've been using the AWS CLI to reboot vms, find ip addresses used within a vpc and looking up vm instance types. I recently had to switch to vSphere and wanted a similar experience.
VMWare has created a CLI for interacting with vSphere called govc. I've enjoyed using it and hope you will too!
Why I like
- The tool is written in
goand is compiled for Linux, FreeBSD, OSX & Windows. Download the most recent releases here.
- It is very simple to use. Download, set a couple environment variables and start poking around:
export GOVC_URL="https://lab1.starkandwayne.com" export GOVC_USERNAME='bruce' export GOVC_PASSWORD='tony'
GOVC_URL is the vCenter url, if you get an
x509 certificate error also add
Now you can quickly list the datacenters
This will output the list of vCenter clusters similar to:
/CF1 /CF2 /Kubo
You list the vms for a datacenter by executing:
govc ls /CF1/vm/*
/CF1/vm/jumpbox1 /CF1/vm/jumpbox2 /CF1/vm/bosh-pr /CF1/vm/shield-pr-lab
Once connected you can use the CLI to upload large ISOs which may otherwise timeout during their upload. For instance the command below will upload an ubuntu ISO from your local filesystem to a vSphere datastore called
govc datastore.upload -dc=CF1 -ds DataStore1 / ./ubuntu-18.04-live-server-amd64.iso ubuntu-18.04-live-server-amd64.iso
Helpful hint: if you do uploads from a vm created on the vSphere cluster they can be much faster than attempting from your laptop.
There are a ton of other examples with the existing
help documented here: https://github.com/vmware/govmomi/blob/master/govc/USAGE.md which gives examples for:
- Listing vm information, including ip and CPU
- Creating/updating/deleting vms, clusters, datastores
- Host switch, storage, power settings
- Copying/moving/deleting files in datastores
- Much more... Go look and enjoy
We like using Homebrew for installing software on MacOS and Debian packages for installing software on Ubuntu/Debian servers. To make life easier for me and you, we've made
govc available on both packaging systems.
These packages will automatically update with new versions whenever VMWare cut new releases.
brew install starkandwayne/cf/govc
wget -q -O - https://raw.githubusercontent.com/starkandwayne/homebrew-cf/master/public.key | apt-key add - echo "deb http://apt.starkandwayne.com stable main" | tee /etc/apt/sources.list.d/starkandwayne.list apt-get update apt-get install govc
If you're interested in how we update our Homebrew and Debian packages using Concourse CI, our repo is at https://github.com/starkandwayne/homebrew-cf.