我正在尝试使用以下链接中的代码在vcenter中部署ovf映像:
[https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/deploy_ovf.py][1]
python vm_deploy.py -s ‘vcneter_url’ -u ‘username’ -p ‘password’ -v ‘.vmdk path’ -f ‘.ovf path’
但是由于下面的回溯而失败:
Traceback (most recent call last):
File "orig.py", line 218, in <module>
exit(main())
File "orig.py", line 185, in main
objs = get_objects(si, args)
File "orig.py", line 150, in get_objects
resource_pool_obj = cluster_obj.resourcePool
AttributeError: 'vim.Folder' object has no attribute 'resourcePool'
除了下面的链接以外,我无法在在线上获得更多有关此错误的帮助:
[https://github.com/vmware/pyvmomi-community-samples/issues/201][1]
我可以看到dir(cluster_obj)
中没有resourcePool
,但不确定如何使它工作。
答案 0 :(得分:0)
仅当您在体系结构中手动创建资源池时,此脚本才起作用。
但是,只需稍加修改,您就可以定位特定主机的默认resourcePool。
在 get_objects 函数中,替换(第140行):
# Get cluster object.
cluster_list = datacenter_obj.hostFolder.childEntity
if args.cluster_name:
cluster_obj = get_obj_in_list(args.cluster_name, cluster_list)
elif len(cluster_list) > 0:
cluster_obj = cluster_list[0]
else:
print "No clusters found in DC (%s)." % datacenter_obj.name
hosts = datacenter_obj.hostFolder.childEntity
resource_pool = hosts[0].resourcePool
# Generate resource pool.
resource_pool_obj = cluster_obj.resourcePool
通过这个:
for computeResource in datacenter_obj.hostFolder.childEntity :
if computeResource.name == 'ip or hostname here':
resource_pool = computeResource.resourcePool
break
在您给出的脚本中给出了 datacenter_obj ,例如:
datacenter_obj = si.content.rootFolder.childEntity[0]
0是找到的第一个数据中心。
即使答案来得有点晚,我希望它会对您有所帮助