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 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 buildCallhomeEvent(ip, domain): r'@types: ip_addr._BaseIP, str -> ObjectStateHolder' callhomeEvent = ObjectStateHolder("callhome_event") callhomeEvent.setStringAttribute(TopologyConstants.ATTR_IP_ADDRESS, str(ip)) callhomeEvent.setStringAttribute(TopologyConstants.ATTR_CALLHOME_DOMAIN_NAME, domain) callhomeEvent.setStringAttribute('name', 'CallhomeEventForIP:' + str(ip)) callhomeEvent.setLongAttribute(TopologyConstants.ATTR_CALLHOME_EVENT_TIME_STAMP, System.currentTimeMillis()) return callhomeEvent
def createSeaOsh(seaAdapter, hostOsh): if seaAdapter and hostOsh: seaOsh = ObjectStateHolder('sea_adapter') seaOsh.setContainer(hostOsh) seaOsh.setStringAttribute('data_name', seaAdapter.name) if seaAdapter.speed: seaOsh.setLongAttribute('speed', seaAdapter.speed) return seaOsh
def build_vdi(self, vdi): vdi_osh = ObjectStateHolder('citrix_vdi') vdi_osh.setStringAttribute('uuid', vdi.uuid) vdi_osh.setStringAttribute('name', vdi.getLabel()) vdi_osh.setStringAttribute('location', vdi.getLocation()) vdi_osh.setLongAttribute('virtual_size', vdi.getVirtualSize()) vdi_osh.setLongAttribute('physical_utilisation', vdi.getPhysicalUtilisation()) return vdi_osh
def _buildTraceFileOsh(self, name, size=None): r'@types: str, long -> ObjectStateHolder(db_trace_file)' osh = ObjectStateHolder('db_trace_file') osh.setAttribute('name', name) if size is not None: osh.setLongAttribute('size', size) return osh
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 _buildLogFileOsh(self, name, size=None, maxSize=None): r'@types: str, long, long -> ObjectStateHolder(db_log_file)' osh = ObjectStateHolder('db_log_file') osh.setAttribute('name', name) if size is not None: osh.setLongAttribute('size', size) if maxSize is not None: osh.setLongAttribute('max_size', maxSize) return osh
def build(self, media): if media is None: raise ValueError("media is None") mediaOsh = ObjectStateHolder('vcloud_media') mediaOsh.setStringAttribute('name', media.getName()) if media.description: mediaOsh.setStringAttribute('description', media.description) if media.size.value() is not None: mediaOsh.setLongAttribute('size', media.size.value()) if media.imageType: mediaOsh.setStringAttribute('image_type', media.imageType) return mediaOsh
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 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 createZoneConfigObject(zone, resultsVector): zoneConfigOsh = ObjectStateHolder('solaris_zone_config') zoneConfigOsh.setAttribute('data_name', 'Solaris Zone Configuration') zoneConfigOsh.setAttribute('zone_name', zone.name) zoneConfigOsh.setAttribute('zone_path', zone.path) zoneConfigOsh.setAttribute('zone_status', zone.status) zoneConfigOsh.setAttribute('zone_brand', zone.brand) if zone.uuid: zoneConfigOsh.setAttribute('zone_uuid', zone.uuid) if zone.autoboot is not None: zoneConfigOsh.setBoolAttribute('zone_autoboot', zone.autoboot) if zone.limitPrivileges: zoneConfigOsh.setAttribute('limit_privileges', zone.limitPrivileges) if zone.schedulingClass: zoneConfigOsh.setAttribute('scheduling_class', zone.schedulingClass) if zone.cpuShares is not None: zoneConfigOsh.setIntegerAttribute('cpu_shares', zone.cpuShares) if zone.cpuCap is not None: zoneConfigOsh.setFloatAttribute('capped_cpu_ncpus', zone.cpuCap) if zone.dedicatedCpu: if zone.dedicatedCpu.ncpus: zoneConfigOsh.setAttribute('dedicated_cpu_ncpus', zone.dedicatedCpu.ncpus) if zone.dedicatedCpu.importance: zoneConfigOsh.setIntegerAttribute('dedicated_cpu_importance', zone.dedicatedCpu.importance) if zone.memoryCaps: if zone.memoryCaps.physicalCap is not None: zoneConfigOsh.setLongAttribute('capped_memory_physical', zone.memoryCaps.physicalCap) if zone.memoryCaps.swapCap is not None: zoneConfigOsh.setLongAttribute('capped_memory_swap', zone.memoryCaps.swapCap) if zone.memoryCaps.lockedCap is not None: zoneConfigOsh.setLongAttribute('capped_memory_locked', zone.memoryCaps.lockedCap) zoneConfigOsh.setContainer(zone.hostOsh) resultsVector.add(zoneConfigOsh) zone.configOsh = zoneConfigOsh
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
def processObjects(allObjects): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() #print 'GOT TYPE: ', attType attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": # print 'KEY ATTRIB <', attName, '> with value <', attValue, '> for CIT <', cit, '> with MAMID <', mamId, '>' if attValue != None and attValue.strip() != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) ciDict[mamId] = [mamId, cit, attributes] for ciVal in ciList: dontCreateCI = 0 #info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2]) ) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container': if dontCreateCI or prop[3] not in ciDict.keys(): # print 'MAM ID <', prop[3], '> not found!' dontCreateCI = 1 continue parent = ciDict[prop[3]] # create the container osh if parent != None: #parentId = parent[0] parentType = parent[1] parentProps = parent[2] containerOsh = ObjectStateHolder(parentType) if parentProps != None: for parentProp in parentProps: containerOsh.setAttribute(parentProp[0], parentProp[3]) createContainer = 1 #print 'Props <', prop, '>' try: if prop[1] == 'StrProp': osh.setStringAttribute(prop[0], prop[3]) elif prop[1] == 'StrListProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: osh.setListAttribute(prop[0], [prop[3]]) elif prop[1] == 'DoubleProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: osh.setDoubleAttribute(prop[0], prop[3]) elif prop[1] == 'FloatProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: osh.setFloatAttribute(prop[0], prop[3]) elif prop[1] == 'IntProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: #print '[VINAY] Got int <', prop[3], '>' osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'LongProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: #print '[VINAY] Got long <', prop[3], '>' osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'BoolProp' and prop[3] != None and prop[3] != '' and len(prop[3]) > 0: osh.setBoolAttribute(prop[0], prop[3]) elif prop[3] != None and prop[3] != '' and len(prop[3]) > 0: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) except: stacktrace = traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) logger.warn('Exception setting attribute <', prop[0], '> with value <', prop[3], '>:\n', stacktrace) pass if dontCreateCI: continue vector.add(osh) return (vector, ciDict)
def createLparProfileOsh(lparProfile, hostOsh): """ Creates the Lpar Profile Object State Holder @param lparProfile: the discovered parameters of the Lpar or VIO Server @type lparProfile: instance of the LparProfile Data Object @param hostOsh: lpar of vio server host @type hostOsh: Object State Holder of the Host CI or any of its children @return: Object State Holder for the LPar Profile """ if lparProfile: lparProfileOsh = ObjectStateHolder('ibm_lpar_profile') lparProfileOsh.setStringAttribute('data_name', lparProfile.lparProfile.name) lparProfileOsh.setContainer(hostOsh) if lparProfile.logicalSerialNumber: lparProfileOsh.setStringAttribute('logical_serial_number', lparProfile.logicalSerialNumber) if lparProfile.lparProfile.sharingMode: lparProfileOsh.setStringAttribute('sharing_mode', lparProfile.lparProfile.sharingMode) if lparProfile.lparProfile.cpuMode: lparProfileOsh.setStringAttribute('proc_mode', lparProfile.lparProfile.cpuMode) if lparProfile.lparProfile.uncapWeight is not None: lparProfileOsh.setIntegerAttribute('uncap_weight', lparProfile.lparProfile.uncapWeight) if lparProfile.powerCtrlIds: lparProfileOsh.setStringAttribute('power_ctrl_lpar_ids', lparProfile.powerCtrlIds) if lparProfile.bootMode: lparProfileOsh.setStringAttribute('boot_mode', lparProfile.bootMode) if lparProfile.lparProfile.connMonEnabled is not None: lparProfileOsh.setBoolAttribute('conn_monitoring', lparProfile.lparProfile.connMonEnabled) if lparProfile.lparProfile.maxVirtSlots is not None: lparProfileOsh.setIntegerAttribute('max_virtual_slots', lparProfile.lparProfile.maxVirtSlots) if lparProfile.autoStart is not None: lparProfileOsh.setBoolAttribute('auto_start', lparProfile.autoStart) if lparProfile.lparProfile.ioPoolIds: lparProfileOsh.setStringAttribute('lpar_io_pool_ids', lparProfile.lparProfile.ioPoolIds) if lparProfile.redunErrPathRep is not None: lparProfileOsh.setBoolAttribute('redundant_err_path_reporting', lparProfile.redunErrPathRep) if lparProfile.lparProfile.desNumHugePages is not None: lparProfileOsh.setIntegerAttribute('desired_num_huge_pages', lparProfile.lparProfile.desNumHugePages) if lparProfile.lparProfile.minNumHugePages is not None: lparProfileOsh.setIntegerAttribute('min_num_huge_pages', lparProfile.lparProfile.minNumHugePages) if lparProfile.lparProfile.maxNumHugePages is not None: lparProfileOsh.setIntegerAttribute('max_num_huge_pages', lparProfile.lparProfile.maxNumHugePages) if lparProfile.lparProfile.desCpu is not None: lparProfileOsh.setIntegerAttribute('desired_procs', lparProfile.lparProfile.desCpu) if lparProfile.lparProfile.minCpu is not None: lparProfileOsh.setIntegerAttribute('min_procs', lparProfile.lparProfile.minCpu) if lparProfile.lparProfile.maxCpu is not None: lparProfileOsh.setIntegerAttribute('max_procs', lparProfile.lparProfile.maxCpu) if lparProfile.lparProfile.desPhysCpu is not None: lparProfileOsh.setFloatAttribute('desired_proc_units', lparProfile.lparProfile.desPhysCpu) if lparProfile.lparProfile.minPhysCpu is not None: lparProfileOsh.setFloatAttribute('min_proc_units', lparProfile.lparProfile.minPhysCpu) if lparProfile.lparProfile.maxPhysCpu is not None: lparProfileOsh.setFloatAttribute('max_proc_units', lparProfile.lparProfile.maxPhysCpu) if lparProfile.lparProfile.desMem is not None: lparProfileOsh.setLongAttribute('desired_mem', lparProfile.lparProfile.desMem) if lparProfile.lparProfile.minMem is not None: lparProfileOsh.setLongAttribute('min_mem', lparProfile.lparProfile.minMem) if lparProfile.lparProfile.maxMem is not None: lparProfileOsh.setLongAttribute('max_mem', lparProfile.lparProfile.maxMem) if lparProfile.workgroupId: lparProfileOsh.setStringAttribute('work_group_id', lparProfile.workgroupId) if lparProfile.defaultProfName: lparProfileOsh.setStringAttribute('default_profile_name', lparProfile.defaultProfName) if lparProfile.profileName: lparProfileOsh.setStringAttribute('profile_name', lparProfile.profileName) if lparProfile.state: lparProfileOsh.setStringAttribute('lpar_state', lparProfile.state) if lparProfile.type: lparProfileOsh.setStringAttribute('lpar_type', lparProfile.type) if lparProfile.lparId is not None: lparProfileOsh.setIntegerAttribute('lpar_id', lparProfile.lparId) if lparProfile.lparName: lparProfileOsh.setStringAttribute('lpar_name', lparProfile.lparName) if lparProfile.lparProfile.virtSerialAdapters: lparProfileOsh.setStringAttribute('virtual_serial_adapters', lparProfile.lparProfile.virtSerialAdapters) return lparProfileOsh
def processObjects(allObjects, DateParsePattern): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) #ciDict[mamId] = [mamId, cit, attributes] #print "MAMID = ", mamId, ", CIT = ", cit, ", Attributes = ", attributes for ciVal in ciList: logger.info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2])) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container' and prop[ 3] != "" and ciDict.has_key(prop[3]): containerOsh = ciDict[prop[3]] createContainer = 1 if prop[1] == 'integer': prop[3] and prop[3].isdigit() and osh.setIntegerAttribute( prop[0], prop[3]) elif prop[1] == 'long': prop[3] and prop[3].isdigit() and osh.setLongAttribute( prop[0], prop[3]) elif prop[1] == 'enum': osh.setEnumAttribute(prop[0], int(prop[3])) elif prop[1] == 'boolean': if str(prop[3]).lower == 'false': osh.setBoolAttribute(prop[0], 0) else: osh.setBoolAttribute(prop[0], 1) elif prop[1] == 'date': if DateParsePattern != None and DateParsePattern != "": formatter = SimpleDateFormat(DateParsePattern) osh.setDateAttribute(prop[0], formatter.parseObject(prop[3])) else: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) ciDict[id] = osh return (vector, ciDict)
def createLparProfileOsh(lparProfile, hostOsh): """ Creates the Lpar Profile Object State Holder @param lparProfile: the discovered parameters of the Lpar or VIO Server @type lparProfile: instance of the LparProfile Data Object @param hostOsh: lpar of vio server host @type hostOsh: Object State Holder of the Host CI or any of its children @return: Object State Holder for the LPar Profile """ if lparProfile: lparProfileOsh = ObjectStateHolder('ibm_lpar_profile') lparProfileOsh.setStringAttribute('data_name', lparProfile.lparProfile.name) lparProfileOsh.setContainer(hostOsh) if lparProfile.logicalSerialNumber: lparProfileOsh.setStringAttribute('logical_serial_number', lparProfile.logicalSerialNumber) if lparProfile.lparProfile.sharingMode: lparProfileOsh.setStringAttribute( 'sharing_mode', lparProfile.lparProfile.sharingMode) if lparProfile.lparProfile.cpuMode: lparProfileOsh.setStringAttribute('proc_mode', lparProfile.lparProfile.cpuMode) if lparProfile.lparProfile.uncapWeight is not None: lparProfileOsh.setIntegerAttribute( 'uncap_weight', lparProfile.lparProfile.uncapWeight) if lparProfile.powerCtrlIds: lparProfileOsh.setStringAttribute('power_ctrl_lpar_ids', lparProfile.powerCtrlIds) if lparProfile.bootMode: lparProfileOsh.setStringAttribute('boot_mode', lparProfile.bootMode) if lparProfile.lparProfile.connMonEnabled is not None: lparProfileOsh.setBoolAttribute( 'conn_monitoring', lparProfile.lparProfile.connMonEnabled) if lparProfile.lparProfile.maxVirtSlots is not None: lparProfileOsh.setIntegerAttribute( 'max_virtual_slots', lparProfile.lparProfile.maxVirtSlots) if lparProfile.autoStart is not None: lparProfileOsh.setBoolAttribute('auto_start', lparProfile.autoStart) if lparProfile.lparProfile.ioPoolIds: lparProfileOsh.setStringAttribute( 'lpar_io_pool_ids', lparProfile.lparProfile.ioPoolIds) if lparProfile.redunErrPathRep is not None: lparProfileOsh.setBoolAttribute('redundant_err_path_reporting', lparProfile.redunErrPathRep) if lparProfile.lparProfile.desNumHugePages is not None: lparProfileOsh.setIntegerAttribute( 'desired_num_huge_pages', lparProfile.lparProfile.desNumHugePages) if lparProfile.lparProfile.minNumHugePages is not None: lparProfileOsh.setIntegerAttribute( 'min_num_huge_pages', lparProfile.lparProfile.minNumHugePages) if lparProfile.lparProfile.maxNumHugePages is not None: lparProfileOsh.setIntegerAttribute( 'max_num_huge_pages', lparProfile.lparProfile.maxNumHugePages) if lparProfile.lparProfile.desCpu is not None: lparProfileOsh.setIntegerAttribute('desired_procs', lparProfile.lparProfile.desCpu) if lparProfile.lparProfile.minCpu is not None: lparProfileOsh.setIntegerAttribute('min_procs', lparProfile.lparProfile.minCpu) if lparProfile.lparProfile.maxCpu is not None: lparProfileOsh.setIntegerAttribute('max_procs', lparProfile.lparProfile.maxCpu) if lparProfile.lparProfile.desPhysCpu is not None: lparProfileOsh.setFloatAttribute( 'desired_proc_units', lparProfile.lparProfile.desPhysCpu) if lparProfile.lparProfile.minPhysCpu is not None: lparProfileOsh.setFloatAttribute( 'min_proc_units', lparProfile.lparProfile.minPhysCpu) if lparProfile.lparProfile.maxPhysCpu is not None: lparProfileOsh.setFloatAttribute( 'max_proc_units', lparProfile.lparProfile.maxPhysCpu) if lparProfile.lparProfile.desMem is not None: lparProfileOsh.setLongAttribute('desired_mem', lparProfile.lparProfile.desMem) if lparProfile.lparProfile.minMem is not None: lparProfileOsh.setLongAttribute('min_mem', lparProfile.lparProfile.minMem) if lparProfile.lparProfile.maxMem is not None: lparProfileOsh.setLongAttribute('max_mem', lparProfile.lparProfile.maxMem) if lparProfile.workgroupId: lparProfileOsh.setStringAttribute('work_group_id', lparProfile.workgroupId) if lparProfile.defaultProfName: lparProfileOsh.setStringAttribute('default_profile_name', lparProfile.defaultProfName) if lparProfile.profileName: lparProfileOsh.setStringAttribute('profile_name', lparProfile.profileName) if lparProfile.state: lparProfileOsh.setStringAttribute('lpar_state', lparProfile.state) if lparProfile.type: lparProfileOsh.setStringAttribute('lpar_type', lparProfile.type) if lparProfile.lparId is not None: lparProfileOsh.setIntegerAttribute('lpar_id', lparProfile.lparId) if lparProfile.lparName: lparProfileOsh.setStringAttribute('lpar_name', lparProfile.lparName) if lparProfile.lparProfile.virtSerialAdapters: lparProfileOsh.setStringAttribute( 'virtual_serial_adapters', lparProfile.lparProfile.virtSerialAdapters) return lparProfileOsh
def processObjects(allObjects): vector = ObjectStateHolderVector() iter = allObjects.iterator() ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() attid = "" while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if cit in host_types and attName == 'id': attid = attValue attName = "" if attid == "": logger.info ('Cannot create host, no UCMDB ID supplied' ) if cit == 'person' and attName == 'identification_type': attType = 'Enum' if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 if createCi == 1: ciList.append([mamId, cit, attributes, attid]) ciDict[mamId] = [mamId, cit, attributes,attid] # # Process all the attibutes setting them into the OSH # for ciVal in ciList: id = ciVal[0] type = ciVal[1] if type in host_types: osh = modeling.createOshByCmdbId(type, ciVal[3]) else: osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container': parent = ciDict[prop[3]] if parent != None: parentId = parent[0] parentType = parent[1] parentProps = parent[2] containerOsh = ObjectStateHolder(parentType) if parentProps != None: for parentProp in parentProps: containerOsh.setAttribute(parentProp[0], parentProp[3]) createContainer = 1 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]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) return (vector, ciDict)
class MsMqQueue: def __init__(self, msMqManagerOsh, queueName=None, queueTransactionType=None, queueIsPrivateType=None, queueStorageLimit=None, queueJuornalEnabled=None, queueJournalStorageLimit=None): self.queueName = queueName self.queueTransactionType = queueTransactionType self.queueIsPrivateType = queueIsPrivateType self.queueStorageLimit = queueStorageLimit self.queueJuornalEnabled = queueJuornalEnabled self.queueJournalStorageLimit = queueJournalStorageLimit self.msMqManagerOsh = msMqManagerOsh self.queueOsh = None def setName(self, name): self.queueName = name def setTransactionType(self, transactionType): self.queueTransactionType = transactionType def setIsPrivateQueueType(self, isPrivateType): self.queueIsPrivateType = isPrivateType def setStorageLimit(self, storageLimit): try: self.queueStorageLimit = long(storageLimit) except: logger.warn( 'Message Storage Limit exceeds long capacity. Setting to zero') self.queueStorageLimit = 0 def setJournalEnabled(self, isEnabled): self.queueJuornalEnabled = isEnabled def setJournalStorageLimit(self, limit): try: self.queueJournalStorageLimit = long(limit) except: logger.warn( 'Message Journal Storage Limit exceeds long capacity. Setting to zero' ) self.queueJournalStorageLimit = 0 def buildOsh(self): if self.queueName and self.msMqManagerOsh: self.queueOsh = ObjectStateHolder('msmqqueue') self.queueOsh.setAttribute('data_name', self.queueName) queueType = '' if self.queueIsPrivateType is not None: self.queueOsh.setAttribute( 'queue_type', QUEUE_TYPE.get(self.queueIsPrivateType)) if self.queueTransactionType: self.queueOsh.setBoolAttribute("istransactional", self.queueTransactionType) if self.queueStorageLimit: self.queueOsh.setLongAttribute('message_storage_limit', self.queueStorageLimit) if self.queueJuornalEnabled: self.queueOsh.setBoolAttribute('journal_enabled', int(self.queueJuornalEnabled)) if self.queueJournalStorageLimit: self.queueOsh.setLongAttribute('journal_storage_limit', self.queueJournalStorageLimit) self.queueOsh.setContainer(self.msMqManagerOsh) def getOsh(self): return self.queueOsh def addResultsToVector(self, resultsVector): self.buildOsh() if self.queueOsh: resultsVector.add(self.queueOsh)
def processObjects(allObjects): vector = ObjectStateHolderVector() iter = allObjects.iterator() ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() attid = "" while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if cit in host_types and attName == 'id': attid = attValue attName = "" if attid == "": logger.info('Cannot create host, no UCMDB ID supplied') if cit == 'person' and attName == 'identification_type': attType = 'Enum' if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 if createCi == 1: ciList.append([mamId, cit, attributes, attid]) ciDict[mamId] = [mamId, cit, attributes, attid] # # Process all the attibutes setting them into the OSH # for ciVal in ciList: id = ciVal[0] type = ciVal[1] if type in host_types: osh = modeling.createOshByCmdbId(type, ciVal[3]) else: osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container': parent = ciDict[prop[3]] if parent != None: parentId = parent[0] parentType = parent[1] parentProps = parent[2] containerOsh = ObjectStateHolder(parentType) if parentProps != None: for parentProp in parentProps: containerOsh.setAttribute( parentProp[0], parentProp[3]) createContainer = 1 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]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) return (vector, ciDict)
def processObjects(allObjects): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() #print 'GOT TYPE: ', attType attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": # print 'KEY ATTRIB <', attName, '> with value <', attValue, '> for CIT <', cit, '> with MAMID <', mamId, '>' if attValue != None and attValue.strip() != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) ciDict[mamId] = [mamId, cit, attributes] for ciVal in ciList: dontCreateCI = 0 #info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2]) ) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container': if dontCreateCI or prop[3] not in ciDict.keys(): # print 'MAM ID <', prop[3], '> not found!' dontCreateCI = 1 continue parent = ciDict[prop[3]] # create the container osh if parent != None: #parentId = parent[0] parentType = parent[1] parentProps = parent[2] containerOsh = ObjectStateHolder(parentType) if parentProps != None: for parentProp in parentProps: containerOsh.setAttribute( parentProp[0], parentProp[3]) createContainer = 1 #print 'Props <', prop, '>' try: if prop[1] == 'StrProp': osh.setStringAttribute(prop[0], prop[3]) elif prop[1] == 'StrListProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: osh.setListAttribute(prop[0], [prop[3]]) elif prop[1] == 'DoubleProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: osh.setDoubleAttribute(prop[0], prop[3]) elif prop[1] == 'FloatProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: osh.setFloatAttribute(prop[0], prop[3]) elif prop[1] == 'IntProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: #print '[VINAY] Got int <', prop[3], '>' osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'LongProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: #print '[VINAY] Got long <', prop[3], '>' osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'BoolProp' and prop[3] != None and prop[ 3] != '' and len(prop[3]) > 0: osh.setBoolAttribute(prop[0], prop[3]) elif prop[3] != None and prop[3] != '' and len( prop[3]) > 0: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) except: stacktrace = traceback.format_exception( sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) logger.warn('Exception setting attribute <', prop[0], '> with value <', prop[3], '>:\n', stacktrace) pass if dontCreateCI: continue vector.add(osh) return (vector, ciDict)
def processObjects(allObjects, DateParsePattern): vector = ObjectStateHolderVector() iter = allObjects.iterator() #ciList = [[id, type, props]] ciList = [] ciDict = {} createCi = 1 while iter.hasNext(): #attributes = [name, type, key, value] attributes = [] objectElement = iter.next() mamId = objectElement.getAttribute('mamId').getValue() cit = objectElement.getAttribute('name').getValue() if mamId != None and cit != None: # add the attributes... allAttributes = objectElement.getChildren('field') iterAtt = allAttributes.iterator() while iterAtt.hasNext(): attElement = iterAtt.next() attName = attElement.getAttribute('name').getValue() attType = attElement.getAttribute('datatype').getValue() attKey = attElement.getAttribute('key') attValue = attElement.getText() if attType == None or attType == "": attType = "string" if attKey == None or attKey == "": attKey = "false" else: attKey = attKey.getValue() if attName != "" and attType != "": attributes.append([attName, attType, attKey, attValue]) # create CI or not? Is key empty or none? if attKey == "true": if attValue != None and attValue != "": createCi = 1 else: createCi = 0 #info (concatenate("Id: ", mamId, ", Type: ", cit, ", Properties: ", attributes)) if createCi == 1: ciList.append([mamId, cit, attributes]) #ciDict[mamId] = [mamId, cit, attributes] #print "MAMID = ", mamId, ", CIT = ", cit, ", Attributes = ", attributes for ciVal in ciList: logger.info("\tAdding %s [%s] => [%s]" % (ciVal[1], ciVal[0], ciVal[2]) ) id = ciVal[0] type = ciVal[1] osh = ObjectStateHolder(type) if ciVal[2] != None: props = ciVal[2] createContainer = 0 containerOsh = None for prop in props: if prop[0] == 'root_container' and prop[3] != "" and ciDict.has_key(prop[3]): containerOsh = ciDict[prop[3]] createContainer = 1 if prop[1] == 'integer': prop[3] and prop[3].isdigit() and osh.setIntegerAttribute(prop[0], prop[3]) elif prop[1] == 'long': prop[3] and prop[3].isdigit() and osh.setLongAttribute(prop[0], prop[3]) elif prop[1] == 'enum': osh.setEnumAttribute(prop[0], int(prop[3])) elif prop[1] == 'boolean': if str(prop[3]).lower == 'false': osh.setBoolAttribute(prop[0], 0) else: osh.setBoolAttribute(prop[0], 1) elif prop[1] == 'date': if DateParsePattern != None and DateParsePattern != "": formatter = SimpleDateFormat(DateParsePattern) osh.setDateAttribute(prop[0], formatter.parseObject(prop[3])) else: osh.setAttribute(prop[0], prop[3]) if createContainer == 1: osh.setContainer(containerOsh) vector.add(osh) ciDict[id] = osh return (vector, ciDict)
class MsMqQueue: def __init__(self, msMqManagerOsh, queueName = None, queueTransactionType=None, queueIsPrivateType=None, queueStorageLimit=None, queueJuornalEnabled=None, queueJournalStorageLimit=None): self.queueName = queueName self.queueTransactionType = queueTransactionType self.queueIsPrivateType = queueIsPrivateType self.queueStorageLimit = queueStorageLimit self.queueJuornalEnabled = queueJuornalEnabled self.queueJournalStorageLimit = queueJournalStorageLimit self.msMqManagerOsh = msMqManagerOsh self.queueOsh = None def setName(self, name): self.queueName = name def setTransactionType(self, transactionType): self.queueTransactionType = transactionType def setIsPrivateQueueType(self, isPrivateType): self.queueIsPrivateType = isPrivateType def setStorageLimit(self, storageLimit): try: self.queueStorageLimit = long(storageLimit) except: logger.warn('Message Storage Limit exceeds long capacity. Setting to zero') self.queueStorageLimit = 0 def setJournalEnabled(self, isEnabled): self.queueJuornalEnabled = isEnabled def setJournalStorageLimit(self, limit): try: self.queueJournalStorageLimit = long(limit) except: logger.warn('Message Journal Storage Limit exceeds long capacity. Setting to zero') self.queueJournalStorageLimit = 0 def buildOsh(self): if self.queueName and self.msMqManagerOsh: self.queueOsh = ObjectStateHolder('msmqqueue') self.queueOsh.setAttribute('data_name', self.queueName) queueType = '' if self.queueIsPrivateType is not None: self.queueOsh.setAttribute('queue_type', QUEUE_TYPE.get(self.queueIsPrivateType)) if self.queueTransactionType: self.queueOsh.setBoolAttribute("istransactional", self.queueTransactionType) if self.queueStorageLimit: self.queueOsh.setLongAttribute('message_storage_limit', self.queueStorageLimit) if self.queueJuornalEnabled: self.queueOsh.setBoolAttribute('journal_enabled', int(self.queueJuornalEnabled)) if self.queueJournalStorageLimit: self.queueOsh.setLongAttribute('journal_storage_limit', self.queueJournalStorageLimit) self.queueOsh.setContainer(self.msMqManagerOsh) def getOsh(self): return self.queueOsh def addResultsToVector(self, resultsVector): self.buildOsh() if self.queueOsh: resultsVector.add(self.queueOsh)