class OshBuilder(CiBuilder): def __init__(self, targetCiType): self.__type = targetCiType self.__osh = ObjectStateHolder(self.__type) def setCiAttribute(self, name, value): attributeType = self.__getAttributeType(self.__type, name) self.__setValue(name, attributeType, value) def build(self): return self.__osh def __setValue(self, name, attributeType, value): if attributeType == 'string': self.__osh.setStringAttribute(name, value) elif attributeType == 'integer': self.__osh.setIntegerAttribute(name, int(value)) elif attributeType.endswith('enum'): self.__osh.setAttribute(name, value) else: raise ValueError('no setter defined for type %s' % attributeType) def __getAttributeType(self, ciType, attributeName): #TODO: memoize this function try: attributeDefinition = modeling._CMDB_CLASS_MODEL.getAttributeDefinition(ciType, attributeName) return attributeDefinition.getType() except: logger.errorException("%s.%s" % (ciType, attributeName)) raise ValueError("Failed to determine type of %s.%s" % (ciType, attributeName))
def build(self, fcPort): ''' @param fcPort: fcPort DO @return: fcport OSH ''' if not fcPort: raise ValueError("fcPort object is None") fcPortOsh = ObjectStateHolder("fcport") if fcPort.id is not None: fcPortOsh.setIntegerAttribute("fcport_portid", fcPort.id) if fcPort.index is not None: fcPortOsh.setIntegerAttribute("port_index", fcPort.index) wwnFormated = '' try: wwnFormated = str(wwn.parse_from_str(fcPort.wwn)) except: logger.debug('error about fcPort.wwn: %s' % fcPort.wwn) fcPort.wwn and fcPortOsh.setStringAttribute("fcport_wwn", wwnFormated) fcPort.name and fcPortOsh.setStringAttribute("fcport_symbolicname", fcPort.name) fcPort.status and fcPortOsh.setStringAttribute("fcport_status", fcPort.status) fcPort.state and fcPortOsh.setStringAttribute("fcport_state", fcPort.state) fcPort.portType and fcPortOsh.setStringAttribute("fcport_type", fcPort.portType) if fcPort.maxSpeedGbps is not None: fcPortOsh.setAttribute("fcport_maxspeed", fcPort.maxSpeedGbps) if fcPort.speedGbps is not None: fcPortOsh.setAttribute("fcport_speed", fcPort.speedGbps) return fcPortOsh
def buildProcessOsh(self, process): if not process: raise ValueError, "process is empty" #shallow copy to not affect original DO cleanProcess = copy.copy(process) self._sanitizer.sanitize(cleanProcess) processOSH = ObjectStateHolder('process') processOSH.setStringAttribute('name', cleanProcess.getName()) if cleanProcess.commandLine: processOSH.setStringAttribute('process_cmdline', cleanProcess.commandLine) if cleanProcess.getPid() is not None: processOSH.setIntegerAttribute('process_pid', cleanProcess.getPid()) if cleanProcess.executablePath: processOSH.setStringAttribute('process_path', cleanProcess.executablePath) if cleanProcess.argumentLine: processOSH.setStringAttribute('process_parameters', cleanProcess.argumentLine) if cleanProcess.owner: processOSH.setStringAttribute('process_user', cleanProcess.owner) if cleanProcess.getStartupTime() is not None: processOSH.setDateAttribute('process_startuptime', cleanProcess.getStartupTime()) if cleanProcess.description is not None: processOSH.setStringAttribute('data_description', cleanProcess.description) return processOSH
def build(self, domain): if domain is None: raise ValueError("domain is None") ldomConfigOsh = ObjectStateHolder('ldom_config') ldomConfigOsh.setAttribute('name', "LDOM Config") if domain.getName() is not None: ldomConfigOsh.setStringAttribute('ldom_name', domain.getName()) if domain.getMac() is not None: ldomConfigOsh.setStringAttribute('ldom_mac', domain.getMac()) if domain.hostId: ldomConfigOsh.setStringAttribute('ldom_hostid', domain.hostId) if domain.getUuid(): ldomConfigOsh.setStringAttribute('ldom_uuid', domain.getUuid()) ldomConfigOsh.setStringAttribute('ldom_state', domain.state.value().value()) ldomConfigOsh.setIntegerAttribute('ldom_ncpu', domain.ncpu.value()) if domain.memorySize.value() is not None: memorySizeMegabytes = int(domain.memorySize.value() / (1024*1024)) ldomConfigOsh.setIntegerAttribute('ldom_memory_size', int(memorySizeMegabytes)) if domain.roles.has(ldom.Domain.ROLE_CONTROL): ldomConfigOsh.setBoolAttribute("ldom_is_control", 1) if domain.roles.has(ldom.Domain.ROLE_IO): ldomConfigOsh.setBoolAttribute("ldom_is_io", 1) if domain.failurePolicy: ldomConfigOsh.setStringAttribute("ldom_failure_policy", domain.failurePolicy) return ldomConfigOsh
def createInterfaceIndexOsh(networkInterface, hostOsh): if hostOsh and networkInterface and networkInterface.interfaceIndex and networkInterface.speed: ifaceIndexOsh = ObjectStateHolder('interfaceindex') ifaceIndexOsh.setContainer(hostOsh) ifaceIndexOsh.setIntegerAttribute('interfaceindex_index', networkInterface.interfaceIndex) ifaceIndexOsh.setDoubleAttribute('interfaceindex_speed', networkInterface.speed) return ifaceIndexOsh
def osh_createDdfOsh(db2SubsystemOsh, ddfObj): str_name = 'name' if UCMDB_VERSION < 9: str_name = 'data_name' _vector = ObjectStateHolderVector() if isNotNull(ddfObj.locationName): ddfOsh = ObjectStateHolder('db2_ddf') ddfOsh.setAttribute(str_name, ddfObj.locationName) ddfOsh.setAttribute('ddf_status', ddfObj.status) ddfOsh.setAttribute('ddf_luname', ddfObj.locationLuName) ddfOsh.setAttribute('ddf_generic_luname', ddfObj.locationGenericLuName) ddfOsh.setAttribute('ddf_ip_address', ddfObj.ipAddress) if isNotNull(ddfObj.ipAddress) and isnumeric(ddfObj.ipAddress): ddfOsh.setAttribute('ddf_tcp_port', int(ddfObj.tcpPort)) ddfOsh.setAttribute('ddf_sql_domain', ddfObj.sqlDomain) ddfOsh.setContainer(db2SubsystemOsh) _vector.add(ddfOsh) for alias in ddfObj.ddfAlias: ddfAliasOsh = ObjectStateHolder('db2_ddf_alias') ddfAliasOsh.setAttribute(str_name, alias.aliasName) if isNotNull(alias.aliasPort) and isnumeric(alias.aliasPort): ddfAliasOsh.setIntegerAttribute('ddf_alias_port', int(alias.aliasPort)) ddfAliasOsh.setContainer(ddfOsh) _vector.add(ddfAliasOsh) return _vector
def discoverPhysicalDiskByWmi(shell, OSHVec, hostOSH): wmiProvider = wmiutils.getWmiProvider(shell) queryBuilder = wmiProvider.getBuilder('Win32_DiskDrive') queryBuilder.addWmiObjectProperties('DeviceID', 'SerialNumber', 'Size') wmiAgent = wmiProvider.getAgent() diskDevices = [] try: diskDevices = wmiAgent.getWmiData(queryBuilder) except: logger.debugException('Failed getting physical disk via wmi') for diskDevice in diskDevices: diskOsh = ObjectStateHolder("disk_device") diskName = diskDevice.DeviceID and diskDevice.DeviceID.strip() or None if diskName: diskOsh.setStringAttribute("name", diskName.upper()) else: continue diskSerialNumber = diskDevice.SerialNumber and diskDevice.SerialNumber.strip( ) or None if diskSerialNumber: diskOsh.setStringAttribute("serial_number", diskSerialNumber) diskOsh.setStringAttribute("disk_type", "fixed_disk") diskSize = diskDevice.Size and diskDevice.Size.strip() or None # Byte to MB if diskSize: diskSize = int(diskSize) / 0x100000 diskOsh.setIntegerAttribute("disk_size", diskSize) diskOsh.setContainer(hostOSH) OSHVec.add(diskOsh)
def createVlanOshv(vlMap, portOshMap): vlanHostOshMap = {} oshv = ObjectStateHolderVector() # process VLANs for (vlanId, vlanObj) in vlMap.items(): ports = vlanObj.ports ports.sort() for portId in ports: if notNull(portOshMap) and portOshMap.has_key(portId): vlanOsh = ObjectStateHolder('vlan') vlanOsh.setIntegerAttribute('vlan_number', int(vlanObj.vlanId)) vlanOsh.setAttribute('vlan_aliasname', vlanObj.name) vlanOsh.setAttribute('data_name', vlanObj.vlanId) if vlanHostOshMap.has_key(vlanObj.vlanId): hostOsh = vlanHostOshMap[vlanObj.vlanId] else: hostOsh = portOshMap[portId].getAttributeValue('root_container') oshv.add(vlanOsh) vlanHostOshMap[vlanObj.vlanId] = hostOsh vlanOsh.setContainer(hostOsh) membershipLink = modeling.createLinkOSH("member", portOshMap[portId], vlanOsh) oshv.add(membershipLink) return oshv
def osh_createDsgAndMemberOsh(db2SubsystemName, db2SubsystemOsh, dsg): str_name = 'name' str_membership = 'membership' if UCMDB_VERSION < 9: str_name = 'data_name' str_membership = 'member' _vector = ObjectStateHolderVector() if isNotNull(dsg) and isNotNull(dsg.name): dsgOsh = ObjectStateHolder('db2_datasharing_group') dsgOsh.setAttribute(str_name, dsg.name) dsgOsh.setAttribute('group_attach_name', dsg.attachName) dsgOsh.setAttribute('group_mode', dsg.mode) if isNotNull(dsg.level) and isnumeric(dsg.level): dsgOsh.setIntegerAttribute('group_level', int(dsg.level)) if isNotNull(dsg.protocolLevel) and isnumeric(dsg.protocolLevel): dsgOsh.setIntegerAttribute('group_protocol_level', int(dsg.protocolLevel)) _vector.add(dsgOsh) for member in dsg.members: if isNotNull(member) and isNotNull(member.db2Member) and isNotNull(member.subsys) and upper(member.subsys) == db2SubsystemName: dsgMemberOsh = ObjectStateHolder('db2_datasharing_group_member') dsgMemberOsh.setAttribute(str_name, member.db2Member) dsgMemberOsh.setAttribute('member_id', member.id) dsgMemberOsh.setAttribute('member_level', member.db2Level) dsgMemberOsh.setAttribute('member_status', member.status) dsgMemberOsh.setContainer(db2SubsystemOsh) _vector.add(dsgMemberOsh) # if DSG Member available, make subsystem member of DSB --------s memberLinkOsh = modeling.createLinkOSH(str_membership, dsgOsh, db2SubsystemOsh) _vector.add(memberLinkOsh) return _vector
def createResourceGroupObject(resourceGroup, clusteredServerOsh, resultsVector): resourceGroupOsh = ObjectStateHolder('sunresourcegroup') resourceGroupOsh.setAttribute('data_name', resourceGroup.name) resourceGroupOsh.setContainer(clusteredServerOsh) resourceGroupOsh.setAttribute('mode', resourceGroup.mode) if resourceGroup.description: resourceGroupOsh.setAttribute('data_description', resourceGroup.description) if resourceGroup.maxPrimaries is not None: resourceGroupOsh.setIntegerAttribute('maximum_primaries', resourceGroup.maxPrimaries) if resourceGroup.desiredPrimaries is not None: resourceGroupOsh.setIntegerAttribute('desired_primaries', resourceGroup.desiredPrimaries) if resourceGroup.isManaged is not None: resourceGroupOsh.setBoolAttribute('is_managed', resourceGroup.isManaged) if resourceGroup.isSystem is not None: resourceGroupOsh.setBoolAttribute('is_system', resourceGroup.isSystem) if resourceGroup.isFailback is not None: resourceGroupOsh.setBoolAttribute('failback', resourceGroup.isFailback) if resourceGroup.autoStartOnNewCluster is not None: resourceGroupOsh.setBoolAttribute('auto_start_on_new_cluster', resourceGroup.autoStartOnNewCluster) resultsVector.add(resourceGroupOsh) return resourceGroupOsh
def osh_createEviewOsh(localshell, zOsOsh, appPath, confFolder, file, nodeName, eviewVersion, defaultIp): # Create EView agent OSH --------------------------------------------------- logger.debug('Creating EView object') eviewOSH = ObjectStateHolder('eview') if _CMDB_CLASS_MODEL.version() >= 9: eviewOSH.setAttribute('name', nodeName) eviewOSH.setAttribute('discovered_product_name', nodeName) eviewOSH.setAttribute('version', eviewVersion) else: eviewOSH.setAttribute('data_name', nodeName) eviewOSH.setAttribute('application_version', eviewVersion) eviewOSH.setAttribute('application_path', appPath) eviewOSH.setAttribute('application_ip', defaultIp) eviewOSH.setAttribute('vendor', 'EView Technology Inc.') eviewOSH.setAttribute('eview_agent_type', 'z/OS') fileContents = localshell.safecat('%s%s' % (confFolder, file)) address, port = eview_lib.getEviewAgentAddress(localshell, fileContents) if eview_lib.isNotNull(address): eviewOSH.setAttribute('application_ip', address) if eview_lib.isNotNull(port) and eview_lib.isnumeric(port): eviewOSH.setIntegerAttribute('application_port', int(port)) eviewOSH.setContainer(zOsOsh) return eviewOSH
def discoverPhysicalDiskByWmi(shell, OSHVec, hostOSH): wmiProvider = wmiutils.getWmiProvider(shell) queryBuilder = wmiProvider.getBuilder("Win32_DiskDrive") queryBuilder.addWmiObjectProperties("DeviceID", "SerialNumber", "Size") wmiAgent = wmiProvider.getAgent() diskDevices = [] try: diskDevices = wmiAgent.getWmiData(queryBuilder) except: logger.debugException("Failed getting physical disk via wmi") for diskDevice in diskDevices: diskOsh = ObjectStateHolder("disk_device") diskName = diskDevice.DeviceID and diskDevice.DeviceID.strip() or None if diskName: diskOsh.setStringAttribute("name", diskName.upper()) else: continue diskSerialNumber = diskDevice.SerialNumber and diskDevice.SerialNumber.strip() or None if diskSerialNumber: diskOsh.setStringAttribute("serial_number", diskSerialNumber) diskOsh.setStringAttribute("disk_type", "fixed_disk") diskSize = diskDevice.Size and diskDevice.Size.strip() or None # Byte to MB if diskSize: diskSize = int(diskSize) / 0x100000 diskOsh.setIntegerAttribute("disk_size", diskSize) diskOsh.setContainer(hostOSH) OSHVec.add(diskOsh)
def createOshFromId(ciDict, id, ciClass = None): osh = None object = ciDict[id] # create the container osh if object != None: id = object[0] type = object[1] props = object[2] ciid = object[3] if type in host_types: real_ci_class = ciClass or type osh = modeling.createOshByCmdbId(real_ci_class, ciid) else: osh = ObjectStateHolder(type) if props != None: for prop in props: if prop[1] == 'Integer': osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'Long': osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'Enum': osh.setEnumAttribute(prop[0], int(prop[3])) else: osh.setAttribute(prop[0], prop[3]) return osh
def getDistributors(self,oshv,sqlServerId): #is there is a chance that we have more than one distributor? rs = self.connection.doCall(Queries.SERVER_DIST_CALL) distributor = None databaseName = None while rs.next(): name = rs.getString('distributor') if(name is None): rs.close() return None databaseName = rs.getString('distribution database') max = int(rs.getInt('max distrib retention')) min = int(rs.getInt('min distrib retention')) history = int(rs.getInt('history retention')) cleanup = String(rs.getString('history cleanup agent')) idx = cleanup.indexOf('Agent history clean up:') if(idx>=0): cleanup=cleanup.substring(len("Agent history clean up:")) distributor = ObjectStateHolder('sqlserverdistributor') sqlServer = self.createSqlServer(name,oshv,sqlServerId) distributor.setContainer(sqlServer) distributor.setAttribute(Queries.DATA_NAME,name) distributor.setIntegerAttribute('maxTxRetention',max) distributor.setIntegerAttribute('minTxRetention',min) distributor.setIntegerAttribute('historyRetention',history) distributor.setAttribute('cleanupAgentProfile',cleanup) oshv.add(sqlServer) oshv.add(distributor) database = self.getDatabase(sqlServer,databaseName) oshv.add(database) oshv.add(modeling.createLinkOSH('use',distributor,database)) rs.close() if(distributor!=None): logger.debug('we got a distributor') return [distributor,databaseName]
def build(self, domain): if domain is None: raise ValueError("domain is None") ldomConfigOsh = ObjectStateHolder("ldom_config") ldomConfigOsh.setAttribute("name", "LDOM Config") if domain.getName() is not None: ldomConfigOsh.setStringAttribute("ldom_name", domain.getName()) if domain.getMac() is not None: ldomConfigOsh.setStringAttribute("ldom_mac", domain.getMac()) if domain.hostId: ldomConfigOsh.setStringAttribute("ldom_hostid", domain.hostId) if domain.getUuid(): ldomConfigOsh.setStringAttribute("ldom_uuid", domain.getUuid()) ldomConfigOsh.setStringAttribute("ldom_state", domain.state.value().value()) ldomConfigOsh.setIntegerAttribute("ldom_ncpu", domain.ncpu.value()) if domain.memorySize.value() is not None: memorySizeMegabytes = int(domain.memorySize.value() / (1024 * 1024)) ldomConfigOsh.setIntegerAttribute("ldom_memory_size", int(memorySizeMegabytes)) if domain.roles.has(ldom.Domain.ROLE_CONTROL): ldomConfigOsh.setBoolAttribute("ldom_is_control", 1) if domain.roles.has(ldom.Domain.ROLE_IO): ldomConfigOsh.setBoolAttribute("ldom_is_io", 1) if domain.failurePolicy: ldomConfigOsh.setStringAttribute("ldom_failure_policy", domain.failurePolicy) return ldomConfigOsh
def createOshFromId(ciDict, id, ciClass=None): osh = None object = ciDict[id] # create the container osh if object != None: id = object[0] type = object[1] props = object[2] ciid = object[3] if type in host_types: real_ci_class = ciClass or type osh = modeling.createOshByCmdbId(real_ci_class, ciid) else: osh = ObjectStateHolder(type) if props != None: for prop in props: if prop[1] == 'Integer': osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'Long': osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'Enum': osh.setEnumAttribute(prop[0], int(prop[3])) else: osh.setAttribute(prop[0], prop[3]) return osh
class OshBuilder(CiBuilder): def __init__(self, targetCiType): self.__type = targetCiType self.__osh = ObjectStateHolder(self.__type) def setCiAttribute(self, name, value): attributeType = self.__getAttributeType(self.__type, name) self.__setValue(name, attributeType, value) def build(self): return self.__osh def __setValue(self, name, attributeType, value): if attributeType == 'string': self.__osh.setStringAttribute(name, value) elif attributeType == 'integer': self.__osh.setIntegerAttribute(name, int(value)) elif attributeType.endswith('enum'): self.__osh.setAttribute(name, value) else: raise ValueError('no setter defined for type %s' % attributeType) def __getAttributeType(self, ciType, attributeName): #TODO: memoize this function try: attributeDefinition = modeling._CMDB_CLASS_MODEL.getAttributeDefinition( ciType, attributeName) return attributeDefinition.getType() except: logger.errorException("%s.%s" % (ciType, attributeName)) raise ValueError("Failed to determine type of %s.%s" % (ciType, attributeName))
def getDistributors(self, oshv, sqlServerId): #is there is a chance that we have more than one distributor? rs = self.connection.doCall(Queries.SERVER_DIST_CALL) distributor = None databaseName = None while rs.next(): name = rs.getString('distributor') if (name is None): rs.close() return None databaseName = rs.getString('distribution database') max = int(rs.getInt('max distrib retention')) min = int(rs.getInt('min distrib retention')) history = int(rs.getInt('history retention')) cleanup = String(rs.getString('history cleanup agent')) idx = cleanup.indexOf('Agent history clean up:') if (idx >= 0): cleanup = cleanup.substring(len("Agent history clean up:")) distributor = ObjectStateHolder('sqlserverdistributor') sqlServer = self.createSqlServer(name, oshv, sqlServerId) distributor.setContainer(sqlServer) distributor.setAttribute(Queries.DATA_NAME, name) distributor.setIntegerAttribute('maxTxRetention', max) distributor.setIntegerAttribute('minTxRetention', min) distributor.setIntegerAttribute('historyRetention', history) distributor.setAttribute('cleanupAgentProfile', cleanup) oshv.add(sqlServer) oshv.add(distributor) database = self.getDatabase(sqlServer, databaseName) oshv.add(database) oshv.add(modeling.createLinkOSH('use', distributor, database)) rs.close() if (distributor != None): logger.debug('we got a distributor') return [distributor, databaseName]
def getClusters(self, clustersParentElement): clusterElList = clustersParentElement.getChildren('Cluster') clusters = [] for clusterEl in clusterElList: tomcatClusterOsh = ObjectStateHolder('tomcatcluster') tomcatClusterOsh.setAttribute('data_name', 'Apache Tomcat Cluster') modeling.setAppSystemVendor(tomcatClusterOsh) mcastAddress = '228.0.0.4' mcastPort = '45564' membership = clusterEl.getChild('Membership') if membership is not None: try: address = membership.getAttributeValue('mcastAddr') mcastAddress = address except: logger.debug('Failed to fetch mcast address, using default ', mcastAddress) try: port = membership.getAttributeValue('mcastPort') mcastPort = port except: logger.debug('Failed to fetch mcast port, using default ', mcastPort) tomcatClusterOsh.setAttribute('tomcatcluster_multicastaddress', mcastAddress) tomcatClusterOsh.setIntegerAttribute('tomcatcluster_multicastport', mcastPort) self.OSHVResult.add(tomcatClusterOsh) clusters.append(tomcatClusterOsh) return clusters
def getClusters(self, clustersParentElement): clusterElList = clustersParentElement.getChildren('Cluster') clusters = [] for clusterEl in clusterElList: tomcatClusterOsh = ObjectStateHolder('tomcatcluster') tomcatClusterOsh.setAttribute('data_name', 'Apache Tomcat Cluster') modeling.setAppSystemVendor(tomcatClusterOsh) mcastAddress = '228.0.0.4' mcastPort = '45564' membership = clusterEl.getChild('Membership') if membership is not None: try: address = membership.getAttributeValue('mcastAddr') mcastAddress = address except: logger.debug( 'Failed to fetch mcast address, using default ', mcastAddress) try: port = membership.getAttributeValue('mcastPort') mcastPort = port except: logger.debug('Failed to fetch mcast port, using default ', mcastPort) tomcatClusterOsh.setAttribute('tomcatcluster_multicastaddress', mcastAddress) tomcatClusterOsh.setIntegerAttribute('tomcatcluster_multicastport', mcastPort) self.OSHVResult.add(tomcatClusterOsh) clusters.append(tomcatClusterOsh) return clusters
def build(self): osh = ObjectStateHolder('logical_volume') osh.setIntegerAttribute('logicalvolume_id', int(self.volumeId)) osh.setAttribute('logicalvolume_size', self.capacityGB) osh.setAttribute('name', self.name) osh.setAttribute('logicalvolume_accesstype', self.volumeType) osh.setAttribute('logicalvolume_fstype', self.diskType) self.osh = osh return osh
def build(self, module): if module is None: raise ValueError("module is None") powerSupplyOsh = ObjectStateHolder("power_supply") powerSupplyOsh.setStringAttribute("name", module.slot) powerSupplyOsh.setStringAttribute("serial_number", module.serialNumber) powerSupplyOsh.setIntegerAttribute("power_supply_index", int(module.slotNumber)) return powerSupplyOsh
def build(self, module): if module is None: raise ValueError("module is None") fanOsh = ObjectStateHolder("fan") fanOsh.setStringAttribute("name", module.slot) fanOsh.setStringAttribute("serial_number", module.serialNumber) fanOsh.setIntegerAttribute("fan_index", int(module.slotNumber)) return fanOsh
def build(self, module): if module is None: raise ValueError("module is None") fanOsh = ObjectStateHolder("fan") fanOsh.setStringAttribute('name', module.slot) fanOsh.setStringAttribute('serial_number', module.serialNumber) fanOsh.setIntegerAttribute('fan_index', int(module.slotNumber)) return fanOsh
def buidlPort(port, switchOsh): portOsh = ObjectStateHolder('physical_port') portOsh.setContainer(switchOsh) portOsh.setIntegerAttribute('port_index', int(port.index)) if port.name: portOsh.setStringAttribute('port_displayName', port.name) if port.slot: portOsh.setStringAttribute('port_slot', port.slot) if port.vlan: portOsh.setStringAttribute('port_vlan', port.vlan) return portOsh
def build_xen_domain_config(self, vm, vm_metrics): xen_domain_config_osh = ObjectStateHolder('xen_domain_config') xen_domain_config_osh.setStringAttribute('name', 'Xen Domain Config') xen_domain_config_osh.setIntegerAttribute('xen_domain_id', int(vm['domid'])) xen_domain_config_osh.setStringAttribute('xen_domain_name', vm.getLabel()) xen_domain_config_osh.setIntegerAttribute('xen_domain_vcpus', int(vm_metrics['VCPUs_number'])) xen_domain_config_osh.setLongAttribute('xen_domain_memory', long(vm['memory_static_max'])) xen_domain_config_osh.setStringAttribute('xen_domain_on_restart', vm['actions_after_reboot']) xen_domain_config_osh.setStringAttribute('xen_domain_on_poweroff', vm['actions_after_shutdown']) xen_domain_config_osh.setStringAttribute('xen_domain_on_crash', vm['actions_after_crash']) return xen_domain_config_osh
def build(self, module): if module is None: raise ValueError("module is None") powerSupplyOsh = ObjectStateHolder("power_supply") powerSupplyOsh.setStringAttribute('name', module.slot) powerSupplyOsh.setStringAttribute('serial_number', module.serialNumber) powerSupplyOsh.setIntegerAttribute('power_supply_index', int(module.slotNumber)) return powerSupplyOsh
def build(self): osh = ObjectStateHolder('fcport') osh.setIntegerAttribute('fcport_portid', int(self.portId)) osh.setIntegerAttribute('port_index', int(self.portId)) setAttribute(osh, 'port_number', self.portId) setAttribute(osh, 'name', self.name) setAttribute(osh, 'fcport_wwn', self.wwn) setAttribute(osh, 'fcport_status', self.status) setAttribute(osh, 'fcport_state', self.state) osh.setDoubleAttribute('fcport_speed', float(self.speed)) self.osh = osh return osh
def _createFolderOsh(self, folder): folderOsh = ObjectStateHolder('ms_exchange_folder') folderOsh.setAttribute('data_name', folder._name) folderOsh.setAttribute('url', folder.Url) folderOsh.setAttribute('data_description', folder.Comment) folderOsh.setAttribute('friendly_url', folder.FriendlyUrl) folderOsh.setBoolAttribute('is_mail_enabled', folder.IsMailEnabled) folderOsh.setAttribute('address_book_name', folder.AddressBookName) folderOsh.setAttribute('administrative_note', folder.AdministrativeNote) folderOsh.setIntegerAttribute('contact_count', folder.ContactCount) return folderOsh
def build(self, vlan): if vlan is None: raise ValueError("vlan is None") if vlan.vlanId is None: raise ValueError("vlan ID is None") vlanOsh = ObjectStateHolder("vlan") vlanOsh.setIntegerAttribute("vlan_id", vlan.vlanId) if vlan.getName(): vlanOsh.setStringAttribute("name", vlan.getName()) return vlanOsh
def createRacOSH(racName, instancesNumber, serviceName, version): racOSH = ObjectStateHolder("rac") racOSH.setAttribute("data_name", racName) racOSH.setAttribute("rac_servicename", serviceName) if instancesNumber: try: racOSH.setIntegerAttribute("instancescount", int(instancesNumber)) except: logger.warn("Number of instances appeared to be a non integer value: %s" % instancesNumber) modeling.setAppSystemVendor(racOSH) if version: racOSH.setAttribute("version", version) return racOSH
def build(self, vlan): if vlan is None: raise ValueError("vlan is None") if vlan.vlanId is None: raise ValueError("vlan ID is None") vlanOsh = ObjectStateHolder('vlan') vlanOsh.setIntegerAttribute('vlan_id', vlan.vlanId) if vlan.getName(): vlanOsh.setStringAttribute('name', vlan.getName()) return vlanOsh
def __buildJmsDestination(self, destination, destinationType): '@types: jms.Destination, str -> ObjectStateHolder' osh = ObjectStateHolder('jmsdestination') osh.setAttribute('name', destination.getName()) if destination.getObjectName(): osh.setAttribute('j2eemanagedobject_objectname', destination.getObjectName()) if destination.getJndiName(): osh.setAttribute('j2eemanagedobject_jndiname', destination.getJndiName()) if destinationType: osh.setAttribute('jmsdestination_type', destinationType) messagescurrent = destination.messagesCurrentCount.value() if messagescurrent is not None: osh.setIntegerAttribute('jmsdestination_messagescurrent', messagescurrent) messagespending = destination.messagesPendingCount.value() if messagespending is not None: osh.setIntegerAttribute('jmsdestination_messagespending', messagespending) messagesreceived = destination.messagesReceivedCount.value() if messagesreceived is not None: osh.setIntegerAttribute('jmsdestination_messagesreceived', messagesreceived) consumerscurrent = destination.consumersCurrentCount.value() if consumerscurrent is not None: osh.setIntegerAttribute('jmsdestination_consumerscurrent', consumerscurrent) subscribers = destination.getDurableSubscribers() if subscribers: vectorOfNames = StringVector() for subscriber in subscribers: vectorOfNames.add(subscriber.getName()) ash = AttributeStateHolder('jmsdestination_durablesubscribers', vectorOfNames) osh.addAttributeToList(ash) return osh
def build(self, port): if port is None: raise ValueError("port is None") portIndex = port._parsedPortIndex if portIndex is None: raise ValueError("port index is None") portOsh = ObjectStateHolder("physical_port") portOsh.setIntegerAttribute("port_index", portIndex) if port.getName(): portOsh.setAttribute("name", port.getName()) return portOsh
def addOshToVector(self, resultVector): nlbNodeOSH = ObjectStateHolder('nlb_clustersoftware') nlbNodeOSH.setAttribute('vendor', 'microsoft_corp') nlbNodeOSH.setIntegerAttribute('host_priority', self.priority) nlbNodeOSH.setStringAttribute('cluster_mode_on_start', self.modeOnStart) nlbNodeOSH.setStringAttribute('data_name', 'NLB Cluster SW') clusterIp = self.nlbClusterOsh.getAttribute('cluster_ip_address').getValue() modeling.setAdditionalKeyAttribute(nlbNodeOSH, 'cluster_ip_address', clusterIp) resultVector.add(self.hostOSH) nlbNodeOSH.setContainer(self.hostOSH) if self.dedicatedIpOSH: resultVector.add(self.dedicatedIpOSH) resultVector.add(modeling.createLinkOSH('contained', self.hostOSH, self.dedicatedIpOSH)) resultVector.add(nlbNodeOSH) resultVector.add(modeling.createLinkOSH('member', self.nlbClusterOsh, nlbNodeOSH))
def build(self, port): if port is None: raise ValueError("port is None") portIndex = port._parsedPortIndex if portIndex is None: raise ValueError("port index is None") portOsh = ObjectStateHolder('physical_port') portOsh.setIntegerAttribute('port_index', portIndex) if port.getName(): portOsh.setAttribute('name', port.getName()) return portOsh
def buildSoftwareComponent(self, component): r'@types: SoftwareComponent -> ObjectStateHolder[sap_abap_software_component]' assert component, "Software component is not specified" osh = ObjectStateHolder('sap_abap_software_component') osh.setAttribute('name', component.name) osh.setAttribute('type', component.type) if component.description: osh.setStringAttribute('description', component.description) versionInfo = component.versionInfo if versionInfo: osh.setStringAttribute('release', versionInfo.release) if versionInfo.patchLevel.value() is not None: osh.setIntegerAttribute('patch_level', versionInfo.patchLevel.value()) return osh
def createRacOSH(racName, instancesNumber, serviceName, version): racOSH = ObjectStateHolder('rac') racOSH.setAttribute('data_name', racName) racOSH.setAttribute('rac_servicename', serviceName) if instancesNumber: try: racOSH.setIntegerAttribute('instancescount', int(instancesNumber)) except: logger.warn( 'Number of instances appeared to be a non integer value: %s' % instancesNumber) modeling.setAppSystemVendor(racOSH) if version: racOSH.setAttribute('version', version) return racOSH
def build(self, certificate): ''' Build ssl_certificate OSH from X509Certificate @types: X509Certificate -> ObjectStateHolderVector ''' certOsh = ObjectStateHolder('digital_certificate') certOsh.setDateAttribute("valid_to", certificate.expiresOn) certOsh.setDateAttribute("create_on", certificate.createOn) certOsh.setStringAttribute("issuer", unicode(certificate.issuer.raw)) certOsh.setStringAttribute("subject", unicode(certificate.subject.raw)) certOsh.setStringAttribute("serial_number", certificate.sn) if certificate.version: certOsh.setIntegerAttribute("version", certificate.version) if certificate.signatureAlgorithm: certOsh.setStringAttribute("signature_algorithm", certificate.signatureAlgorithm) if certificate.type: certOsh.setStringAttribute("type", certificate.type) organization = certificate.subject.dn.find_first('O') if organization: certOsh.setStringAttribute("organization", organization.value) organization_unit = certificate.subject.dn.lookup('OU') if organization_unit: ou = map(lambda obj: str(obj.value), organization_unit) certOsh.setListAttribute("organization_unit", ou) cnSubject = certificate.subject.dn.find_first('CN') if cnSubject and cnSubject.value: certOsh.setStringAttribute("common_name", cnSubject.value) cnIssuer = certificate.issuer.dn.find_first('CN') oIssuer = certificate.issuer.dn.find_first('O') issuerName = None if cnIssuer and cnIssuer.value: issuerName = cnIssuer.value else: issuerName = oIssuer and oIssuer.value certOsh.setStringAttribute("issuer_name", issuerName) isSelfSigned = certificate.subject.raw == certificate.issuer.raw certOsh.setBoolAttribute("is_self_signed", isSelfSigned) return certOsh
def build(self, containerOsh): 'host osh -> list(Cpu)' for cpu in self.getCpus(): osh = ObjectStateHolder('cpu') osh.setContainer(containerOsh) osh.setAttribute('cpu_cid', cpu.id) cpu.vendor and osh.setAttribute('cpu_vendor', cpu.vendor) if cpu.speedInMhz(): osh.setLongAttribute("cpu_clock_speed", cpu.speedInMhz()) if cpu.name: osh.setAttribute('data_name', cpu.name) if cpu.coresCount(): osh.setIntegerAttribute('core_number', cpu.coresCount()) if cpu.description: osh.setAttribute('data_description', cpu.description) cpu.osh = osh
def createResourceObject(resource, resourceGroupOsh, resultsVector): resourceOsh = ObjectStateHolder('sunclusterresource') resourceOsh.setAttribute('data_name', resource.name) resourceOsh.setContainer(resourceGroupOsh) if resource.description: resourceOsh.setAttribute('data_description', resource.description) if resource.type: resourceOsh.setAttribute('type', resource.type) if resource.failoverMode: resourceOsh.setAttribute('failover_mode', resource.failoverMode) if resource.retryCount is not None: resourceOsh.setIntegerAttribute('retry_count', resource.retryCount) if resource.retryInterval is not None: resourceOsh.setIntegerAttribute('retry_interval', resource.retryInterval) resultsVector.add(resourceOsh)
def getSqlJobs(self,oshv,sqlServerId): jobById = HashMap() rs = self.connection.getTable(Queries.SERVER_JOBS) while rs.next(): name = rs.getString('name') enabled = int(rs.getInt('enabled')) description= rs.getString('description') jobId = rs.getString('job_id') osh = ObjectStateHolder('sqljob') osh.setAttribute('sqljob_jobid',jobId) osh.setAttribute(Queries.DATA_NAME,name) osh.setIntegerAttribute('sqljob_enabled',enabled) osh.setAttribute('data_description',description) osh.setContainer(sqlServerId) oshv.add(osh) jobById.put(jobId,osh) rs.close() return jobById
def build_xen_domain_config(self, vm, vm_metrics): xen_domain_config_osh = ObjectStateHolder('xen_domain_config') xen_domain_config_osh.setStringAttribute('name', 'Xen Domain Config') xen_domain_config_osh.setIntegerAttribute('xen_domain_id', int(vm['domid'])) xen_domain_config_osh.setStringAttribute('xen_domain_name', vm.getLabel()) xen_domain_config_osh.setIntegerAttribute( 'xen_domain_vcpus', int(vm_metrics['VCPUs_number'])) xen_domain_config_osh.setLongAttribute('xen_domain_memory', long(vm['memory_static_max'])) xen_domain_config_osh.setStringAttribute('xen_domain_on_restart', vm['actions_after_reboot']) xen_domain_config_osh.setStringAttribute('xen_domain_on_poweroff', vm['actions_after_shutdown']) xen_domain_config_osh.setStringAttribute('xen_domain_on_crash', vm['actions_after_crash']) return xen_domain_config_osh
def createKvmDomainConfigOsh(domainConfig, hostOsh): if domainConfig and hostOsh: domainConfigOsh = ObjectStateHolder('kvm_domain_config') domainConfigOsh.setStringAttribute('data_name', domainConfig.name) domainConfigOsh.setContainer(hostOsh) if domainConfig.vCpus is not None: domainConfigOsh.setIntegerAttribute('kvm_domain_vcpus', domainConfig.vCpus) if domainConfig.onRestart: domainConfigOsh.setStringAttribute('kvm_domain_on_restart', domainConfig.onRestart) if domainConfig.onCrash: domainConfigOsh.setStringAttribute('kvm_domain_on_crash', domainConfig.onCrash) if domainConfig.state: domainConfigOsh.setStringAttribute('kvm_domain_state', domainConfig.state) if domainConfig.onPoweroff: domainConfigOsh.setStringAttribute('kvm_domain_on_poweroff', domainConfig.onPoweroff) if domainConfig.memory: domainConfigOsh.setLongAttribute('kvm_domain_memory', domainConfig.memory) if domainConfig.maxMemory is not None: domainConfigOsh.setLongAttribute('kvm_domain_max_memory', domainConfig.maxMemory) if domainConfig.domainName: domainConfigOsh.setStringAttribute('kvm_domain_name', domainConfig.domainName) if domainConfig.domainId is not None: domainConfigOsh.setIntegerAttribute('kvm_domain_id', domainConfig.domainId) if domainConfig.domainUuid: hostOsh.setStringAttribute('host_biosuuid', domainConfig.domainUuid.upper()) if domainConfig.domainType is None: domainConfigOsh.setStringAttribute('kvm_domain_type', 'Para-Virtualized') if domainConfig.coresPerSocket is not None: domainConfigOsh.setIntegerAttribute('kvm_cores_per_socket', domainConfig.coresPerSocket) if domainConfig.maxFreeMemory is not None: domainConfigOsh.setLongAttribute('kvm_max_free_memory', domainConfig.maxFreeMemory) if domainConfig.totalMemory is not None: domainConfigOsh.setLongAttribute('kvm_domain_memory', domainConfig.totalMemory) if domainConfig.threadsPerCore is not None: domainConfigOsh.setIntegerAttribute('kvm_threads_per_core', domainConfig.threadsPerCore) if domainConfig.freeMemory is not None: domainConfigOsh.setLongAttribute('kvm_free_memory', domainConfig.freeMemory) if domainConfig.cpuCount is not None: domainConfigOsh.setIntegerAttribute('kvm_cpu_count', domainConfig.cpuCount) if domainConfig.hvmMemory is not None: domainConfigOsh.setLongAttribute('kvm_hvm_memory', domainConfig.hvmMemory) if domainConfig.paraMemory is not None: domainConfigOsh.setLongAttribute('kvm_para_memory', domainConfig.paraMemory) return domainConfigOsh
class OshBuilder(CiBuilder): def __init__(self, targetCiType): self.__type = targetCiType self.__osh = ObjectStateHolder(self.__type) def setCiAttribute(self, name, value): attributeType = self.__getAttributeType(self.__type, name) if value: self.__setValue(name, attributeType, value) else: logger.debug("Meet none value for %s, type:%s" % (name, attributeType)) def build(self): return self.__osh def __setValue(self, name, attributeType, value): if attributeType == 'string': self.__osh.setStringAttribute(name, str(value)) elif attributeType == 'integer': self.__osh.setIntegerAttribute(name, int(value)) elif attributeType.endswith('enum'): if isinstance(value, int): self.__osh.setEnumAttribute(name, value) else: self.__osh.setAttribute(name, value) elif attributeType == 'string_list': self.__osh.setListAttribute(name, value) else: raise ValueError('no setter defined for type %s' % attributeType) def __getAttributeType(self, ciType, attributeName): try: attributeDefinition = modeling._CMDB_CLASS_MODEL.getAttributeDefinition( ciType, attributeName) return attributeDefinition.getType() except: if DEBUG: if attributeName in ['memory_size', 'port_index']: return 'integer' return 'string' raise ValueError("Failed to determine type of %s.%s" % (ciType, attributeName))
def createScpOsh(container, type, ip, port=None, context=None, hostname=None): """ @type container: str @type type: str @type ip: str @type port: str @type context: str @type hostname: str @return: ObjectStateHolder """ if not ip or not type: raise ValueError('SCP type and ip address must be specified') scpOsh = ObjectStateHolder(SCP_TYPE) scpOsh.setAttribute(ATTR_SERVICE_TYPE, type.strip()) scpOsh.setAttribute(ATTR_SERVICE_IP_ADDRESS, ip.strip()) if not port or port == 0: port = DEFAULT_PORTS.get(type) else: port = int(port) if isinstance(port, int): scpOsh.setIntegerAttribute(ATTR_SERVICE_PORT, port) else: raise ValueError('No default port defined for SCP type:', type) if context and context.isspace(): # Convert empty string to None context = None if type in [HTTP_TYPE, HTTPS_TYPE]: # Special check for http and https protocol if not context: # Use '/' as default value context = '/' else: context = context.strip() if context != '/' and context[-1] == '/': # Remove trailing slash context = context[:-1] if context: scpOsh.setAttribute(ATTR_SERVICE_CONTEXT, context) if hostname: scpOsh.setAttribute(ATTR_SERVICE_HOST_NAME, hostname.strip()) scpOsh.setContainer(container) return scpOsh
def build(self, virtualDisk): if virtualDisk is None: raise ValueError("virtualDisk is None") if not virtualDisk.getName(): raise ValueError("name of virtualDisk is empty") diskOsh = ObjectStateHolder('ldom_virtual_disk') diskOsh.setStringAttribute('name', virtualDisk.getName()) if virtualDisk.deviceName: diskOsh.setStringAttribute('vd_device', virtualDisk.deviceName) if virtualDisk.multiPathGroupName: diskOsh.setStringAttribute('vd_mpgroup', virtualDisk.multiPathGroupName) if virtualDisk.timeout.value() is not None: diskOsh.setIntegerAttribute('vd_timeout', virtualDisk.timeout.value()) if virtualDisk.diskId.value() is not None: diskOsh.setIntegerAttribute('vd_id', virtualDisk.diskId.value()) return diskOsh