1

有人知道针对VMware ESXi 5.1我家中的服务器运行 Perl 脚本的细节吗?我已经下载了以下内容并将软件包安装在Ubuntu 12.04 LTS机器上,但我不知道如何开始。

VMware-vSphere-CLI-5.1.0-780721.x86_64.gz
VMware-vSphere-Perl-SDK-5.1.0-780721.x86_64.gz
VMware-vSphere-SDK-5.1.0-774886.zip

安装软件包时,我确保满足所有 Perl 模块依赖项。接下来我该怎么做?例如,我如何在 Perl 中查询运行在 ESXi 服务器上的虚拟机列表?

4

1 回答 1

4

检查以下代码以获取 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

于 2013-01-09T02:11:02.667 回答