コード例 #1
0
ファイル: ms_cluster.py プロジェクト: ddonnelly19/dd-git
 def buildResourcePdo(self, pdo):
     r'@types: Builder.Pdo -> ObjectStateHolder'
     osh = self.buildResource(pdo.resource)
     content = pdo.privateDetailsContent
     findResource = lambda x: type(x) in [type(u''), type('')] and x.find('------') or str(x).find('------')
     if findResource(content) != -1:
         zippedBytes = modeling.processBytesAttribute(content)[0]
         osh.setBytesAttribute('resource_properties', zippedBytes)
     return osh
コード例 #2
0
ファイル: ms_cluster.py プロジェクト: deezeesms/dd-git
 def buildResourcePdo(self, pdo):
     r'@types: Builder.Pdo -> ObjectStateHolder'
     osh = self.buildResource(pdo.resource)
     content = pdo.privateDetailsContent
     findResource = lambda x: type(x) in [type(u''), type('')] and x.find(
         '------') or str(x).find('------')
     if findResource(content) != -1:
         zippedBytes = modeling.processBytesAttribute(content)[0]
         osh.setBytesAttribute('resource_properties', zippedBytes)
     return osh
コード例 #3
0
def mainFunction(resBuffer, cfPath, shUtils, OSHVResult, protocol, Framework, lastUpdateTime):

    # Parsing the main.cf file by a reg exp that returns (Element type, name and properties)
    
    reg = '(\w+)\s([^\s]+)\s\(([^\)]+)\)'

    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    clusterName        = None
    groupName        = None
    veritasclusterOSH    = None
    vcsGroupOSH        = None
    clusterDeviceOSH        = None

    resourceNameToOSH    = {}
    nodeNameToOSH        = {}
    nodeNameToFSSWOSH    = {}

    for match in matches:

        element_type = match[0].strip()
        element_name = match[1].strip()
        element_prop = match[2].strip()

        # Handle the cluster element
        if element_type == 'cluster':
            clusterName = element_name

            veritasclusterOSH = ObjectStateHolder('veritascluster')
            veritasclusterOSH.setAttribute('data_name', clusterName)
            modeling.setAppSystemVendor(veritasclusterOSH)
            OSHVResult.add(veritasclusterOSH)

            # Create configuration file object containing the zipped main.cf
            configFileOsh = modeling.createConfigurationDocumentOSH("main.cf.properties", "NA", resBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, 'main.cf')
            OSHVResult.add(configFileOsh)

        # Handle the system element (Cluster nodes)
        elif element_type == 'system':
            nodeName = element_name

            hostOSH = shUtils.resolveHost(nodeName.strip())
            if hostOSH == None:
                continue

            hostOSH.setAttribute('host_hostname', nodeName)
            OSHVResult.add(hostOSH)
            
            clusterSoftware = modeling.createClusterSoftwareOSH(hostOSH, 'Veritas Cluster SW')
    
            memberOSH = modeling.createLinkOSH('member', veritasclusterOSH, clusterSoftware)
            OSHVResult.add(clusterSoftware)
            OSHVResult.add(memberOSH)
            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):

                # create config file object containing the zipped cf file and link it to host
                configFileName = "%s.properties" % nodeName
                configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", element_prop, clusterSoftware, modeling.MIME_TEXT_PLAIN, lastUpdateTime, nodeName)
                OSHVResult.add(configFileOsh)

            # add hostosh to nodenames map so it will be easy to access later based on nodename
            nodeNameToOSH[nodeName] = hostOSH
            nodeNameToFSSWOSH[nodeName] = clusterSoftware

        # Handle the group element
        elif element_type == 'group':
            groupName = element_name

            clusterDeviceOSH = ObjectStateHolder('clusteredservice')
            clusterDeviceOSH.setAttribute('data_name', groupName)
            clusterName = veritasclusterOSH.getAttribute('data_name').getValue()
            clusterDeviceOSH.setAttribute('host_key', '%s:%s' % (clusterName, groupName))
            clusterDeviceOSH.setBoolAttribute('host_iscomplete', 1)

            containsOSH = modeling.createLinkOSH('contained', veritasclusterOSH, clusterDeviceOSH)
            OSHVResult.add(clusterDeviceOSH)
            OSHVResult.add(containsOSH)

