检查以下代码以获取 VM 名称:
#!/usr/bin/perl -w
use strict;
use VMware::VIRuntime;
my %opts = (
datacenter => {
type => "=s",
help => "Enter the Dacenter Name",
required => 1,
},
);
Opts::add_options(%opts);
Opts::parse();
Opts::validate();
Util::connect();
my $dc = Opts::get_option("datacenter");
my $datacenter = Vim::find_entity_view ( view_type => "Datacenter",
properties => [ "name" ],
filter => { name => $dc },
);
my $vms = Vim::find_entity_views ( view_type => "VirtualMachine",
properties => [ "name" ],
begin_entity => $datacenter,
);
foreach my $vm ( @$vms )
{
print $vm->name."\n";
}
Util::disconnect();
运行上面的脚本如下:
perl vm_list.pl --server <vCenter_server_name> --datacenter <Datacenter_name>
当然,除非您阅读 vSphere perl SDK 文档,否则上述代码对您没有任何意义。请参阅以下链接以帮助您入门:
解释 vpshere 对象的示例代码:http: //www.vmware.com/support/developer/viperltoolkit/doc/perl_toolkit_guide_idx.html
API 参考指南:http ://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fright-pane.html
客户端对象:http ://pubs.vmware.com/vi301/admin/wwhelp/wwhimpl/common/html/wwhelp.htm?context=admin&file=BSA_Inventory.9.2.html
通用 API 文档: http: //www.vmware.com/support/developer/viperltoolkit/
和www.google.com