vshpere客户端中VMware OVF导出到本地磁盘的Python代码

vshpere客户端中VMware OVF导出到本地磁盘的Python代码,python,python-3.x,vmware,vsphere,esxi,Python,Python 3.x,Vmware,Vsphere,Esxi,我正在尝试编写代码,关闭虚拟机电源,将虚拟机的OVF模板导出到Vsphere客户端上的本地磁盘,然后打开虚拟机电源 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.CER

我正在尝试编写代码,关闭虚拟机电源,将虚拟机的OVF模板导出到Vsphere客户端上的本地磁盘,然后打开虚拟机电源

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备份