python - 在 vshpere 客户端中将 VMware OVF 导出到本地磁盘的 Python 代码
问题描述
我正在尝试编写将关闭 VM 并将 VM 的 OVF 模板导出到 Vsphere 客户端上的本地磁盘然后打开 VM 的代码。
import pyVim
import atexit
import ssl
from pyVim import connect
from pyVmomi import vim
def vconnect():
try:
s = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode = ssl.CERT_NONE
# Connect to a cluster or host
#service_instance = connect.SmartConnect(host="Host IP", user="Host user", pwd="Host Pswd", port=443, sslContext=s)
atexit.register(connect.Disconnect, service_instance)
content = service_instance.RetrieveContent()
container = content.rootFolder
viewType = [vim.VirtualMachine]
recursive = True
containerView = content.viewManager.CreateContainerView(container, viewType, recursive)
childern = containerView.view
#print(childern)
for child in childern:
summary = child.summary
print(child.name, "=" ,child.runtime.powerState)
#print(summary.config.name)
#print("---")
vm_name = child.name
if vm_name == 'Test 51.48':
print("-------")
print("VM : {}".format(vm_name))
print("Powering off VM {}".format(vm_name))
#Power on the VM
try:
child.PowerOff()
print("VM powered off")
except Exception as e:
print("{} Power off failed because : {}".format(vm_name, e))
#Take OVF backup to local disk
try:
#Need the Backup code
except Exception as e:
print("Back up failed because ", e)
#Power on the VM
try:
child.PowerOn()
print("VM powered off")
except Exception as e:
print("{} Power off failed because : {}".format(vm_name, e))
print("-------")
except Exception as e:
print("SSL connection failed because ", e)
vconnect()
python脚本的新手。需要在上面的代码中添加备份脚本。如何使用代码进行 OVF 备份?
解决方案
推荐阅读
- c++ - 如何在 C++ 中从客户端取消服务器端流式调用?
- d3.js - 如何在使用 d3.js 显示数据的鼠标上绘制垂直线
- yaml - ruamel 压缩评论并注入 0x07
- google-chrome-extension - 我怎样才能将“文本”转换为“可下载的 url”?
- java - 如何使用 JSoup 打印此 HTML 表格的内容?
- postgresql - POSTGRESQL查询:有空格不返回结果,使用下划线返回结果
- email - Laravel 无法在任何 mail_encryption(tls、ssl、starttls)上建立连接主机
- python - 在 Python 中,如何计算电子邮件地址列表中的数字“1”?
- html - Ruby on Rails:使用 button_to 增加脚手架中对象的值
- php - 树枝中的 Symfony4 翻译