以下 esxcli 命令组的并行 pyVmomi API 是什么:
software sources vib get - Displays detailed information about one or more VIB packages in the depot
(https://vdan.cz/esxcli-commands-for-esxi-7-0/)
我想从主机获取特定的 vib 组件
实际上我正在将 ruby 脚本转换为 python,这些是 ruby 脚本中的相关代码行:
@vim = RbVmomi::VIM.connect(:host => @conn["server"], :password => @conn["password"], :user => @conn["user"], :port => 443, :insecure => true)
@dc = @vim.serviceInstance.find_datacenter
@host = @dc.hostFolder.children.first.host.first
@host.esxcli.software.sources.vib.get(:depot => [vib_component]).map(&:props)
谢谢,
我搜索了以下对象,没有找到软件包列表:
si = SmartConnect(host=[server], user=[user], pwd=[password], port=443,
disableSslCertValidation=True, connectionPoolTimeout=60)
content = si.RetrieveContent()
container = content.rootFolder # starting point to look into
viewType = [pyVmomi.vim.HostSystem] # object types to look for
recursive = True # whether we should look into it recursively
containerView = content.viewManager.CreateContainerView(container, viewType, recursive)
children = containerView.view
for child in children:
software_packages = child.configManager.imageConfigManager.fetchSoftwarePackages()
for package in software_packages:
if package.name in component:
print(package.name)
但我仍在寻找 URL,并且在包对象中,referenceurl 为空...
最终,我在类中添加了以下函数:
def get_host(si):
content = si.RetrieveContent()
container = content.rootFolder # starting point to look into
viewType = [pyVmomi.vim.HostSystem] # object types to look for
recursive = True # whether we should look into it recursively
containerView = content.viewManager.CreateContainerView(container, viewType, recursive)
children = containerView.view
return children[0]
def get_host_software_sources(host, component: str) -> str:
components = list()
software_packages = host.configManager.imageConfigManager.fetchSoftwarePackages()
for package in software_packages:
if package.name in component:
components.append(package)
if not components:
print(f"Error: {component} not found!")
return components