def getProcessorsByUnitaryComputerSystem(client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> list(Processor)
    Get Processors by UnitaryComputerSystem
    '''
    processorInstances = client.getInstances("OMC_Processor")
    
    processors = []
    ignoredProcessorsCount = 0
    for processorInstace in processorInstances:
        systemName = cim_discover.cleanString(_getCimInstanceProperty(processorInstace, 'SystemName'))
        # uuid of cpu should match uuid of ESX, safe check
        if unitaryComputerSystem.name == systemName:
            processor = Processor()
            processor.setObjectPath(processorInstace.getObjectPath())
            processor.systemName = systemName
            processor.cpuStatus = cim_discover.getIntFromCimInt(_getCimInstanceProperty(processorInstace, 'CPUStatus'))
            processor.elementName = cim_discover.cleanString(_getCimInstanceProperty(processorInstace, 'ElementName'))
            modelName = cim_discover.cleanString(_getCimInstanceProperty(processorInstace, 'ModelName'))
            processor.modelName = modelName and re.sub(r"\s+", " ", modelName)
            processor.currentClockSpeed = cim_discover.getIntFromCimInt(_getCimInstanceProperty(processorInstace, 'CurrentClockSpeed'))
            processor.numberOfEnabledCores = cim_discover.getIntFromCimInt(_getCimInstanceProperty(processorInstace, 'NumberOfEnabledCores'))
            processor.enabledState = cim_discover.getIntFromCimInt(_getCimInstanceProperty(processorInstace, 'EnabledState'))
            
            processors.append(processor)
        else:
            ignoredProcessorsCount += 1
            
    if ignoredProcessorsCount > 0:
        logger.warn("Ignored %s processors due to mismatching UUID or being disabled" % ignoredProcessorsCount)
    
    return processors
def getMemoryByUnitaryComputerSystem(client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> list(Memory)
    Get Memory by UnitaryComputerSystem
    '''
    memoryInstances = client.getInstances("OMC_Memory")
    
    memoryList = []
    ignoredMemoryCount = 0
    for memoryInstance in memoryInstances:
        systemName = cim_discover.cleanString(_getCimInstanceProperty(memoryInstance, 'SystemName'))
        # uuid of memory should match uuid of ESX, safe check
        if unitaryComputerSystem.name == systemName:
            memory = Memory()
            memory.setObjectPath(memoryInstance.getObjectPath())
            memory.systemName = systemName
            memory.numberOfBlocks = cim_discover.getIntFromCimInt(_getCimInstanceProperty(memoryInstance, "NumberOfBlocks"))
            memory.blockSize = cim_discover.getIntFromCimInt(_getCimInstanceProperty(memoryInstance, "BlockSize"))
            memoryList.append(memory)
        else:
            ignoredMemoryCount += 1
            
    if ignoredMemoryCount > 0:
        logger.warn("Ignored %s memory instances due to mismatching UUID")
    
    return memoryList
def getHypervisorSoftwareIdentityByUnitaryComputerSystem(client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> VmwareHypervisorSoftwareIdentity or None
    '''
    softwareIdentityInstances = cim_discover.getAssociatorsWithTypeEnforcement(client, unitaryComputerSystem.getObjectPath(), "VMware_InstalledSoftwareIdentity", "VMware_HypervisorSoftwareIdentity")

    hypervisorInstance = softwareIdentityInstances and softwareIdentityInstances[0] or None
    
    if hypervisorInstance is not None:
        hypervisorSoftwareIdentity = VmwareHypervisorSoftwareIdentity()
        hypervisorSoftwareIdentity.setObjectPath(hypervisorInstance.getObjectPath())
        hypervisorSoftwareIdentity.name = cim_discover.cleanString(_getCimInstanceProperty(hypervisorInstance, 'Name'))
        hypervisorSoftwareIdentity.elementName = cim_discover.cleanString(_getCimInstanceProperty(hypervisorInstance, 'ElementName'))
        hypervisorSoftwareIdentity.versionString = cim_discover.cleanString(_getCimInstanceProperty(hypervisorInstance, 'VersionString'))
        
        majorVersion = _getCimInstanceProperty(hypervisorInstance, 'MajorVersion')
        hypervisorSoftwareIdentity.majorVersion = cim_discover.getIntFromCimInt(majorVersion)
        minorVersion = _getCimInstanceProperty(hypervisorInstance, 'MinorVersion')
        hypervisorSoftwareIdentity.minorVersion = cim_discover.getIntFromCimInt(minorVersion)
        revisionNumber = _getCimInstanceProperty(hypervisorInstance, 'RevisionNumber')
        hypervisorSoftwareIdentity.revisionNumber = cim_discover.getIntFromCimInt(revisionNumber)
        largeBuildNumber = _getCimInstanceProperty(hypervisorInstance, 'LargeBuildNumber')
        hypervisorSoftwareIdentity.largeBuildNumber = cim_discover.getIntFromCimInt(largeBuildNumber)

        lastStartTime = _getCimInstanceProperty(hypervisorInstance, 'LastStartTime')
        hypervisorSoftwareIdentity.lastStartTime = cim_discover.getDateFromCimDate(lastStartTime)

        return hypervisorSoftwareIdentity
Example #4
0
def getMemoryByUnitaryComputerSystem(client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> list(Memory)
    Get Memory by UnitaryComputerSystem
    '''
    memoryInstances = client.getInstances("OMC_Memory")

    memoryList = []
    ignoredMemoryCount = 0
    for memoryInstance in memoryInstances:
        systemName = cim_discover.cleanString(
            _getCimInstanceProperty(memoryInstance, 'SystemName'))
        # uuid of memory should match uuid of ESX, safe check
        if unitaryComputerSystem.name == systemName:
            memory = Memory()
            memory.setObjectPath(memoryInstance.getObjectPath())
            memory.systemName = systemName
            memory.numberOfBlocks = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(memoryInstance, "NumberOfBlocks"))
            memory.blockSize = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(memoryInstance, "BlockSize"))
            memoryList.append(memory)
        else:
            ignoredMemoryCount += 1

    if ignoredMemoryCount > 0:
        logger.warn("Ignored %s memory instances due to mismatching UUID")

    return memoryList
