def updateCiDictionary(ciDictionary, addRefXml): try: allRefChildren = addRefXml.getRootElement().getChild('data').getChild('objects').getChildren('Object') iter = allRefChildren.iterator() while iter.hasNext(): currentCIElement = iter.next() realId = currentCIElement.getAttributeValue('id') externalId = ExternalIdUtil.restoreExternalCiId(realId) ciDictionary.put(realId, externalId.getPropertyValue('ID')) except: logger.debug('No referenced CIs')
def updateCiDictionary(ciDictionary, addRefXml): try: allRefChildren = addRefXml.getRootElement().getChild("data").getChild("objects").getChildren("Object") iter = allRefChildren.iterator() while iter.hasNext(): currentCIElement = iter.next() realId = currentCIElement.getAttributeValue("id") externalId = ExternalIdUtil.restoreExternalCiId(realId) ciDictionary.put(realId, externalId.getPropertyValue("ID")) except: logger.debug("No referenced CIs")
def processCis(allObjectChildren, client, ciDictionary, objectMappings, action, updateStatus): iter = allObjectChildren.iterator() while iter.hasNext(): objectElement = iter.next() table = objectElement.getAttributeValue('name') id = objectElement.getAttributeValue('id') mode = objectElement.getAttributeValue('mode') operation = objectElement.getAttributeValue('operation') attributesMap = HashMap() fieldChildren = objectElement.getChildren('field') if fieldChildren is not None: iter2 = fieldChildren.iterator() while iter2.hasNext(): fieldElement = iter2.next() fieldName = fieldElement.getAttributeValue('name') fieldValue = fieldElement.getText() attributesMap.put(fieldName,fieldValue) isKey = fieldElement.getAttributeValue('key') objId = CmdbObjectID.Factory.restoreObjectID(id) newId = objId.getPropertyValue(ID_KEY) externalId = None if (newId is None): #if this is CMDB id cmdbId = objId.getPropertyValue('internal_id') newId = str(client.getNextCounter()) attributesMap.put('ID', newId) propArray = [TypesFactory.createProperty(ID_KEY, attributesMap.get(ID_KEY))] className = objId.getType() externalId = ExternalIdFactory.createExternalCiId(className, propArray) objectMappings.put(cmdbId, externalId) else: logger.info('objId is external and objId.getPropertyValue is ', newId) externalId = ExternalIdUtil.restoreExternalCiId(objId.toString()) attributesMap.put('ID', newId) ciDictionary.put(id, newId) if (action == ADD): client.executeInsert(table, attributesMap, updateStatus, externalId) elif (action == UPDATE): client.executeUpdate(table, attributesMap, newId, updateStatus, externalId) elif (action == DELETE): client.executeDelete(table, attributesMap, newId, updateStatus, externalId)
def processCis(allObjectChildren, client, ciDictionary, objectMappings, action, updateStatus): iter = allObjectChildren.iterator() while iter.hasNext(): objectElement = iter.next() table = objectElement.getAttributeValue("name") id = objectElement.getAttributeValue("id") mode = objectElement.getAttributeValue("mode") operation = objectElement.getAttributeValue("operation") attributesMap = HashMap() fieldChildren = objectElement.getChildren("field") if fieldChildren is not None: iter2 = fieldChildren.iterator() while iter2.hasNext(): fieldElement = iter2.next() fieldName = fieldElement.getAttributeValue("name") fieldValue = fieldElement.getText() attributesMap.put(fieldName, fieldValue) isKey = fieldElement.getAttributeValue("key") objId = CmdbObjectID.Factory.restoreObjectID(id) newId = objId.getPropertyValue(ID_KEY) externalId = None if newId is None: # if this is CMDB id cmdbId = objId.getPropertyValue("internal_id") newId = str(client.getNextCounter()) attributesMap.put("ID", newId) propArray = [TypesFactory.createProperty(ID_KEY, attributesMap.get(ID_KEY))] className = objId.getType() externalId = ExternalIdFactory.createExternalCiId(className, propArray) objectMappings.put(cmdbId, externalId) else: logger.info("objId is external and objId.getPropertyValue is ", newId) externalId = ExternalIdUtil.restoreExternalCiId(objId.toString()) attributesMap.put("ID", newId) ciDictionary.put(id, newId) if action == ADD: client.executeInsert(table, attributesMap, updateStatus, externalId) elif action == UPDATE: client.executeUpdate(table, attributesMap, newId, updateStatus, externalId) elif action == DELETE: client.executeDelete(table, attributesMap, newId, updateStatus, externalId)