假设我有 2 个“物理”ESX,它们都由 vSphere 服务器领导。我想要做的是运行一个脚本,它将文件上传到指定的虚拟机。所以基本上,我使用 VMWare 社区提供的 VIFS.pl 脚本,其文档可在此处获得:http ://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vcli .ref.doc%2Fvifs.html和代码源在这里:http: //communities.vmware.com/docs/DOC-10774。
源代码非常简单,它只是使用模块中的http_put_file()
函数VIExt
,而这个函数对我来说实际上是失败的,因为我得到一个错误 500,它的日志在这里(我通过打印得到它$resp->as_string()
):
do_put() 函数
sub do_put {
my ($local_source, $remote_target, $datacenter) = @_;
my ($mode, $dc, $ds, $filepath) = VIExt::parse_remote_path($remote_target);
# bug 322577
if (defined $local_source and -d $local_source) {
VIExt::fail("Error: File to be uploaded cannot be a folder.");
}
# bug 266936
unless (-e $local_source) {
VIExt::fail("Error: File $local_source does not exist.");
}
my $resp = VIExt::http_put_file($mode, $local_source, $filepath, $ds, $datacenter);
# bug 301206
print $resp->as_string(); # => Trace
if ($resp && $resp->is_success) {
print "Uploaded file $local_source to $filepath successfully.\n";
} else {
print "Failed to upload !";
}
}
** 痕迹 **
# vSphere server : @192.168.20.2
# Datastore : nfs
# Datacenter : dc
# Target VM name : target_vm
# Target filename : VM.txt
>> perl vifs --server 192.168.20.2 --username root --password root -p "/tmp/foo.txt" "[nfs] target_vm/VM.txt" -Z "dc"
HTTP/1.1 500 Internal Server Error
Connection: close
Date: Thu, 6 Dec 2012 10:32:30 GMT
Content-Length: 0
Content-Type: text; charset=plain
Client-Date: Thu, 06 Dec 2012 11:32:53 GMT
Client-Peer: 192.168.20.2:443
Client-Response-Num: 9
Client-SSL-Cert-Issuer: /C=US/ST=California/L=Palo Alto/O=VMware, Inc./CN=localhost.localdom CA 26fc6343/emailAddress=ssl-certificates@vmware.com
Client-SSL-Cert-Subject: /C=US/ST=California/L=Palo Alto/O=VMware, Inc./OU=VMware vCenter Server Certificate/emailAddress=ssl-certificates@vmware.com/CN=localhost.localdom/unstructuredName=1352217590,031bd875,564d7761726520496e632e
Client-SSL-Cipher: AES256-SHA
Client-SSL-Socket-Class: IO::Socket::SSL
Client-SSL-Warning: Peer certificate not verified
Failed to upload !
请注意,我检查了函数中作为参数传递的所有变量的值http_put_file
,它们都是正确的。
如果有人遇到过这个问题,将不胜感激......