前の回から結局離れてしまっていたので、サンプルを叩いてモチベーションをあげる作戦。
vSphere SDK for Perl(ver 5.0.0U1)
http://downloads.vmware.com/jp/d/info/datacenter_cloud_infrastructure/vmware_vsphere/5_0#drivers_tools
Perlのモジュールにしては大きいと思ったら、Perl(5.8.8)もついてきました。
モジュール導入に苦戦しちゃう僕にはありがたいです。
既に入っているものと競合しないように、PATHを指定してコマンドラインを実行します。
また、サンプル実行しようとしたとき、
Error connecting to server at 'https://localhost/sdk/webService': Perhaps host is not a vCenter or ESX server
とか出たので、ESXiじゃだめなのかな・・・終わったかな・・・とか思っていたらそんなことはなくて、
ESXiのサーバのIPを直接指定すればOKでした。
NICを検出サンプル
C:\Program Files (x86)\VMware\VMware vSphere CLI>echo %PATH% C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\VMware\VMware vSphere CLI\bin;C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin; C:\Program Files (x86)\VMware\VMware vSphere CLI>perl bin\esxcfg-nics.pl --list --server [ESXiのIPアドレス] --username root --password XXXX Name PCI Driver Link Speed Duplex MAC Address MTU Description vmnic0 05:00.0 e1000e Up 100Mbps Full 00:15:17:XX:XX:XX 1500 Intel Corporation 82571EB Gigabit Ethernet Controller vmnic1 05:00.1 e1000e Down 0Mbps Half 00:15:17:XX:XX:XX 1500 Intel Corporation 82571EB Gigabit Ethernet Controller
VMの一覧取得サンプル
C:\Program Files (x86)\VMware\VMware vSphere CLI>perl .\Perl\apps\vm\vminfo.pl --server [ESXiのIPアドレス] --username root --password XXXX Information of Virtual Machine CentOS 6.2 Name: CentOS 6.2 No. of CPU(s): 1 Memory Size: 2048 Virtual Disks: 1 Template: 0 vmPathName: [datastore_small1] CentOS 6.2/CentOS 6.2.vmx Guest OS: CentOS 4/5/6 (64-bit) guestId: centos64Guest Host name: localhost.localdomain IP Address: 192.168.11.129 VMware Tools: VMware Tools is running and the version is current Cpu usage: 4 MHz Host memory usage: 378 MB Guest memory usage: 0 MB Overall Status: The entity is OK
1個しか作ってなかった。
ただ、1回1回のレスポンスが時間かかる(3秒ぐらい)ので、
監視は1分単位の定期実行にするなどして、非同期な設計を前提にしたほうが良いかもしれない。
コネクションに時間かかっているっぽいので、コネクション張りっぱなしにするのも手かもしれませんが。
ハードウェアモニタなどリソース使用状況や、電源つけたりとかもできるようだし、
WEBからVM状態を監視するようなもんを書いてみよう。
おまけ。ESXiのシェルへ公開鍵暗号で接続
/usr/lib/vmware/openssh/bin/ssh-keygen -t rsa -b 2048 # 作成先は /tmp/id_rsa mv /tmp/id_rsa.pub /etc/ssh/keys-root/authorized_keys
以下を追加してパスワード認証を無効にしておきます。
vi /etc/ssh/sshd_config
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
PermitEmptyPasswords no
再起動
/etc/init.d/SSH restart