LAKostis / govc-scripts

govc.sh - wrapper which sets VSphere specific settings and runs govc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple scripts to manage vsphere from command line

govc.sh

govc.sh - wrapper which sets VSphere specific settings and runs govc.

Other things to install:

Installation

  • git clone libshell, install shell-* files to /usr/local/bin or somewhere in $PATH
  • install govc binary to dir within $PATH
  • install govc.sh wrapper to dir within $PATH
  • create minimal cofiguration with vsphere login/passwd:
cat ~/.terraformware.conf
....
vsphere_username = <user>@<domain>

vsphere_password = <base64 encoded password string>
  • create Vsphere DC layout:
cat ~/.vs-dc.ini
# global settings are not really needed
# but ease the usage
[global]
location=ams

[ams]
url=ams-prd-vc01.xxxxx
dc=AMS-PRD-DC01

[brq]
url=brq-prd-vc02.xxxxx
dc=BRQ-PRD-DC01

Example of use:

$ govc.sh --help
Usage: Usage: govc.sh [-l DC] [options] <cmd> <vm>

Options:

  -l, --location=<FRA|PAR>      VSphere DC location (FRA or PAR);
  -V, --version                 print program version and exit;
  -h, --help                    show this text and exit;
  -j, --json                    use json output.

Command shortcuts (takes VM as last argument):

  poweron
  poweroff
  suspend
  pstate                        Shows current VM power state
  info
  disk_info
  disk_shrink
  disk_extend <size>
  disk_change <mode>
  memory_extend <size>Mb
  memory_hotadd_check
  memory_hotadd_enable
  cpu_add <nr>
  cpu_remove <nr>
  cpu_hotadd_check
  cpu_hotadd_enable
  cpu_hotremove_check
  cpu_hotremove_enable
  ls_snapshot
  create_snapshot
  delete_snapshot <name>        Delete defined snapshot
  revert_snapshot <name>        Revert to defined snapshot

Advanced usage:

govc.sh [options] -- <govc direct cmd>

Find vm:

$ govc.sh -l fra -- find vm -name wiki*
vm/AMS_UBUNTU/<vmname>

Query vm config option (via direct option):

$ govc.sh -l fra -- object.collect -s vm/AMS_UBUNTU/<vmname> config.memoryHotAddEnabled
false

Enable memory hotadd (by using shortcut):

$ govc.sh -l fra poweroff test-nginx01-fra
$ govc.sh -l fra memory_hotadd_enable test-nginx01-fra
$ govc.sh -l fra poweron test-nginx01-fra
$ govc.sh -l fra memory_hotadd_check test-nginx01-fra
govc.sh: Enabled

CPU hotadd/hotremove:

$ govc.sh -l fra cpu_hotremove_check test-nginx01-fra
govc.sh: Enabled

$ govc.sh -l fra cpu_remove 1 test-nginx01-fra
govc.sh: Cannot remove CPUs from a running VM

$ govc.sh -l fra poweroff test-nginx01-fra
Shutdown guest VirtualMachine:vm-5749... OK

$ govc.sh -l fra cpu_remove 1 test-nginx01-fra
govc.sh: Changing CPU count 4->3 ..

$ govc.sh -l fra poweron test-nginx01-fra
...

$ govc.sh -l fra cpu_add 1 test-nginx01-fra
govc.sh: Changing CPU count 3->4 ..

About

govc.sh - wrapper which sets VSphere specific settings and runs govc

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%