#            for clusterSoftware in clusterSoftwares:
#                runOSH = modeling.createLinkOSH('run', clusterSoftware, clusterDeviceOSH)
#                OSHVResult.add(runOSH)

            # create group object and link it to the cluster
            vcsGroupOSH = ObjectStateHolder('vcsgroup')
            vcsGroupOSH.setAttribute('data_name', groupName)
            vcsGroupOSH.setContainer(clusterDeviceOSH)
            OSHVResult.add(vcsGroupOSH)

            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):

                # create config file object containing the current group related section in cf file, zipped and link it to cluster
                configFileName = "%s.properties" % groupName
                configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", element_prop, vcsGroupOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, groupName)
                OSHVResult.add(configFileOsh)

            m = re.search('SystemList\s*\=\s*\{(.*)\}', element_prop, re.M)
            if m:
                systemList = m.group(1)
                systemsWithPriorities = getSystemsWithPriorities(systemList)
                for nodeName, priority in systemsWithPriorities.items():
                    if nodeNameToFSSWOSH.has_key(nodeName):
                        clusterSoftware = nodeNameToFSSWOSH[nodeName]
                        ownerOSH = modeling.createLinkOSH('potentially_run', clusterSoftware, clusterDeviceOSH)
                        if priority == 0:
                            ownerOSH.setAttribute('data_name', 'Preferred Owner')
                            ownerOSH.setBoolAttribute('is_owner', 1)
                        else:
                            ownerOSH.setAttribute('data_name', 'Alternate Owner')
                            ownerOSH.setBoolAttribute('is_owner', 0)

                        OSHVResult.add(ownerOSH)

        # Handle the resource element
        elif element_type != None:
            if vcsGroupOSH == None:
                continue

            resourceName = element_name

            vcsresourceOSH = ObjectStateHolder('vcsresource')
            vcsresourceOSH.setAttribute('data_name', resourceName)
            vcsresourceOSH.setAttribute('type', element_type)
            vcsresourceOSH.setContainer(vcsGroupOSH)
            OSHVResult.add(vcsresourceOSH)

            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):
                (zippedBytes, checksumValue, dataLength) = modeling.processBytesAttribute(element_prop)
                vcsresourceOSH.setBytesAttribute('resource_properties', zippedBytes)

            resourceNameToOSH[resourceName] = vcsresourceOSH
            
            # Create the real resource element behine the vcs resource and link the two objects with a depend link
            handleResource(element_name, element_type, element_prop, vcsresourceOSH, nodeNameToOSH, OSHVResult, clusterDeviceOSH)

    # Handle the resources dependencies
    reg = '([\w-]+)\srequires\s([\w-]+)'
    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    for match in matches:

        depended = match[0].strip()
        master  = match[1].strip()

        # link each resource with the resource it depends on
        dependOSH = modeling.createLinkOSH('depend', resourceNameToOSH[depended], resourceNameToOSH[master])
        OSHVResult.add(dependOSH)


    # Handle the CF included files
    reg = 'include\s\"(.*)\"'
    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    for match in matches:

        cfFileName = match.strip()
        try:
            includeFilePath = cfPath + cfFileName
            currCFBuffer = shUtils.safecat(includeFilePath)
        except:
            errorMessage = 'Failed to handle include file %s' % includeFilePath
            logger.debugException(errorMessage)
            errobj = errorobject.createError(errorcodes.FAILED_HANDLING_INCLUDE_FILE, [includeFilePath], errorMessage)
            logger.reportWarningObject(errobj)
        
        if not shUtils.getLastCmdReturnCode():
            currCFBuffer = currCFBuffer.strip()
            if (currCFBuffer != None) and (currCFBuffer != ''):
                # create configuration file object with the included cf file zipped
                configFileName = "%s.properties" % cfFileName
                configFileOsh = modeling.createConfigurationDocumentOSH(configFileName, "NA", currCFBuffer, veritasclusterOSH, modeling.MIME_TEXT_PLAIN, lastUpdateTime, cfFileName)
                OSHVResult.add(configFileOsh)
