harry’s memorandum

おれおれメモ

Scientific Linux 6.0 で libvirtを野良ビルドしてVMware ESXiにアクセスしてみた。

Scientific Linux 6.0 で libvirtを使ってesxにアクセスして遊んでみようとしたのですが...
世の中は思うようにいかないです。

$ virsh -c esx://192.168.1.5/?no_verify=1
Enter username for 192.168.1.5 [root]:
Enter root's password for 192.168.1.5:
error: internal error Expecting VI API major/minor version '2.5' or '4.0' but found '4.1'
error: failed to connect to the hypervisor

少しlibvritが古いのか esx4.1 は受け付けないと怒られてしまいました。

$ rpm -aq | grep libvirt
libvirt-0.8.1-27.el6_0.6.x86_64
libvirt-client-0.8.1-27.el6_0.6.x86_64

公式サイトをみたところ「Since 0.8.3」からサポートのようです。

The libvirt VMware ESX driver can manage VMware ESX/ESXi 3.5/4.x and VMware GSX 2.0, also called VMware Server 2.0, and possibly later versions. Since 0.8.3 the driver can also connect to a VMware vCenter 2.5/4.x (VPX).

http://libvirt.org/drvesx.html


仕方が無いのでScientific Linux 6.1がリリースされるまで、でRHEL6.1のsrc.rpmを野良ビルドして我慢してみました。

libvirtのビルド

まずはrhel6.1のsrc.rpmをダウンロード。

$ wget ftp://ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/redhat/linux/enterprise/6Server/en/os/SRPMS/libvirt-0.8.7-18.el6.src.rpm

このぐらいで大丈夫だろう、と前もって入れておいたのですが...

$ sudo yum install rpm-build gcc gdb make 

かなり怒られました。

$ rpmbuild --rebuild libvirt-0.8.7-18.el6.src.rpm
Installing libvirt-0.8.7-18.el6.src.rpm
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
error: Failed build dependencies:
        python-devel is needed by libvirt-0.8.7-18.el6.x86_64
        autoconf is needed by libvirt-0.8.7-18.el6.x86_64
        automake is needed by libvirt-0.8.7-18.el6.x86_64
        libtool is needed by libvirt-0.8.7-18.el6.x86_64
        libxml2-devel is needed by libvirt-0.8.7-18.el6.x86_64
        xhtml1-dtds is needed by libvirt-0.8.7-18.el6.x86_64
        readline-devel is needed by libvirt-0.8.7-18.el6.x86_64
        ncurses-devel is needed by libvirt-0.8.7-18.el6.x86_64
        gettext is needed by libvirt-0.8.7-18.el6.x86_64
        gnutls-devel is needed by libvirt-0.8.7-18.el6.x86_64
        augeas is needed by libvirt-0.8.7-18.el6.x86_64
        libudev-devel >= 145 is needed by libvirt-0.8.7-18.el6.x86_64
        libpciaccess-devel >= 0.10.9 is needed by libvirt-0.8.7-18.el6.x86_64
        yajl-devel is needed by libvirt-0.8.7-18.el6.x86_64
        libpcap-devel is needed by libvirt-0.8.7-18.el6.x86_64
        libnl-devel is needed by libvirt-0.8.7-18.el6.x86_64
        avahi-devel is needed by libvirt-0.8.7-18.el6.x86_64
        libselinux-devel is needed by libvirt-0.8.7-18.el6.x86_64
        radvd is needed by libvirt-0.8.7-18.el6.x86_64
        cyrus-sasl-devel is needed by libvirt-0.8.7-18.el6.x86_64
        parted-devel is needed by libvirt-0.8.7-18.el6.x86_64
        device-mapper-devel is needed by libvirt-0.8.7-18.el6.x86_64
        numactl-devel is needed by libvirt-0.8.7-18.el6.x86_64
        libcap-ng-devel >= 0.5.0 is needed by libvirt-0.8.7-18.el6.x86_64
        netcf-devel >= 0.1.4 is needed by libvirt-0.8.7-18.el6.x86_64
        libcurl-devel is needed by libvirt-0.8.7-18.el6.x86_64
        audit-libs-devel is needed by libvirt-0.8.7-18.el6.x86_64
        systemtap-sdt-devel is needed by libvirt-0.8.7-18.el6.x86_64

