Vmware-Esxi

以程式方式獲取 vmware 來賓列表

  • October 12, 2017

有沒有辦法以程式方式(即編寫一個小型 c 應用程序或更好的 ruby​​ 或 perl 腳本)從 VMWare 基礎架構獲取所有來賓列表(以及有關來賓的詳細資訊)?

謝謝,馬特·德爾維斯

這裡有很多選擇

像這樣的東西應該​​很好用。呼叫此 perl 腳本時,您需要指定伺服器 ( server_fqdn:port#) 以及使用者名和密碼 (例如$ perl listVMS --server 1.1.1.1:333 --username "whatever\user" --password "s0m3p4ss")

use FindBin;
use lib "$FindBin::Bin/../";

use VMware::VIRuntime;
use AppUtil::HostUtil;
use AppUtil::VMUtil;

use Data::Dumper;

use Getopt::Long qw( :config no_ignore_case pass_through );

Opts::parse('pass_through');
$server     = Opts::get_option('server');
$username   = Opts::get_option('username');
$password   = Opts::get_option('password');

$service_url = "https://".$server."/sdk/vimService";

Util::connect();

Vim::login(service_url => $service_url, user_name => $username, password => $password);

# This gets all the host systems
my $host_views = Vim::find_entity_views(view_type => 'HostSystem', properties => [ 'summary', 'hardware', 'name' ]); 

foreach my $host (@$host_views) {
   $hostname = $host->name;

   my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => { name => $host->name } );

   # This gets all the vms running on a the host system
   my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $host_view, properties => ['summary','name']);

   print "HostSystem '$hostname' has the following virtual guests\n";
   foreach my $vm (@$vm_views) 
   {
       my $vmName = $vm->name;
       print "\t$vmName\n";
   }

} 
Util::disconnect();

引用自:https://serverfault.com/questions/86102