def getChassisByUnitaryComputerSystem(client, unitaryComputerSystem): ''' CimClient, UnitaryComputerSystem -> Chassis or None ''' chassisInstances = cim_discover.getAssociatorsWithTypeEnforcement( client, unitaryComputerSystem.getObjectPath(), "OMC_ComputerSystemPackage", "OMC_Chassis") chassisInstance = chassisInstances and chassisInstances[0] or None if chassisInstance is not None: chassis = Chassis() chassis.setObjectPath(chassisInstance.getObjectPath()) chassis.manufacturer = cim_discover.cleanString( _getCimInstanceProperty(chassisInstance, 'Manufacturer')) chassis.model = cim_discover.cleanString( _getCimInstanceProperty(chassisInstance, 'Model')) chassis.oemSpecificStrings = _getCimInstanceProperty( chassisInstance, 'OEMSpecificStrings') serialNumber = cim_discover.cleanString( _getCimInstanceProperty(chassisInstance, 'SerialNumber')) if host_discoverer.isServiceTagValid(serialNumber): chassis.serialNumber = serialNumber chassis.uuid = cim_discover.cleanString( _getCimInstanceProperty(chassisInstance, 'uuid')) return chassis
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
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
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
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
def getUnitaryComputerSystemByBaseServerProfile(client, baseServerProfile): ''' CimClient, Profile -> UnitaryComputerSystem or None Get UnitaryComputerSystem associated with base server profiles provided ''' elements = cim_discover.getAssociatorsWithTypeEnforcement(client, baseServerProfile.getObjectPath(), "OMC_ElementConformsToBaseServerProfile", "OMC_UnitaryComputerSystem") unitaryComputerSystemInstance = elements and elements[0] or None if unitaryComputerSystemInstance is not None: unitaryComputerSystem = UnitaryComputerSystem() unitaryComputerSystem.setObjectPath(unitaryComputerSystemInstance.getObjectPath()) unitaryComputerSystem.name = cim_discover.cleanString(_getCimInstanceProperty(unitaryComputerSystemInstance, 'Name')) unitaryComputerSystem.elementName = cim_discover.cleanString(_getCimInstanceProperty(unitaryComputerSystemInstance, 'ElementName')) if unitaryComputerSystem.name: return unitaryComputerSystem
def getChassisByUnitaryComputerSystem(client, unitaryComputerSystem): ''' CimClient, UnitaryComputerSystem -> Chassis or None ''' chassisInstances = cim_discover.getAssociatorsWithTypeEnforcement(client, unitaryComputerSystem.getObjectPath(), "OMC_ComputerSystemPackage", "OMC_Chassis") chassisInstance = chassisInstances and chassisInstances[0] or None if chassisInstance is not None: chassis = Chassis() chassis.setObjectPath(chassisInstance.getObjectPath()) chassis.manufacturer = cim_discover.cleanString(_getCimInstanceProperty(chassisInstance, 'Manufacturer')) chassis.model = cim_discover.cleanString(_getCimInstanceProperty(chassisInstance, 'Model')) chassis.oemSpecificStrings = _getCimInstanceProperty(chassisInstance, 'OEMSpecificStrings') serialNumber = cim_discover.cleanString(_getCimInstanceProperty(chassisInstance, 'SerialNumber')) if host_discoverer.isServiceTagValid(serialNumber): chassis.serialNumber = serialNumber chassis.uuid = cim_discover.cleanString(_getCimInstanceProperty(chassisInstance, 'uuid')) return chassis
def getUnitaryComputerSystemByBaseServerProfile(client, baseServerProfile): ''' CimClient, Profile -> UnitaryComputerSystem or None Get UnitaryComputerSystem associated with base server profiles provided ''' elements = cim_discover.getAssociatorsWithTypeEnforcement( client, baseServerProfile.getObjectPath(), "OMC_ElementConformsToBaseServerProfile", "OMC_UnitaryComputerSystem") unitaryComputerSystemInstance = elements and elements[0] or None if unitaryComputerSystemInstance is not None: unitaryComputerSystem = UnitaryComputerSystem() unitaryComputerSystem.setObjectPath( unitaryComputerSystemInstance.getObjectPath()) unitaryComputerSystem.name = cim_discover.cleanString( _getCimInstanceProperty(unitaryComputerSystemInstance, 'Name')) unitaryComputerSystem.elementName = cim_discover.cleanString( _getCimInstanceProperty(unitaryComputerSystemInstance, 'ElementName')) if unitaryComputerSystem.name: return unitaryComputerSystem