コード例 #4
0
def mainFunction(resBuffer, cfPath, shUtils, OSHVResult, protocol, Framework,
                 lastUpdateTime):

    # Parsing the main.cf file by a reg exp that returns (Element type, name and properties)

    reg = '(\w+)\s([^\s]+)\s\(([^\)]+)\)'

    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    clusterName = None
    groupName = None
    veritasclusterOSH = None
    vcsGroupOSH = None
    clusterDeviceOSH = None

    resourceNameToOSH = {}
    nodeNameToOSH = {}
    nodeNameToFSSWOSH = {}

    for match in matches:

        element_type = match[0].strip()
        element_name = match[1].strip()
        element_prop = match[2].strip()

        # Handle the cluster element
        if element_type == 'cluster':
            clusterName = element_name

            veritasclusterOSH = ObjectStateHolder('veritascluster')
            veritasclusterOSH.setAttribute('data_name', clusterName)
            modeling.setAppSystemVendor(veritasclusterOSH)
            OSHVResult.add(veritasclusterOSH)

            # Create configuration file object containing the zipped main.cf
            configFileOsh = modeling.createConfigurationDocumentOSH(
                "main.cf.properties", "NA", resBuffer, veritasclusterOSH,
                modeling.MIME_TEXT_PLAIN, lastUpdateTime, 'main.cf')
            OSHVResult.add(configFileOsh)

        # Handle the system element (Cluster nodes)
        elif element_type == 'system':
            nodeName = element_name

            hostOSH = shUtils.resolveHost(nodeName.strip())
            if hostOSH == None:
                continue

            hostOSH.setAttribute('host_hostname', nodeName)
            OSHVResult.add(hostOSH)

            clusterSoftware = modeling.createClusterSoftwareOSH(
                hostOSH, 'Veritas Cluster SW')

            memberOSH = modeling.createLinkOSH('member', veritasclusterOSH,
                                               clusterSoftware)
            OSHVResult.add(clusterSoftware)
            OSHVResult.add(memberOSH)
            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):

                # create config file object containing the zipped cf file and link it to host
                configFileName = "%s.properties" % nodeName
                configFileOsh = modeling.createConfigurationDocumentOSH(
                    configFileName, "NA", element_prop, clusterSoftware,
                    modeling.MIME_TEXT_PLAIN, lastUpdateTime, nodeName)
                OSHVResult.add(configFileOsh)

            # add hostosh to nodenames map so it will be easy to access later based on nodename
            nodeNameToOSH[nodeName] = hostOSH
            nodeNameToFSSWOSH[nodeName] = clusterSoftware

        # Handle the group element
        elif element_type == 'group':
            groupName = element_name

            clusterDeviceOSH = ObjectStateHolder('clusteredservice')
            clusterDeviceOSH.setAttribute('data_name', groupName)
            clusterName = veritasclusterOSH.getAttribute(
                'data_name').getValue()
            clusterDeviceOSH.setAttribute('host_key',
                                          '%s:%s' % (clusterName, groupName))
            clusterDeviceOSH.setBoolAttribute('host_iscomplete', 1)

            containsOSH = modeling.createLinkOSH('contained',
                                                 veritasclusterOSH,
                                                 clusterDeviceOSH)
            OSHVResult.add(clusterDeviceOSH)
            OSHVResult.add(containsOSH)

            #            for clusterSoftware in clusterSoftwares:
            #                runOSH = modeling.createLinkOSH('run', clusterSoftware, clusterDeviceOSH)
            #                OSHVResult.add(runOSH)

            # create group object and link it to the cluster
            vcsGroupOSH = ObjectStateHolder('vcsgroup')
            vcsGroupOSH.setAttribute('data_name', groupName)
            vcsGroupOSH.setContainer(clusterDeviceOSH)
            OSHVResult.add(vcsGroupOSH)

            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):

                # create config file object containing the current group related section in cf file, zipped and link it to cluster
                configFileName = "%s.properties" % groupName
                configFileOsh = modeling.createConfigurationDocumentOSH(
                    configFileName, "NA", element_prop, vcsGroupOSH,
                    modeling.MIME_TEXT_PLAIN, lastUpdateTime, groupName)
                OSHVResult.add(configFileOsh)

            m = re.search('SystemList\s*\=\s*\{(.*)\}', element_prop, re.M)
            if m:
                systemList = m.group(1)
                systemsWithPriorities = getSystemsWithPriorities(systemList)
                for nodeName, priority in systemsWithPriorities.items():
                    if nodeNameToFSSWOSH.has_key(nodeName):
                        clusterSoftware = nodeNameToFSSWOSH[nodeName]
                        ownerOSH = modeling.createLinkOSH(
                            'potentially_run', clusterSoftware,
                            clusterDeviceOSH)
                        if priority == 0:
                            ownerOSH.setAttribute('data_name',
                                                  'Preferred Owner')
                            ownerOSH.setBoolAttribute('is_owner', 1)
                        else:
                            ownerOSH.setAttribute('data_name',
                                                  'Alternate Owner')
                            ownerOSH.setBoolAttribute('is_owner', 0)

                        OSHVResult.add(ownerOSH)

        # Handle the resource element
        elif element_type != None:
            if vcsGroupOSH == None:
                continue

            resourceName = element_name

            vcsresourceOSH = ObjectStateHolder('vcsresource')
            vcsresourceOSH.setAttribute('data_name', resourceName)
            vcsresourceOSH.setAttribute('type', element_type)
            vcsresourceOSH.setContainer(vcsGroupOSH)
            OSHVResult.add(vcsresourceOSH)

            element_prop = element_prop.strip()
            if (element_prop != '') and (len(element_prop) > 3):
                (zippedBytes, checksumValue,
                 dataLength) = modeling.processBytesAttribute(element_prop)
                vcsresourceOSH.setBytesAttribute('resource_properties',
                                                 zippedBytes)

            resourceNameToOSH[resourceName] = vcsresourceOSH

            # Create the real resource element behine the vcs resource and link the two objects with a depend link
            handleResource(element_name, element_type, element_prop,
                           vcsresourceOSH, nodeNameToOSH, OSHVResult,
                           clusterDeviceOSH)

    # Handle the resources dependencies
    reg = '([\w-]+)\srequires\s([\w-]+)'
    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    for match in matches:

        depended = match[0].strip()
        master = match[1].strip()

        # link each resource with the resource it depends on
        dependOSH = modeling.createLinkOSH('depend',
                                           resourceNameToOSH[depended],
                                           resourceNameToOSH[master])
        OSHVResult.add(dependOSH)

    # Handle the CF included files
    reg = 'include\s\"(.*)\"'
    compiled = re.compile(reg)
    matches = compiled.findall(resBuffer)

    for match in matches:

        cfFileName = match.strip()
        try:
            includeFilePath = cfPath + cfFileName
            currCFBuffer = shUtils.safecat(includeFilePath)
        except:
            errorMessage = 'Failed to handle include file %s' % includeFilePath
            logger.debugException(errorMessage)
            errobj = errorobject.createError(
                errorcodes.FAILED_HANDLING_INCLUDE_FILE, [includeFilePath],
                errorMessage)
            logger.reportWarningObject(errobj)

        if not shUtils.getLastCmdReturnCode():
            currCFBuffer = currCFBuffer.strip()
            if (currCFBuffer != None) and (currCFBuffer != ''):
                # create configuration file object with the included cf file zipped
                configFileName = "%s.properties" % cfFileName
                configFileOsh = modeling.createConfigurationDocumentOSH(
                    configFileName, "NA", currCFBuffer, veritasclusterOSH,
                    modeling.MIME_TEXT_PLAIN, lastUpdateTime, cfFileName)
                OSHVResult.add(configFileOsh)