首页 > 解决方案 > 在 VMware 环境中与来宾文件系统交互

问题描述

我的问题是我找不到一个像样的 API 文档,说明如何在本地 vCenter 基础架构上的来宾操作系统 VM 上本地运行 exes/bat 文件。我试图通过轮询来宾操作系统 vm 文件系统来自动化一些修补任务,在该 vm 中运行 .bat,然后在该 vm 中运行一些 powershell cmdlet,但是我无法弄清楚文件系统部分。我可以使用以下代码获得 VM 列表:

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
import vmware.vapi
import vmware
session = requests.session()

HOST = 'vcenter.homelab.local'
USER = 'Admin@vsphere.local'
PWD = 'password'

session.verify = False

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

vsphere_client = create_vsphere_client(server=HOST, username=USER, password=PWD, session=session)

vms_list = vsphere_client.vcenter.VM.list()

print(vms_list)

for item in vms_list:
     print(item.name)

     local_fs = vsphere_client.vcenter.VM.guest_client.LocalFilesystem.get(item.name)

我对 VMware API 文档的问题是它似乎不正确或未更新,因为最新的 github sdk for python 显示不存在的模块。

https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/vcenter/vm/guest/guest_ops.py

如果我克隆整个 repo 并在 pycharm 中打开,则 filesystem_client 不存在。所以看起来 pycharm 没有更新模块骨架,或者他们正在使用模块中实际不存在的类。

标签: pythonvmwarevspherevcenter

解决方案


推荐阅读