在 VMware 环境中与来宾文件系统交互

问题描述

我的问题是,我找不到有关如何在本地 vCenter 基础架构上的来宾 OS VM 上本地运行 exe/bat 文件的体面 API 文档。我试图通过轮询来宾操作系统 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 文档的问题是,它似乎不正确或未更新,因为 Python 的最新 github sdk 显示模块不存在。

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)