Example #5
0
def getHypervisorSoftwareIdentityByUnitaryComputerSystem(
        client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> VmwareHypervisorSoftwareIdentity or None
    '''
    softwareIdentityInstances = cim_discover.getAssociatorsWithTypeEnforcement(
        client, unitaryComputerSystem.getObjectPath(),
        "VMware_InstalledSoftwareIdentity",
        "VMware_HypervisorSoftwareIdentity")

    hypervisorInstance = softwareIdentityInstances and softwareIdentityInstances[
        0] or None

    if hypervisorInstance is not None:
        hypervisorSoftwareIdentity = VmwareHypervisorSoftwareIdentity()
        hypervisorSoftwareIdentity.setObjectPath(
            hypervisorInstance.getObjectPath())
        hypervisorSoftwareIdentity.name = cim_discover.cleanString(
            _getCimInstanceProperty(hypervisorInstance, 'Name'))
        hypervisorSoftwareIdentity.elementName = cim_discover.cleanString(
            _getCimInstanceProperty(hypervisorInstance, 'ElementName'))
        hypervisorSoftwareIdentity.versionString = cim_discover.cleanString(
            _getCimInstanceProperty(hypervisorInstance, 'VersionString'))

        majorVersion = _getCimInstanceProperty(hypervisorInstance,
                                               'MajorVersion')
        hypervisorSoftwareIdentity.majorVersion = cim_discover.getIntFromCimInt(
            majorVersion)
        minorVersion = _getCimInstanceProperty(hypervisorInstance,
                                               'MinorVersion')
        hypervisorSoftwareIdentity.minorVersion = cim_discover.getIntFromCimInt(
            minorVersion)
        revisionNumber = _getCimInstanceProperty(hypervisorInstance,
                                                 'RevisionNumber')
        hypervisorSoftwareIdentity.revisionNumber = cim_discover.getIntFromCimInt(
            revisionNumber)
        largeBuildNumber = _getCimInstanceProperty(hypervisorInstance,
                                                   'LargeBuildNumber')
        hypervisorSoftwareIdentity.largeBuildNumber = cim_discover.getIntFromCimInt(
            largeBuildNumber)

        lastStartTime = _getCimInstanceProperty(hypervisorInstance,
                                                'LastStartTime')
        hypervisorSoftwareIdentity.lastStartTime = cim_discover.getDateFromCimDate(
            lastStartTime)

        return hypervisorSoftwareIdentity
Example #6
0
def getVirtualMachinesByEsx(client, esxInstance):
    '''
    CimClient -> list(VmComputerSystem)
    '''
    vmInstances = cim_discover.getAssociatorsWithTypeEnforcement(
        client, esxInstance.getObjectPath(), "VMWARE_HostedDependency",
        "VMWARE_VMComputerSystem")

    vmList = []
    for vmInstance in vmInstances:
        vm = VmComputerSystem()
        vm.setObjectPath(vmInstance.getObjectPath())
        vm.name = cim_discover.cleanString(
            _getCimInstanceProperty(vmInstance, "Name"))
        elementName = _getCimInstanceProperty(vmInstance, "ElementName")
        elementName = cim_discover.cleanString(elementName)
        # html unescape : & -> &
        elementName = cim_discover.htmlUnescape(elementName)
        # url unescape: %25 -> %
        # vmware escapes 3 characters, both slashes and %
        elementName = urllib.unquote(elementName)
        vm.elementName = elementName

        description = _getCimInstanceProperty(vmInstance, "Description")
        description = cim_discover.cleanString(description)
        vm.description = cim_discover.htmlUnescape(description)

        identifyingDescriptions = _getCimInstanceProperty(
            vmInstance, 'IdentifyingDescriptions')
        identifyingDescriptions = map(cim_discover.cleanString,
                                      identifyingDescriptions)

        otherIdentifyingInfo = _getCimInstanceProperty(vmInstance,
                                                       'OtherIdentifyingInfo')
        otherIdentifyingInfo = map(cim_discover.cleanString,
                                   otherIdentifyingInfo)

        customProperties = _dictionaryFromCrossCollections(
            identifyingDescriptions, otherIdentifyingInfo)

        vm.biosUuid = customProperties.get("BIOS UUID")
        vm.hostName = customProperties.get("Hostname")

        primaryIpAddress = customProperties.get("Primary IP Address")
        if netutils.isValidIp(
                primaryIpAddress) and not netutils.isLocalIp(primaryIpAddress):
            vm.primaryIpAddress = primaryIpAddress

        operationalStatusArray = _getCimInstanceProperty(
            vmInstance, 'OperationalStatus')
        if operationalStatusArray is not None:
            for statusValue in operationalStatusArray:
                if statusValue is not None:
                    statusValueInt = cim_discover.getIntFromCimInt(statusValue)
                    vm.operationalStatus.add(statusValueInt)

        vmList.append(vm)

    return vmList
Example #7
0
def getProcessorsByUnitaryComputerSystem(client, unitaryComputerSystem):
    '''
    CimClient, UnitaryComputerSystem -> list(Processor)
    Get Processors by UnitaryComputerSystem
    '''
    processorInstances = client.getInstances("OMC_Processor")

    processors = []
    ignoredProcessorsCount = 0
    for processorInstace in processorInstances:
        systemName = cim_discover.cleanString(
            _getCimInstanceProperty(processorInstace, 'SystemName'))
        # uuid of cpu should match uuid of ESX, safe check
        if unitaryComputerSystem.name == systemName:
            processor = Processor()
            processor.setObjectPath(processorInstace.getObjectPath())
            processor.systemName = systemName
            processor.cpuStatus = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(processorInstace, 'CPUStatus'))
            processor.elementName = cim_discover.cleanString(
                _getCimInstanceProperty(processorInstace, 'ElementName'))
            modelName = cim_discover.cleanString(
                _getCimInstanceProperty(processorInstace, 'ModelName'))
            processor.modelName = modelName and re.sub(r"\s+", " ", modelName)
            processor.currentClockSpeed = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(processorInstace, 'CurrentClockSpeed'))
            processor.numberOfEnabledCores = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(processorInstace,
                                        'NumberOfEnabledCores'))
            processor.enabledState = cim_discover.getIntFromCimInt(
                _getCimInstanceProperty(processorInstace, 'EnabledState'))

            processors.append(processor)
        else:
            ignoredProcessorsCount += 1

    if ignoredProcessorsCount > 0:
        logger.warn(
            "Ignored %s processors due to mismatching UUID or being disabled" %
            ignoredProcessorsCount)

    return processors
def getVirtualMachinesByEsx(client, esxInstance):
    '''
    CimClient -> list(VmComputerSystem)
    '''
    vmInstances = cim_discover.getAssociatorsWithTypeEnforcement(client, esxInstance.getObjectPath(), "VMWARE_HostedDependency", "VMWARE_VMComputerSystem")
    
    vmList = []
    for vmInstance in vmInstances:
        vm = VmComputerSystem()
        vm.setObjectPath(vmInstance.getObjectPath())
        vm.name = cim_discover.cleanString(_getCimInstanceProperty(vmInstance, "Name"))
        elementName = _getCimInstanceProperty(vmInstance, "ElementName")
        elementName = cim_discover.cleanString(elementName)
        # html unescape : & -> &
        elementName = cim_discover.htmlUnescape(elementName)
        # url unescape: %25 -> %
        # vmware escapes 3 characters, both slashes and %
        elementName = urllib.unquote(elementName)
        vm.elementName = elementName
        
        description = _getCimInstanceProperty(vmInstance, "Description")
        description = cim_discover.cleanString(description)
        vm.description = cim_discover.htmlUnescape(description)
        
        identifyingDescriptions = _getCimInstanceProperty(vmInstance, 'IdentifyingDescriptions')
        identifyingDescriptions = map(cim_discover.cleanString, identifyingDescriptions)
        
        otherIdentifyingInfo = _getCimInstanceProperty(vmInstance, 'OtherIdentifyingInfo')
        otherIdentifyingInfo = map(cim_discover.cleanString, otherIdentifyingInfo)
        
        customProperties = _dictionaryFromCrossCollections(identifyingDescriptions, otherIdentifyingInfo)
        
        vm.biosUuid = customProperties.get("BIOS UUID")
        vm.hostName = customProperties.get("Hostname")
        
        primaryIpAddress = customProperties.get("Primary IP Address")
        if netutils.isValidIp(primaryIpAddress) and not netutils.isLocalIp(primaryIpAddress):
            vm.primaryIpAddress = primaryIpAddress
        
        operationalStatusArray = _getCimInstanceProperty(vmInstance, 'OperationalStatus')
        if operationalStatusArray is not None:
            for statusValue in operationalStatusArray:
                if statusValue is not None:
                    statusValueInt = cim_discover.getIntFromCimInt(statusValue)
                    vm.operationalStatus.add(statusValueInt)
        
        vmList.append(vm)
    
    return vmList