足りないものは潰す。

$ sudo yum install python-devel autoconf automake libtool libxml2-devel xhtml1-dtds readline-devel ncurses-devel gettext gnutls-devel augeas libudev-devel libpciaccess-devel yajl-devel libpcap-devel libnl-devel avahi-devel libselinux-devel radvd cyrus-sasl-devel parted-devel device-mapper-devel numactl-devel libcap-ng-devel netcf-devel libcurl-devel audit-libs-devel systemtap-sdt-devel gnutls-utils

もう一度rpmbuildして完成。

$ rpmbuild --rebuild libvirt-0.8.7-18.el6.src.rpm

so.2()(64bit) libxslt.so.1()(64bit) libyajl.so.1()(64bit) libz.so.1()(64bit) python(abi) = 2.6 rtld(GNU_HASH)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/foo/rpmbuild/BUILDROOT/libvirt-0.8.7-18.el6.x86_64
Wrote: /home/foo/rpmbuild/RPMS/x86_64/libvirt-0.8.7-18.el6.x86_64.rpm
Wrote: /home/foo/rpmbuild/RPMS/x86_64/libvirt-client-0.8.7-18.el6.x86_64.rpm
Wrote: /home/foo/rpmbuild/RPMS/x86_64/libvirt-devel-0.8.7-18.el6.x86_64.rpm
Wrote: /home/foo/rpmbuild/RPMS/x86_64/libvirt-python-0.8.7-18.el6.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.VinqCn
+ umask 022
+ cd /home/foo/rpmbuild/BUILD
+ cd libvirt-0.8.7
+ rm -fr /home/foo/rpmbuild/BUILDROOT/libvirt-0.8.7-18.el6.x86_64
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.uE2shc
+ umask 022
+ cd /home/foo/rpmbuild/BUILD
+ rm -rf libvirt-0.8.7
+ exit 0

野良ビルドしたlibvirtをインストール

$ sudo rpm -Uvh *rpm
Preparing...                ########################################### [100%]
   1:libvirt-client         ########################################### [ 25%]
   2:libvirt                ########################################### [ 50%]
   3:libvirt-python         ########################################### [ 75%]
   4:libvirt-devel          ########################################### [100%]

念のため再起動

$ sudo /etc/init.d/libvirtd restart
Stopping libvirtd daemon:                                  [  OK  ]
Starting libvirtd daemon:                                  [  OK  ]

libvirtでesxにアクセス

$ virsh -c esx://192.168.1.5/?no_verify=1
Enter username for 192.168.1.5 [root]:
Enter root's password for 192.168.1.5:
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit
ゲスト一覧
virsh # list
 Id Name                 State
----------------------------------
 16 windows2000          running
 32 ubuntu11.04          running
208 centos5              running
224 cern6                running
esxの構成情報
virsh # nodeinfo
CPU model:           Intel Core i5 CPU M 460 @ 2.53G
CPU(s):              2
CPU frequency:       2526 MHz
CPU socket(s):       1
Core(s) per socket:  2
Thread(s) per core:  2
NUMA cell(s):        1
Memory size:         5954024 kB
ゲストのシャットダウン
virsh # shutdown 32
Domain 32 is being shutdown

virsh # list
 Id Name                 State
----------------------------------
 16 windows2000          running
208 centos5              running
224 cern6                running
ゲストOSの情報
virsh # dominfo 208
Id:             208
Name:           centos5
UUID:           564dc12a-363f-d01f-2863-606774e120fa
OS Type:        hvm
State:          running
CPU(s):         2
Max memory:     1048576 kB
Used memory:    1048576 kB
Persistent:     yes


まったくもって素晴らしい。野良ビルドって本当にいいですね。
しかし、まだまだESXサポートしているAPIは少ないのが現状っぽいですね。
http://libvirt.org/hvsupport.html

virsh # dommemstat 16
error: Failed to get memory statistics for domain 16
error: this function is not supported by the connection driver: virDomainMemoryStats