Techioz Blog

pyVmomiを使用してvibパッケージを検索します

概要

次の 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