public ESXTools(String url, String username, String password) {
try {
si = new ServiceInstance(new URL(url), username, password, true);
} catch (RuntimeFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public void showEsx (String ipAddress) {
try {
ManagedEntity me = si.getSearchIndex().findByIp(null, ipAddress, true);
if (me instanceof VirtualMachine) {
VirtualMachineRuntimeInfo vmri = ((VirtualMachine) me).getSummary().getRuntime();
System.out.println(((VirtualMachine) me).getName() + "," + new HostSystem(si.getServerConnection(), vmri.getHost()).getName() + "," + ipAddress);
}
} catch (RuntimeFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
インスタンスを作成する際のurl, username, passwordはそれぞれ「vCenterのIPアドレス」「vCenterに登録してあるユーザ名、パスワード」です
findByIpからVMを検索してそのVMが乗っているホスト名を取得します
ポイントはHostSystemのインスタンスを作成する点
VMの情報からはどうやっても参照できないようです
(gitで公開しようとしましたが、やめておきましたw)
0 件のコメント:
コメントを投稿