Govc
From Halfface
Jump to navigationJump to search
govc
Install
curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | sudo tar -C /usr/local/bin -xvzf - govc
Enable login
export GOVC_URL=https://vcenter.halfface.se export GOVC_USERNAME=administrator@vsphere.local; export GOVC_PASSWORD=<password> export GOVC_INSECURE=true
govc Completion
. <(curl -sk https://raw.githubusercontent.com/vmware/govmomi/main/scripts/govc_bash_completion)
List resources
govc ls
View console
govc vm.console -capture - <output from ls> | display
open console
Download and install VMware-Remote-Console-12.0.5-22744838.x86_64.bundle
sudo mkdir -p /etc/vmware/hostd/ echo '<?xml version="1.0" ?> <metadata> </metadata>' | sudo tee /etc/vmware/hostd/proxy.xml vmrc $(govc vm.console /site/vm/bla/bla) &
List roles.
govc role.ls
who has specified role
govc role.usage
list privileges
govc role.ls -json Admin | jq -r '.privilege[]'
Add missing permission to role.
govc role.update -a openshift-vcenter-level openshift-vcenter-level
List all permission for matching role
govc role.ls | sort | grep openshift | awk '{print $1}' | while read i ; do echo '*' $i ; govc role.ls $i ; done | less
List info about vm
govc vm.info /RGK/vm/costest-ph9l4/costest-ph9l4-master-0 govc vm.info -json /<cluster>/vm/<folder>/<vm>
Turn on or off.
govc vm.power -on /<cluster>/vm/<folder>/<vm> govc vm.power -off /<cluster>/vm/<folder>/<vm> govc vm.power -off -force /<cluster>/vm/<folder>/<vm>
reboot/reset
govc vm.power -reset=true /<cluster>/vm/<folder>/<vm>
Change memory on vm.
govc vm.change -vm /<cluster>/vm/<folder>/<vm> -m 20480
Change number of cpu:s
govc vm.change -vm /<cluster>/vm/<folder>/<vm> -c 10
Set attribute
govc vm.change -e="disk.EnableUUID=1" -vm='VM Path'
List datastore
govc ls /<company>/datastore/IPO-01-vsanDatastore
List datastore to find file Iso
govc datastore.ls -ds=IPO-01-vsanDatastore -R -a -l -p
List directories
govc datastore.ls -ds /company/datastore/IX-STO1-01-vsanDatastore . | grep -v '[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}' | sort
Find network
govc ls /company/network | grep 172.19.14. /company/network/dpg-1914-172.19.14.0
List devices
govc device.ls -vm=/<cluster>/vm/<folder>/<vm>-00001-odf-0
datastore.upload
govc datastore.upload -ds=IPO-01-vsanDatastore boot.3.iso 0b0a8061-420f-77bd-367b-e43d1a863890/boot.3.iso
datastore.rm
govc datastore.rm -ds=IPO-01-vsanDatastore 0b0a8061-420f-77bd-367b-e43d1a863890/boot.3.iso
Eject cdrom
govc device.cdrom.eject -vm <vm>
Insert cdrom
govc device.cdrom.insert -vm <vm> images/boot.iso
View events from vm
govc events /<cluster>/vm/<folder>/<vm> | less
List logs
List logs from vsphere.
govc logs.ls
List logs from all hostsystems.
govc find . -type h | awk -F / '{print $NF}'| while read HOST ; do echo '*' $HOST ; govc logs.ls -host $HOST ; done
extend disk
Find disk to extend
govc device.ls -vm /path/to/your/vm
Extend disk
govc vm.disk.change -vm /path/to/your/vm -disk.label "Hard disk 1" -size 100G govc vm.disk.change -vm control-plane-1 -disk.name disk-1000-0 -size 100G
events
Search for events for vm.
govc find / -type m | sort | grep oc5 | while read i ; do echo '*' $i ; govc events -n 100 $i | grep migrate ; done
Distributed Resource Scheduler(drs) disable
Change on matching vm:s.
govc find / -type m | grep oc4 | sort | while read i ; do echo '*' $i ; govc cluster.override.change -cluster /LIV/host/LIVCLU01 -vm $i -drs-enabled=false ; done
How are settings.
govc cluster.override.info -cluster /LIV/host/LIVCLU01
get ip address of vm
govc vm.ip <path_to_vm>