search for a vib package using pyVmomi

58 Views Asked by At

What is the parallel pyVmomi API for the following esxcli command group:

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/)

I would like to get a specific vib component from a host

actually i am converting a ruby script to python and these are the relevant code lines in ruby script:

@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)

Thanks,

i searched the following objects and didn't find a list of software packages:

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)

but i am still looking for the URL and in the package object the referenceurl is empty...

1

There are 1 best solutions below

0
On

Eventually, I added the following functions to the class:

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