def build(self, vm): if vm is None: raise ValueError("vm is None") vmOsh = None if vm.primaryIpAddress: vmOsh = modeling.HostBuilder.incompleteByIp(vm.primaryIpAddress) else: vmOsh = modeling.HostBuilder.fromClassName('node') vmOsh.setAsVirtual(True) if vm.biosUuid: modeling.setHostBiosUuid(vmOsh, vm.biosUuid) if vm.hostName: hostName, domainName = getHostNameAndDomain(vm.hostName) if hostName: vmOsh.setStringAttribute('name', hostName) if domainName: vmOsh.setStringAttribute('host_osdomain', domainName) if vm.description: vmOsh.setStringAttribute('data_description', vm.description) return vmOsh.build()
def build(self, unitaryComputerSystem): if unitaryComputerSystem is None: raise ValueError("unitaryComputerSystem is None") hostOsh = modeling.HostBuilder.fromClassName('vmware_esx_server') hostOsh.setStringAttribute('host_key', unitaryComputerSystem.name) hostOsh.setBoolAttribute('host_iscomplete', 1) modeling.setHostBiosUuid(hostOsh, unitaryComputerSystem.name) modeling.setHostOsFamily(hostOsh, 'baremetal_hypervisor') if unitaryComputerSystem._chassis: if unitaryComputerSystem._chassis.model: hostOsh.setStringAttribute('host_model', unitaryComputerSystem._chassis.model) if unitaryComputerSystem._chassis.manufacturer: hostOsh.setStringAttribute('host_vendor', unitaryComputerSystem._chassis.manufacturer) if unitaryComputerSystem._chassis.serialNumber: hostOsh.setStringAttribute('serial_number', unitaryComputerSystem._chassis.serialNumber) if unitaryComputerSystem._hypervisorSoftwareIdentity: if unitaryComputerSystem._hypervisorSoftwareIdentity.lastStartTime is not None: hostOsh.setDateAttribute('host_last_boot_time', unitaryComputerSystem._hypervisorSoftwareIdentity.lastStartTime) hostName, domainName = getHostNameAndDomain(unitaryComputerSystem.elementName) if hostName: hostOsh.setStringAttribute('name', hostName) if domainName: hostOsh.setStringAttribute('host_osdomain', domainName) return hostOsh.build()
def setHostAttributes(self): if self.hostOsh: if self.hostDo.hostName: self.hostOsh.setAttribute('host_hostname', self.hostDo.hostName) if self.hostDo.hostOsName: modeling.setHostOsName(self.hostOsh, self.hostDo.hostOsName) if self.hostDo.description: self.hostOsh = modeling.HostBuilder(self.hostOsh).setDescription(self.hostDo.description).build() if self.hostDo.servicePack: self.hostOsh.setAttribute('nt_servicepack', self.hostDo.servicePack) if self.hostDo.buildNumber: self.hostOsh.setAttribute('host_osrelease', self.hostDo.buildNumber) if self.hostDo.ntVersion: self.hostOsh.setAttribute('host_osversion', self.hostDo.ntVersion) if self.hostDo.installType: self.hostOsh.setAttribute('host_osinstalltype', self.hostDo.installType) if self.hostDo.vendor: self.hostOsh.setAttribute('host_vendor', self.hostDo.vendor) if self.hostDo.registeredOwner: self.hostOsh.setAttribute('nt_registeredowner', self.hostDo.registeredOwner) if self.hostDo.organization: self.hostOsh.setStringAttribute('nt_registrationorg', self.hostDo.organization) if self.hostDo.physicalMemory: self.hostOsh.setAttribute('nt_physicalmemory', self.hostDo.physicalMemory) if self.hostDo.biosAssetTag: self.hostOsh.setStringAttribute('bios_asset_tag', self.hostDo.biosAssetTag) if self.hostDo.osDomain: self.hostOsh.setStringAttribute('host_osdomain', self.hostDo.osDomain) if self.hostDo.winProcessorsNumber: self.hostOsh.setIntegerAttribute('nt_processorsnumber', self.hostDo.winProcessorsNumber) if self.hostDo.serialNumber: modeling.setHostSerialNumberAttribute(self.hostOsh, self.hostDo.serialNumber) if self.hostDo.hostModel: modeling.setHostModelAttribute(self.hostOsh, self.hostDo.hostModel) if self.hostDo.hostManufacturer: modeling.setHostManufacturerAttribute(self.hostOsh, self.hostDo.hostManufacturer) if self.hostDo.udUniqueId: self.hostOsh.setAttribute("ud_unique_id", self.hostDo.udUniqueId) if self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in ['1', 'true']: self.hostOsh.setBoolAttribute("pae_enabled", 1) elif self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in ['0', 'false']: self.hostOsh.setBoolAttribute("pae_enabled", 0) if self.hostDo.installType and self.hostDo.installType.encode('ascii','ignore').lower().find('ia64') != -1: self.hostDo.osArchitecture = 'ia64' elif self.hostDo.installType and self.hostDo.installType.encode('ascii','ignore').find('64') != -1: self.hostDo.osArchitecture = '64-bit' if self.hostDo.osArchitecture: self.hostOsh.setStringAttribute('os_architecture', self.hostDo.osArchitecture) modeling.setHostBiosUuid(self.hostOsh, self.hostDo.biosUUID) modeling.setHostDefaultGateway(self.hostOsh, self.hostDo.defaultGateway) modeling.setHostOsFamily(self.hostOsh, self.hostDo.osFamily) # fill in list of DNS servers if self.dnsServerIpList: list_ = StringVector(map(str, self.dnsServerIpList)) attr = AttributeStateHolder('dns_servers', list_) self.hostOsh.setListAttribute(attr) self.resultVector.add(self.hostOsh)
def build(self, unitaryComputerSystem): if unitaryComputerSystem is None: raise ValueError("unitaryComputerSystem is None") hostOsh = modeling.HostBuilder.fromClassName('vmware_esx_server') hostOsh.setStringAttribute('host_key', unitaryComputerSystem.name) hostOsh.setBoolAttribute('host_iscomplete', 1) modeling.setHostBiosUuid(hostOsh, unitaryComputerSystem.name) modeling.setHostOsFamily(hostOsh, 'baremetal_hypervisor') if unitaryComputerSystem._chassis: if unitaryComputerSystem._chassis.model: hostOsh.setStringAttribute( 'host_model', unitaryComputerSystem._chassis.model) if unitaryComputerSystem._chassis.manufacturer: hostOsh.setStringAttribute( 'host_vendor', unitaryComputerSystem._chassis.manufacturer) if unitaryComputerSystem._chassis.serialNumber: hostOsh.setStringAttribute( 'serial_number', unitaryComputerSystem._chassis.serialNumber) if unitaryComputerSystem._hypervisorSoftwareIdentity: if unitaryComputerSystem._hypervisorSoftwareIdentity.lastStartTime is not None: hostOsh.setDateAttribute( 'host_last_boot_time', unitaryComputerSystem. _hypervisorSoftwareIdentity.lastStartTime) hostName, domainName = getHostNameAndDomain( unitaryComputerSystem.elementName) if hostName: hostOsh.setStringAttribute('name', hostName) if domainName: hostOsh.setStringAttribute('host_osdomain', domainName) return hostOsh.build()
def doWMI(client, wmiOSH, ip_address, ip_domain, hostForLinkOSH, host_cmdbid=None, host_key=None, host_macs=None, ucmdb_version=None): '''@types: WmiClient, ObjectStateHolder, IPAddress, str, ObjectStateHolder, str, str, list[str], int -> ObjectStateHolderVector @param ip_address: Destination IP address ''' wmiProvider = wmiutils.getWmiProvider(client) hostDiscoverer = host_win_wmi.WmiHostDiscoverer(wmiProvider) hostInfo = hostDiscoverer.discoverHostInfo() machineName = hostInfo.hostName interfacesDiscover = networking_win_wmi.WmiInterfaceDiscoverer(wmiProvider, ip_address) vector = ObjectStateHolderVector() interfaceList = interfacesDiscover.getInterfaces() parentLinkList = ObjectStateHolderVector() isVirtual = 1 resultEmpty = 1 interfacesToUpdateList = [] for interface in interfaceList: ips = interface.ips MACAddress = interface.macAddress masks = interface.masks Description = interface.description dhcpEnabled = interface.dhcpEnabled resultEmpty = 0 for ipIndex, ipAddress in enumerate(__iterate_valid_ips(ips)): IPSubnet = (masks and masks[ipIndex]) or None if str(ip_address) == str(ipAddress): isVirtual = 0 ipOSH = modeling.createIpOSH(ipAddress) # Test if the same ip and interface are in the list allready logger.debug('Found ip address: ', ipAddress, ', MACAddress: ', MACAddress, ', IPSubnet: ', IPSubnet, ', Description: ', Description) # create OSH for IP and add it to the list # create OSH for Network and add it to the list __vector = getIPNetworkMemebrList(ipAddress, IPSubnet, '', dhcpEnabled, Description) if __vector.size() > 0: vector.addAll(__vector) if netutils.isValidMac(MACAddress): # create link interface to its ip only it has an ip defined interfaceOSH = modeling.createInterfaceOSH(MACAddress, hostForLinkOSH, Description) parentLinkList.add(modeling.createLinkOSH('containment', interfaceOSH, ipOSH)) interfacesToUpdateList.append(interfaceOSH) # Check if the Input IP is virtual, we do not want to return the WMI if isVirtual == 1: logger.warn('Destination is not among discovered IPs assuming virtual. WMI object will not be reported.') vIPOSH = modeling.createIpOSH(ip_address) vIPOSH.setBoolAttribute('isvirtual', 1) vector.add(vIPOSH) if resultEmpty == 1: logger.warn('WMI was able to connect, but WMI Query returns no results') vector.clear() return vector # create the host and all the objects if len(interfaceList) > 0: hostOSH = None try: hostOSH = modeling.createCompleteHostOSHByInterfaceList('nt', interfaceList, 'Windows', machineName, None, host_cmdbid, host_key, host_macs, ucmdb_version) except: hostOSH = modeling.createHostOSH(str(ip_address), 'nt') logger.debugException('Could not find a valid MAC address for key on ip : %s. Creating incomplete host\n' % ip_address) logger.warn('Could not find a valid MAC address for key on ip : %s. Creating incomplete host\n' % ip_address) # select from Win32_OperatingSystem _wmiQuery = 'select Caption,Version,ServicePackMajorVersion,ServicePackMinorVersion,BuildNumber,Organization,RegisteredUser,TotalVisibleMemorySize,LastBootUpTime,OtherTypeDescription,description from Win32_OperatingSystem' resultSet = client.executeQuery(_wmiQuery) # @@CMD_PERMISION wmi protocol execution osinstalltype = None if resultSet.next(): Caption = resultSet.getString(1) Version = resultSet.getString(2) ServicePackMajorVersion = resultSet.getString(3) ServicePackMinorVersion = resultSet.getString(4) BuildNumber = resultSet.getString(5) Organization = resultSet.getString(6) RegisteredUser = resultSet.getString(7) TotalVisibleMemorySize = resultSet.getString(8) LastBootUpTime = resultSet.getString(9) OtherTypeDescription = resultSet.getString(10) description = resultSet.getString(11) (vendor, osName, osinstalltype) = separateCaption(Caption, OtherTypeDescription) hostOSH.setAttribute('host_vendor', vendor) modeling.setHostOsName(hostOSH, osName) hostOSH.setAttribute('host_osinstalltype', osinstalltype) setLastBootUpTime(hostOSH, LastBootUpTime) biosUUID = getBIOSUUID(client) defaultGateway = getDefaultGateway(client) hostOSH.setAttribute('host_osversion', Version) sp = ServicePackMajorVersion + '.' + ServicePackMinorVersion if checkSpVersion(sp): hostOSH.setAttribute('nt_servicepack', sp) hostOSH.setAttribute('host_osrelease', str(BuildNumber)) hostOSH.setAttribute('nt_registrationorg', Organization) hostOSH.setAttribute('nt_registeredowner', RegisteredUser) hostOSH.setAttribute('nt_physicalmemory', TotalVisibleMemorySize) hostOSH.setAttribute('host_hostname', machineName) modeling.setHostBiosUuid(hostOSH, biosUUID) modeling.setHostDefaultGateway(hostOSH, defaultGateway) modeling.setHostOsFamily(hostOSH, 'windows') hostOSH = HostBuilder(hostOSH).setDescription(description).build() _wmiQuery2 = 'select Manufacturer,NumberOfProcessors,Model,Domain from Win32_ComputerSystem' resultSet = client.executeQuery(_wmiQuery2) # @@CMD_PERMISION wmi protocol execution if resultSet.next(): Manufacturer = resultSet.getString(1) if ((Manufacturer != None) and (Manufacturer.find('system manufacturer') == -1)): modeling.setHostManufacturerAttribute(hostOSH, Manufacturer.strip()) NumberOfProcessors = resultSet.getString(2) hostOSH.setAttribute('nt_processorsnumber', int(NumberOfProcessors)) Model = resultSet.getString(3) modeling.setHostModelAttribute(hostOSH, Model) osDomain = resultSet.getString(4) hostOSH.setAttribute('host_osdomain', osDomain.strip()) biosAssetTag = hostDiscoverer.getBiosAssetTag() if biosAssetTag: hostOSH.setAttribute('bios_asset_tag', biosAssetTag) _wmiQuery4 = 'SELECT SerialNumber FROM Win32_BIOS' resultSet = client.executeQuery(_wmiQuery4) # @@CMD_PERMISSION wmi protocol execution if resultSet.next(): serialNumber = processSerialNumber(resultSet.getString(1)) if not serialNumber: wmiBaseBoardSerialNumber = 'SELECT SerialNumber FROM Win32_BaseBoard' resultSet = client.executeQuery(wmiBaseBoardSerialNumber) # @@CMD_PERMISION wmi protocol execution serialNumber = processSerialNumber(str(resultSet)) modeling.setHostSerialNumberAttribute(hostOSH, serialNumber) try: paeEnabled = getPAEState(client) if paeEnabled and paeEnabled.lower() in ['1', 'true']: hostOSH.setBoolAttribute('pae_enabled', 1) elif paeEnabled and paeEnabled.lower() in ['0', 'false']: hostOSH.setBoolAttribute('pae_enabled', 0) except Exception, ex: logger.warn('Failed getting PAE state. %s' % ex) try: osArchitecture = getOsArchitecture(client) if osinstalltype and osinstalltype.find('64') != -1: osArchitecture = '64-bit' if osArchitecture: hostOSH.setStringAttribute('os_architecture', osArchitecture) except Exception, ex: logger.warn('Failed getting OS Architecture value. %s' % ex)
def setHostAttributes(self): if self.hostOsh: if self.hostDo.hostName: self.hostOsh.setAttribute('host_hostname', self.hostDo.hostName) if self.hostDo.hostOsName: modeling.setHostOsName(self.hostOsh, self.hostDo.hostOsName) if self.hostDo.description: self.hostOsh = modeling.HostBuilder( self.hostOsh).setDescription( self.hostDo.description).build() if self.hostDo.servicePack: self.hostOsh.setAttribute('nt_servicepack', self.hostDo.servicePack) if self.hostDo.buildNumber: self.hostOsh.setAttribute('host_osrelease', self.hostDo.buildNumber) if self.hostDo.ntVersion: self.hostOsh.setAttribute('host_osversion', self.hostDo.ntVersion) if self.hostDo.installType: self.hostOsh.setAttribute('host_osinstalltype', self.hostDo.installType) if self.hostDo.vendor: self.hostOsh.setAttribute('host_vendor', self.hostDo.vendor) if self.hostDo.registeredOwner: self.hostOsh.setAttribute('nt_registeredowner', self.hostDo.registeredOwner) if self.hostDo.organization: self.hostOsh.setStringAttribute('nt_registrationorg', self.hostDo.organization) if self.hostDo.physicalMemory: self.hostOsh.setAttribute('nt_physicalmemory', self.hostDo.physicalMemory) if self.hostDo.biosAssetTag: self.hostOsh.setStringAttribute('bios_asset_tag', self.hostDo.biosAssetTag) if self.hostDo.osDomain: self.hostOsh.setStringAttribute('host_osdomain', self.hostDo.osDomain) if self.hostDo.winProcessorsNumber: self.hostOsh.setIntegerAttribute( 'nt_processorsnumber', self.hostDo.winProcessorsNumber) if self.hostDo.serialNumber: modeling.setHostSerialNumberAttribute(self.hostOsh, self.hostDo.serialNumber) if self.hostDo.hostModel: modeling.setHostModelAttribute(self.hostOsh, self.hostDo.hostModel) if self.hostDo.hostManufacturer: modeling.setHostManufacturerAttribute( self.hostOsh, self.hostDo.hostManufacturer) if self.hostDo.udUniqueId: self.hostOsh.setAttribute("ud_unique_id", self.hostDo.udUniqueId) if self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in [ '1', 'true' ]: self.hostOsh.setBoolAttribute("pae_enabled", 1) elif self.hostDo.paeEnabled and self.hostDo.paeEnabled.lower() in [ '0', 'false' ]: self.hostOsh.setBoolAttribute("pae_enabled", 0) if self.hostDo.installType and self.hostDo.installType.encode( 'ascii', 'ignore').lower().find('ia64') != -1: self.hostDo.osArchitecture = 'ia64' elif self.hostDo.installType and self.hostDo.installType.encode( 'ascii', 'ignore').find('64') != -1: self.hostDo.osArchitecture = '64-bit' if self.hostDo.osArchitecture: self.hostOsh.setStringAttribute('os_architecture', self.hostDo.osArchitecture) modeling.setHostBiosUuid(self.hostOsh, self.hostDo.biosUUID) modeling.setHostDefaultGateway(self.hostOsh, self.hostDo.defaultGateway) modeling.setHostOsFamily(self.hostOsh, self.hostDo.osFamily) # fill in list of DNS servers if self.dnsServerIpList: list_ = StringVector(map(str, self.dnsServerIpList)) attr = AttributeStateHolder('dns_servers', list_) self.hostOsh.setListAttribute(attr) self.resultVector.add(self.hostOsh)