https://github.com/lakostis/govc-scripts
govc.sh - wrapper which sets VSphere specific settings and runs govc
https://github.com/lakostis/govc-scripts
golang shell-script vmware vmware-esxi vsphere-api
Last synced: about 2 months ago
JSON representation
govc.sh - wrapper which sets VSphere specific settings and runs govc
- Host: GitHub
- URL: https://github.com/lakostis/govc-scripts
- Owner: LAKostis
- License: gpl-3.0
- Created: 2018-04-25T15:45:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T10:04:40.000Z (over 6 years ago)
- Last Synced: 2025-01-10T19:23:25.630Z (12 months ago)
- Topics: golang, shell-script, vmware, vmware-esxi, vsphere-api
- Language: Shell
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
- libshell (http://git.altlinux.org/people/legion/packages/?p=libshell.git;a=summary)
- jq
- govc (https://github.com/vmware/govmomi/tree/master/govc)
### 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 = @
vsphere_password =
```
- 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]
Options:
-l, --location= 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
disk_change
memory_extend Mb
memory_hotadd_check
memory_hotadd_enable
cpu_add
cpu_remove
cpu_hotadd_check
cpu_hotadd_enable
cpu_hotremove_check
cpu_hotremove_enable
ls_snapshot
create_snapshot
delete_snapshot Delete defined snapshot
revert_snapshot Revert to defined snapshot
Advanced usage:
govc.sh [options] --
```
### Find vm:
```
$ govc.sh -l fra -- find vm -name wiki*
vm/AMS_UBUNTU/
```
### Query vm config option (via direct option):
```
$ govc.sh -l fra -- object.collect -s vm/AMS_UBUNTU/ 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 ..
```