python - 在 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 显示不存在的模块。
如果我克隆整个 repo 并在 pycharm 中打开,则 filesystem_client 不存在。所以看起来 pycharm 没有更新模块骨架,或者他们正在使用模块中实际不存在的类。
解决方案
推荐阅读
- excel - 扫描#时如何自动返回原始列但下一行
- javascript - 如何防止上传按钮选择特定大小和类型的文件?
- android - 在 Android Kotlin 中使用 Algolia 进行地理搜索
- dji-sdk - 如何获得 Matrice 600 (PRO) A3 的快门信号?
- javascript - es6 Array Reduce 函数和字符串拆分用法
- dns - DNS 问题 - 找不到服务器 IP 地址
- javascript - 如何在 javascript 中给出 !important
- google-apps-script - 如何为变量设置 Google Apps 脚本对话框答案?
- python - 如何修复烧瓶 test_client().post() 中的 json 解码错误?
- python - 我可以使用 python 通过 HTTP 直接从服务器流式传输 GZIP 数据集吗?