Is there a way to see the Licenses installed on every host in the environment

66 Views Asked by At

I've tried multiple ways of getting the license information for a host. we'd like to automate this so that once a year we can just run the script and write the information to a database for audit purposes. I'm just not sure how as I loop through the hosts am able to get the License Information.

----BEGIN CODE----

def get_obj(si, root, vim_type):
    container = si.content.viewManager.CreateContainerView(root, vim_type,True)
    view = container.view
    #print(container.view)
    obj = [ret for ret in container.view]
    container.Destroy()
    return obj

lm = content.licenseManager.licenseAssignmentManager

DCS = get_obj(c, c.content.rootFolder, [vim.Datacenter])
print(DCS)
print(len(DCS))
for dc in DCS:
    print("DATACENTEER --"+dc.name)
    HOSTS = get_obj(c,dc,[vim.HostSystem])
    for host in HOSTS:
        print("HOST -- "+str(host.config.host))
        print(host.hardware.systemInfo.uuid)
        #entity_id = host.hardware.systemInfo.uuid
        print(lm.QueryAssignedLicenses(str(host.config.host)))
        #print(host.config)
        #print(host.configManager)
        #sys.exit()
1

There are 1 best solutions below

0
sky_jokerxx On

The argument of the QueryAssignedLicenses method must be given moid.
https://vdc-download.vmware.com/vmwb-repository/dcr-public/8ed923df-bad4-49b3-b677-45bca5326e85/d2d90bb6-d1b3-4266-8ce5-443680187a9a/vim.LicenseAssignmentManager.html#queryAssignedLicenses

Please try after the argument changes the below like.

        print(lm.QueryAssignedLicenses(host._moId)