DeltaCloud 0.4.1rc1でVMwareESXiの情報を取得してみる
前回の記事(Deltacloud 0.3.0→0.4.1-rc1にしてみる - ike-daiの日記)でDeltaCloudの0.4.1rc1へのバージョンは完了しました。
それではvSphereドライバを利用してVMwareESXiの環境を操作してみたいと思います。
まずは、deltaclouddを-i vsphereのドライバ指定で起動します。
http://xxx.xxx.xxx.xxx:3001/apiにアクセスすると前回の記事のような画面が表示されます。
ここで、Instancesをクリックしてみると、Basic認証がかかっていて、ユーザ名とパスワードを入力するよう促されます。
?ホスト名はどこで指定するの?
ということでソースコードの中身を追ってみます。
vsphere_driver.rbの中身を見ると、
def new_client(credentials) safely do RbVmomi::VIM.connect(:host => host_endpoint, :user => credentials.user, :password => credentials.password, :insecure => true) end end def host_endpoint endpoint = api_provider endpoint || Deltacloud::Drivers::driver_config[:vsphere][:entrypoints]['default']['default'] end
こういった記述があります。
どうやらESXiへのアクセスにはRbVmomiを利用しているみたいです。
ここで、host情報はhost_endpointを指定していて、host_endpointを見てみると、driver_configということで設定ファイルからhost名を引っ張ってきているみたいです。
そこで、設定ファイルを確認。
設定ファイルは、gemの中の以下の場所にあります。
/usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/deltacloud-core-0.4.1/config/drivers/vsphere.yaml
-
- -
- vsphere
yamlファイルにデフォルトだと上記のような記述がされています。
このファイルのentrypoints default defaultを書き換えて実際に接続可能なホスト名にします。
Instancesにアクセスしユーザ名とパスワードを入力すると、エラーが発生しました。
172.27.20.138 - - [27/Oct/2011 14:31:34] "GET /api/instances HTTP/1.1" 401 15 0.0646 [NO HANDLED] SocketError: getaddrinfo: Temporary failure in name resolution ・・・略
yamlファイルに記述しても駄目みたい。
ということでこのような形でdeltaclouddの起動時にAPI_PROVIDERでホスト名を指定してみると取得できました。
API_PROVIDER="10.1.1.1" deltacloudd -i vsphere -r 192.168.1.10 -p 3001
Instancesにアクセスすると情報が取得可能になります。
curlコマンドを使ってCUIでxmlを取得する場合はこのような感じで取得可能です。
# curl --user ユーザ名:パスワード http://192.168.1.10:3001/api/instances <!DOCTYPE html> <html> <head> <title>Deltacloud API 0.4.1</title> <link charset="utf-8" href="/stylesheets/jquery.mobile-1.0b1.min.css" media="screen" rel="stylesheet" type="text/css"> <link charset="utf-8" href="/stylesheets/new.css" media="screen" rel="stylesheet" type="text/css"> <script src='/javascripts/jquery.min.js' type='text/javascript'></script> <script src='/javascripts/application.js' type='text/javascript'></script> <script src='/javascripts/jquery.mobile-1.0b1.min.js' type='text/javascript'></script> <script type='text/javascript'> //<![CDATA[ $(document).ready(function() { $(document).bind("mobileinit", function(){ $.mobile.ajaxEnabled = false; $.mobile.hashListeningEnabled = false; }); }) //]]> </script> </head> <body> <div data-role='page'> <div data-add-back-btn='true' data-role='header' data-theme='b'> <a data-rel='back'> Back </a> <h1> Instances </h1> </div> <div data-role='header' data-theme='a'> <p class='inner-right'> 192.168.1.10 </p> </div> <div data-role='content' data-theme='c'> <ul data-divider-theme='a' data-inset='true' data-role='listview'> <li data-role='list-divider'>vsphere</li> <li> <a data-ajax='false' href='http://192.168.1.10:3001/api/instances/VM01'> <img class='ui-link-thumb' src='/images/machine.png' /> <h3>VM01</h3> <p> <strong>VM01</strong> </p> <p>root, , default</p> <span class='ui-li-count'>RUNNING</span> </a> </li> <li> <a data-ajax='false' href='http://192.168.1.10:3001/api/instances/VM02'> <img class='ui-link-thumb' src='/images/machine.png' /> <h3>VM02</h3> <p> <strong>VM02</strong> </p> <p>root, , default</p> <span class='ui-li-count'>RUNNING</span> </a> </li> <li> <a data-ajax='false' href='http://192.168.1.10:3001/api/instances/VM03'> <img class='ui-link-thumb' src='/images/machine.png' /> <h3>VM03</h3> <p> <strong>VM03</strong> </p> <p>root, , default</p> <span class='ui-li-count'>STOPPED</span> </a> </li> </ul> </div> <div data-role='footer' data-theme='a'> <div data-role='navbar'> <ul> <li> <a data-ajax='false' data-icon='home' href='/api/'>Home</a> </li> <li><a data-ajax="false" data-icon="grid" href="/api/instances?format=xml">XML</a></li> <li><a data-ajax="false" data-icon="grid" href="/api/instances?format=json">JSON</a></li> </ul> </div> <div data-role='header' data-theme='a'> <div id='copyright'> Copyright 2009-2011 <a href='http://incubator.apache.org/deltacloud/'>The Apache Software Foundation</a> and individual contributors. </div> </div> </div> </div> </body> </html>
一覧を取得して、その稼働状態まではこれで取得できました。
次回は起動・停止などの操作を実施してみたいと思います。