LoginSignup
5
3

More than 5 years have passed since last update.

govmomi/govcで簡単にESXiを操作出来てたらよかったんだけど

Posted at

今北産業
・pyvmomi、そういうのもあるのか
・goでもあるんじゃね
・CLIツールがあった←今ココ(NEW!)

vCenterやESXiを操作するPythonのライブラリのpyvmomiというものがあります。
これでVMを作ったり電源操作したりと便利そうです。

goならCLIツールであるんじゃねと探したらありました。

govmomiの内部で使われているツールのようです。
リリースページで公開されているバイナリを落としてきて配置するだけです。

配置したら環境変数にユーザ/パスワード、IPアドレスをセットします。

C:\Users\xxx>set GOVC_INSECURE=1

C:\Users\xxx>set GOVC_USERNAME=xxxx

C:\Users\xxx>set GOVC_PASSWORD=xxxxxxxx

C:\Users\xxx>set GOVC_URL=IPアドレス/sdk

コマンドを実行してみます。

C:\Users\xxx>govc host.info
Name:              localhost.localdomain
  Path:            /ha-datacenter/host/localhost./localhost.localdomain
  Manufacturer:
  Logical CPUs:    2 CPUs @ 2304MHz
  Processor type:  Intel(R) Core(TM) i3-6100U CPU @ 2.30GHz
  CPU usage:       44 MHz (1.0%)
  Memory:          32657MB
  Memory usage:    2762 MB (8.5%)
  Boot time:       2018-01-05 20:47:18.21575 +0000 UTC
  State:           connected

C:\Users\xxx>

んほーーーーーーーいいじゃん!
使い方はここにありますが、

govc [Option] -h で使い方がわかります。

C:\Users\xxx>govc guest.ls -h
Usage: govc guest.ls [OPTIONS] PATH

List PATH files in VM.

Examples:
  govc guest.ls -vm $name /tmp

Options:
  -cert=                        Certificate [GOVC_CERTIFICATE]
  -dc=                          Datacenter [GOVC_DATACENTER]
  -debug=false                  Store debug logs [GOVC_DEBUG]
  -dump=false                   Enable Go output
  -json=false                   Enable JSON output
  -k=true                       Skip verification of server certificate [GOVC_INSECURE]
  -key=                         Private key [GOVC_PRIVATE_KEY]
  -l=:                          Guest VM credentials [GOVC_GUEST_LOGIN]
  -persist-session=true         Persist session to disk [GOVC_PERSIST_SESSION]
  -s=false                      Simple path only listing
  -tls-ca-certs=                TLS CA certificates file [GOVC_TLS_CA_CERTS]
  -tls-known-hosts=             TLS known hosts file [GOVC_TLS_KNOWN_HOSTS]
  -u=https://@192.168.0.50/sdk  ESX or vCenter URL [GOVC_URL]
  -vim-namespace=urn:vim25      Vim namespace [GOVC_VIM_NAMESPACE]
  -vim-version=6.5              Vim version [GOVC_VIM_VERSION]
  -vm=                          Virtual machine [GOVC_VM]
  -vm.dns=                      Find VM by FQDN
  -vm.ip=                       Find VM by IP address
  -vm.ipath=                    Find VM by inventory path
  -vm.path=                     Find VM by path to .vmx file
  -vm.uuid=                     Find VM by UUID

C:\Users\xxx>

仮想マシン一覧

C:\Users\xxx>govc ls /*/vm/*
/ha-datacenter/vm/WIN12
/ha-datacenter/vm/CentOS7_2
/ha-datacenter/vm/CentOS7_3
/ha-datacenter/vm/Ubuntu
/ha-datacenter/vm/CentOS7_Controller
/ha-datacenter/vm/CentOS7_Compute
/ha-datacenter/vm/CentOS7

C:\Users\xxx>

起動中のマシンとマシン情報

C:\Users\xxx>govc find . -type m -runtime.powerState poweredOn
/ha-datacenter/vm/CentOS7_3

C:\Users\xxx>govc vm.info CentOS7
Name:           CentOS7
  Path:         /ha-datacenter/vm/CentOS7
  UUID:         564d55c2-76e3-c3df-e95b-3929fa949f85
  Guest name:   CentOS 7 (64-bit)
  Memory:       1024MB
  CPU:          2 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:
  Host:         localhost.localdomain

C:\Users\xxx>

マシン起動ってあれ?

C:\Users\xxx>govc vm.power -on CentOS7
Powering on VirtualMachine:7... govc: ServerFaultCode: Current license or ESXi version prohibits execution of the requested operation.

C:\Users\xxx>

ぐわぁー、ライセンスの壁か...
無料版だからvSphere APIがread-onlyしかできないのか...
そういうことか...(´・ω・`)

https://kb.vmware.com/s/article/2111426
https://blogs.vmware.com/vsphere/2012/02/introduction-to-the-vsphere-api-part-1.html

Licensing
Access to the vSphere API is governed by the variousvSphere Editions which
provides both read and write access to the API. If you are using vSphere
Hypervisor (free edition of ESXi), the vSphere API will only be available as read-only.
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3