govc is a vSphere CLI built on top of govmomi.
The CLI is designed to be a user friendly CLI alternative to the GUI and well suited for automation tasks. It also acts as a test harness for the govmomi APIs and provides working examples of how to use the APIs.
Lab #0 - Getting Started with GOVC
Lab #1 - Creating a New Datacenter
Lab #2 - Adding ESXi to the Cluster
Lab #3 - Deploy Virtual Machine from ISO Image
Lab #4 - Deploy Virtual Machine from template
Lab #5 - Demonstrating Storage vMotion
Configure a vCenter cluster with vSAN datastore, DVS and DVPGs
Create a Datacenter and connect the underlying ESXi host to vCenter VM
Create a VM and boot stateless ESXi via cdrom/iso
Create VCSA VM
You can find prebuilt govc binaries on the releases page.
Download and install a binary locally like this:
wget https://github.com/vmware/govmomi/releases/download/v0.19.0/govc_linux_amd64.gz
gunzip govc_linux_amd64.gz
mv govc_linux_amd64 govc
cp -rf govc /usr/local/bin/
chmod +x /usr/local/bin/govc
export GOVC_URL='root:password@<IPaddress>'
export GOVC_INSECURE=1
govc ls
/ha-datacenter/vm
/ha-datacenter/vm/CSERACKPAS61
/ha-datacenter/vm/CSELABDNS.local (1)
Say, I have VM in datastore1 and I want to migrate it to "Local" datastore. I can run the below command to perform it:
govc vm.migrate -ds Local PhotonOS
[31-01-19 16:59:43] migrating VirtualMachine:vm-673... OK
govc host.esxcli -host=<IP> network firewall set --enabled false
govc host.esxcli -host=<Ip> system wbem set -e 1
govc host.date.change -host <IP> -server <IP>
govc host.service -host <IP> enable ntpd
govc host.service -host <IP> start ntpd
govc vm.clone -vm=<template-name> -on=true -waitip=false -host=<targethostIP> -ds=<targetdatastore> newVMname
govc vm.clone -vm=windows8Server64Guest-template -on=true -waitip=false -host=XXX.XXX.XXX.XXX -ds=ESX67 windows8Server64Guest
govc datastore.mkdir -ds=datastorename newfolder
govc datastore.cp -ds=dastorename VM1/VM1.vmdk newfolder/VM1.vmdk
govc vm.unregister VMname
govc datacenter.create demo
# govc datacenter.info demo
Name: demo
Path: /demo
Hosts: 0
Clusters: 0
Virtual Machines: 0
Networks: 0
Datastores: 0
govc cluster.create -dc=demo democluster
- First we need to take care of cert and put it under thumbprint variable
thumbprint=$(govc about.cert -k -u <ESXi IP> -thumbprint | awk '{print $2}')
- Now add the ESXi host flawlessly
govc cluster.add -cluster democluster -hostname <esxi IP> -username root -password <password> -thumbprint $thumbprint
- This is a 2 step process. First, put the ESXi host in maintenance mode by running below command:
govc host.maintenance.enter -dc=demo <ESXi IP>
- Now you can remove ESXi
govc host.remove -dc=demo <ESXi IP>