Esempio n. 1
0
 def isApplicable(self, context):
     r''' Determine whether plugin can be applicable, main process 'sapstartsrv'
     is present and has path to the profile
     @types: applications.ApplicationSignatureContext -> bool
     '''
     return fptools.findFirst(hasProfileInCmdline,
                              context.application.getMainProcesses())
Esempio n. 2
0
def getCategoryByName(categoryName, categories):
    '''
    string, list[category] -> Category or None
    '''
    if not categories:
        return None
    return fptools.findFirst(lambda c: c.getName() == categoryName, categories)
Esempio n. 3
0
 def isApplicable(self, context):
     r''' @types: applications.ApplicationSignatureContext '''
     return (isinstance(context.client, shellutils.Shell)
             # has daemon process
             and findFirst(isMainTrexProcess,
                     context.application.getProcesses()) is not None
     )
Esempio n. 4
0
def discoverEsxVirtualTopology(ipAddress, credentialsId, esxBiosUuid, framework):
    client = None
    try:
        client = cim_discover.createClient(framework, ipAddress, vmware_cim_discover.CimNamespace.ESXV2, credentialsId)
        
        esxList = vmware_cim_discover.getVmwareEsxComputerSystems(client)

        isValidEsxFn = fptools.partiallyApply(_esxMatchesBiosUuid, fptools._, esxBiosUuid.lower())
        esxInstance = fptools.findFirst(isValidEsxFn, esxList)
        
        if not esxInstance:
            raise ValueError("Cannot find ESX Server instance in '%s' namespace" % vmware_cim_discover.CimNamespace.ESXV2)
        
        
        virtualMachines = vmware_cim_discover.getVirtualMachinesByEsx(client, esxInstance)
        totalVms = len(virtualMachines)
        
        virtualMachines = filter(_vmIsReportable, virtualMachines)
        reportableVms = len(virtualMachines)
        
        logger.debug("Virtual machines found: %s, filtered out: %s" % (totalVms, totalVms - reportableVms))
        
        return virtualMachines        
    
    finally:
        if client is not None:
            client.close()
def discoverBaseServerProfile(context, framework):
    '''
    ConnectionContext, Framework -> Profile
    @raise Exception
    @raise ValueError in case no BaseServerprofile can be found
    '''
    baseServerProfile = None
    interopClient = None
    try:
        interopClient = cim_discover.createClient(framework, context.ipAddress,
                                                  cim.CimNamespace.INTEROP,
                                                  context.credentialId)

        profiles = vmware_cim_discover.getProfiles(interopClient)
        baseServerProfile = fptools.findFirst(
            vmware_cim_discover.isBaseServerProfile, profiles)
        if baseServerProfile is None:
            raise ValueError("Base server profile cannot be found")
        else:
            return baseServerProfile
    finally:
        try:
            interopClient and interopClient.close()
        except:
            pass
Esempio n. 6
0
def get_db2_version_by_home_path(reg_provider, db2_home_path):
    regbased_discoverers = registry.get_discoverers()
    discover_version = Fn(fptools.safeFunc(__discover_version),
                         reg_provider, fptools._, db2_home_path)
    return fptools.findFirst(lambda x: x,
                                ifilter(None, imap(discover_version,
                                                   regbased_discoverers)))
Esempio n. 7
0
def getCategoryByName(categoryName, categories):
    '''
    string, list[category] -> Category or None
    '''
    if not categories:
        return None
    return fptools.findFirst(lambda c: c.getName() == categoryName, categories)
Esempio n. 8
0
 def isApplicable(self, context):
     self._hdbDaemonProcess = findFirst(
         hana_discoverer.isHdbDaemonProcess,
         context.application.getMainProcesses())
     if self._hdbDaemonProcess:
         return isinstance(context.client, shellutils.Shell)
     logger.debug('Hanadb daemon process not found')
def get_version_by_instance_name(shell, instance_name):
    discover_version = partial(fptools.safeFunc(__version_by_instance_name),
                               shell, instance_name)
    return fptools.findFirst(lambda x: x,
                                ifilter(None, imap(discover_version,
                                                   registry.get_discoverers()))
                             )
Esempio n. 10
0
def getUnderlyingNodeByName(node, name):
    r'''@types: str -> TopologyConfigParser.Node
    @raise TrexTopologyConfig.NodeNotFound
    '''
    node = fptools.findFirst(lambda c, name = name: c.getName() == name,
                             node.children)
    if not node: raise TrexTopologyConfig.NodeNotFound()
    return node
Esempio n. 11
0
def getUnderlyingNodeByName(node, name):
    r'''@types: str -> TopologyConfigParser.Node
    @raise TrexTopologyConfig.NodeNotFound
    '''
    node = fptools.findFirst(lambda c, name=name: c.getName() == name,
                             node.children)
    if not node: raise TrexTopologyConfig.NodeNotFound()
    return node
Esempio n. 12
0
def findDbmCliPath(fs, mainProcessPath):
    '''
    checks existence of dbmcli commands in following paths:
    /sapdb/<SID>/db/pgm/
    /sapdb/<SID>/db/bin/
    /sapdb/programs/bin/
    /sapdb/clients/<SID>/bin/
    Main process "kernel" has following path:
    /sapdb/<SID>/db/pgm/kernel
    @types: file_system.FileSystem, mainProcessPath -> str:

    '''
    if mainProcessPath:
        possibleDbmcliPaths = []
        pathTool = file_system.getPath(fs)
        # expecting /sapdb/<SID>/db/pgm/kernel
        pathList = mainProcessPath.split(fs.FileSeparator)
        if fs._shell.isWinOs():
            dbmCliBin = 'dbmcli.exe'
        else:
            dbmCliBin = 'dbmcli'
        if (len(pathList) >= 5 and pathList[-2] == 'pgm'
                and pathList[-3] == 'db'):
            # get maxDB home dir from kernel process:
            maxDbSid = pathList[-4]
            logger.debug('Found maxDB instance %s from kernel process path' %
                         maxDbSid)
            # get maxDB base dir from kernel process:
            maxDbHomeDir = pathTool.dirName(
                pathTool.dirName(
                    pathTool.dirName(pathTool.dirName(mainProcessPath))))
            logger.debug(
                'Found maxDB home folder %s from kernel process path' %
                maxDbHomeDir)
            possibleDbmcliPaths = (pathTool.join(maxDbHomeDir, maxDbSid, 'db',
                                                 'pgm', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, maxDbSid, 'db',
                                                 'bin', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, 'programs',
                                                 'bin', dbmCliBin),
                                   pathTool.join(maxDbHomeDir, 'clients',
                                                 maxDbSid, 'bin', dbmCliBin))
        else:
            mainProcessPath = pathTool.dirName(mainProcessPath).strip('" ')
            path_ = file_system.Path(mainProcessPath, pathTool) + dbmCliBin
            path_ = shell_interpreter.normalizePath(path_)
            possibleDbmcliPaths = (path_, )

    return findFirst(fs.exists, possibleDbmcliPaths) or __DEFAULT_DBMCLI_PATH
    def handler(self, items):
        get_db_info = operator.attrgetter('DB2_BDINFO')
        is_not_none = Fn(operator.is_not, fptools._, None)
        filterd_items = ifilter(comp(is_not_none, get_db_info), items)

        is_pid_matched = Fn(re.match, '%s\s\d+\s\d+' % self.pid, fptools._)

        item = fptools.findFirst(comp(is_pid_matched, get_db_info),
                                 filterd_items)
        if item:
            registry_path = RegistryPath(item.keyPath)
            if self.isNode(registry_path):
                node_registry_path = RegistryPath(registry_path.getPath())
                registry_path = RegistryPath(node_registry_path.getPath())
            return registry_path.name
Esempio n. 14
0
    def handler(self, items):
        get_db_info = operator.attrgetter('DB2_BDINFO')
        is_not_none = Fn(operator.is_not, fptools._, None)
        filterd_items = ifilter(comp(is_not_none, get_db_info), items)

        is_pid_matched = Fn(re.match, '%s\s\d+\s\d+' % self.pid, fptools._)

        item = fptools.findFirst(comp(is_pid_matched, get_db_info),
                                 filterd_items)
        if item:
            registry_path = RegistryPath(item.keyPath)
            if self.isNode(registry_path):
                node_registry_path = RegistryPath(registry_path.getPath())
                registry_path = RegistryPath(node_registry_path.getPath())
            return registry_path.name
Esempio n. 15
0
def getRegKeys(client, regPath):
    '''
    Returns a dict of key-values by path
    @types Client, str -> dict
    @raise InitException, ExecException or ParseException
    '''
    provider = getProvider(client)
    root, path = regPath.split('\\', 1)
    rootFolder = registryRootFolder.findChildByName(root)
    if not rootFolder:
        rootFolder = RegistryFolder(root)
    builder = provider.getBuilder(rootFolder, path)
    items = provider.getAgent().execQuery(builder)
    item = fptools.findFirst(lambda x: x.keyPath == regPath, items)
    return item and item.getAsDict() or {}
Esempio n. 16
0
def getRegKeys(client, regPath):
    '''
    Returns a dict of key-values by path
    @types Client, str -> dict
    @raise InitException, ExecException or ParseException
    '''
    provider = getProvider(client)
    root, path = regPath.split('\\', 1)
    rootFolder = registryRootFolder.findChildByName(root)
    if not rootFolder:
        rootFolder = RegistryFolder(root)
    builder = provider.getBuilder(rootFolder, path)
    items = provider.getAgent().execQuery(builder)
    item = fptools.findFirst(lambda x: x.keyPath == regPath, items)
    return item and item.getAsDict() or {}
Esempio n. 17
0
 def discoverComponents(self):
     r''' Collect all data from different queries about available software
     components
     @types: -> list[sap.SoftwareComponent]'''
     componentDescriptions = self.getComponentLocalizedDescriptions()
     # may exist several localized descriptions per component
     descrsByName = fptools.groupby(
         self.ComponentLocalizedDescription.getName, componentDescriptions)
     components = []
     for component in self.getComponents():
         # find description in english
         isEn = SoftwareComponentDiscovererByJco.isEnglishCmpDescription
         descrs = descrsByName.get(component.name, ())
         description = fptools.findFirst(isEn, descrs)
         components.append(
             sap.SoftwareComponent(component.name, component.type,
                                   description and description.value,
                                   component.versionInfo))
     return components
Esempio n. 18
0
    def get_instance_name(self, context):
        pid = self._main_process.getPid()
        if pid is not None:
            shell = context.client
            os_bitcount = shell.is64BitMachine() and 64 or 32

            reg_provider = regutils.getProvider(shell)
            version = self.get_db2_version(context)
            discoverer = winreg_discoverer.registry.get_discoverer(version,
                                                                   os_bitcount)
            execute_reg_command = Fn(winreg_base_discoverer.execute_reg_query,
                                     reg_provider,
                                     fptools._)
            execute_reg_command = safeFn(execute_reg_command)
            return fptools.findFirst(bool, map(execute_reg_command,
                                  (discoverer.GetInstanceNameByPid(pid),
                                   discoverer.GetClusterInstanceNameByPid(pid))
                                  ))
        else:
            logger.debug('pid is not available for the main db2 process')
Esempio n. 19
0
 def discoverComponents(self):
     r''' Collect all data from different queries about available software
     components
     @types: -> list[sap.SoftwareComponent]'''
     componentDescriptions = self.getComponentLocalizedDescriptions()
     # may exist several localized descriptions per component
     descrsByName = fptools.groupby(
         self.ComponentLocalizedDescription.getName, componentDescriptions)
     components = []
     for component in self.getComponents():
         # find description in english
         isEn = SoftwareComponentDiscovererByJco.isEnglishCmpDescription
         descrs = descrsByName.get(component.name, ())
         description = fptools.findFirst(isEn, descrs)
         components.append(sap.SoftwareComponent(
             component.name,
             component.type,
             description and description.value,
             component.versionInfo))
     return components
Esempio n. 20
0
def findDbmCliPath(fs, mainProcessPath):
    """
    checks existence of dbmcli commands in following paths:
    /sapdb/<SID>/db/pgm/
    /sapdb/<SID>/db/bin/
    /sapdb/programs/bin/
    /sapdb/clients/<SID>/bin/
    Main process "kernel" has following path:
    /sapdb/<SID>/db/pgm/kernel
    @types: file_system.FileSystem, mainProcessPath -> str:

    """
    if mainProcessPath:
        possibleDbmcliPaths = []
        pathTool = file_system.getPath(fs)
        # expecting /sapdb/<SID>/db/pgm/kernel
        pathList = mainProcessPath.split(fs.FileSeparator)
        if fs._shell.isWinOs():
            dbmCliBin = "dbmcli.exe"
        else:
            dbmCliBin = "dbmcli"
        if len(pathList) >= 5 and pathList[-2] == "pgm" and pathList[-3] == "db":
            # get maxDB home dir from kernel process:
            maxDbSid = pathList[-4]
            logger.debug("Found maxDB instance %s from kernel process path" % maxDbSid)
            # get maxDB base dir from kernel process:
            maxDbHomeDir = pathTool.dirName(pathTool.dirName(pathTool.dirName(pathTool.dirName(mainProcessPath))))
            logger.debug("Found maxDB home folder %s from kernel process path" % maxDbHomeDir)
            possibleDbmcliPaths = (
                pathTool.join(maxDbHomeDir, maxDbSid, "db", "pgm", dbmCliBin),
                pathTool.join(maxDbHomeDir, maxDbSid, "db", "bin", dbmCliBin),
                pathTool.join(maxDbHomeDir, "programs", "bin", dbmCliBin),
                pathTool.join(maxDbHomeDir, "clients", maxDbSid, "bin", dbmCliBin),
            )
        else:
            mainProcessPath = pathTool.dirName(mainProcessPath).strip('" ')
            path_ = file_system.Path(mainProcessPath, pathTool) + dbmCliBin
            path_ = shell_interpreter.normalizePath(path_)
            possibleDbmcliPaths = (path_,)

    return findFirst(fs.exists, possibleDbmcliPaths) or __DEFAULT_DBMCLI_PATH
def discoverBaseServerProfile(context, framework):
    '''
    ConnectionContext, Framework -> Profile
    @raise Exception
    @raise ValueError in case no BaseServerprofile can be found
    '''
    baseServerProfile = None
    interopClient = None
    try:
        interopClient = cim_discover.createClient(framework, context.ipAddress, cim.CimNamespace.INTEROP, context.credentialId)
    
        profiles = vmware_cim_discover.getProfiles(interopClient)
        baseServerProfile = fptools.findFirst(vmware_cim_discover.isBaseServerProfile, profiles)
        if baseServerProfile is None:
            raise ValueError("Base server profile cannot be found")
        else:
            return baseServerProfile
    finally:
        try:
            interopClient and interopClient.close()
        except:
            pass
Esempio n. 22
0
def is_reserved_schema_name(name):
    return fptools.findFirst(lambda fn: fn(name),
                             _is_reserved_schema_name_predicates)
Esempio n. 23
0
def is_default_client_program_name(name):
    return fptools.findFirst(lambda fn: fn(name),
                             _is_default_client_program_name_predicates)
Esempio n. 24
0
def is_default_client_program_name(name):
    return fptools.findFirst(lambda fn: fn(name),
                             _is_default_client_program_name_predicates)
Esempio n. 25
0
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # 1) get process related application
        application = context.application
        connectionIp = application.getConnectionIp()
        # 2) find out process where path to the instance profile is stored
        logger.info(" Get executable path of main process ")
        mainProcess = application.getMainProcesses()[0]
        # 3)
        logger.info("Found out path to instance profile")
        instanceProfilePath = self.__getProfilePath(mainProcess)
        # 4)
        logger.info("Instance profile path: ", instanceProfilePath, ". Get content")
        getContent = fptools.safeFunc(self.__getContent, Exception)
        profileFile = (instanceProfilePath and getContent(shell, pathtools, instanceProfilePath))
        if not profileFile:
            logger.warn("Failed to get content of instance profile")
            return
        # 5) parse content using instance and default profile parsers
        logger.info("Make configuration parsing")
        iniParser = sap_discoverer.IniParser()
        instancePfParser = sap_discoverer.InstanceProfileParser(iniParser)
        try:
            instanceProfile = instancePfParser.parseContent(profileFile.content)
        except Exception:
            logger.warnException("Failed to parse instance profile")
        else:
            traceConfig = None
            runtimeConfig = None
            sapInstance = instanceProfile.instance
            sapInstance = sap.Instance(sapInstance.name + sapInstance.number,
                                       sapInstance.number,
                                       sapInstance.hostname)

            # 6) Process runtime.properties that contains information about
            #    Solution Manager and SLD if present
            logger.info("Create agent layout")
            logger.info("Get content of runtime properties")
            agentLayout = fptools.safeFunc(sap_smd_discoverer.createAgentLayoutFromBinPath)(
                (pathtools.isAbsolute(mainProcess.executablePath)
                 and mainProcess.executablePath
                 or discoverExecutablePath(shell, mainProcess)
                 ),
                    fs,
                    pathtools
                )
            if agentLayout:
                propertiesFile = getContent(shell, pathtools, agentLayout.getRuntimePropertiesPath())
                if propertiesFile:
                    parser = sap_smd_discoverer.RuntimePropertiesParser(
                        sap_discoverer.IniParser())
                    try:
                        runtimeConfig = parser.parse(propertiesFile.content)
                    except Exception:
                        logger.warnException("Failed to parse runtime properties")

                logger.info("Find out version information")
                devSmdAgentFile = getContent(shell, pathtools, agentLayout.getDevSmdAgentConfigFile())
                if devSmdAgentFile:
                    configParser = sap_smd_discoverer.DevSmdAgentConfigParser()
                    # find config with corresponding PID (of main process)
                    hasMainProcessPid = lambda c, pid = mainProcess.getPid(): c.pid == pid
                    traceConfig = fptools.findFirst(hasMainProcessPid,
                                                    configParser.parse(devSmdAgentFile.content))
                    if not traceConfig:
                        logger.warn("Failed to find trace information for the main process")

            # === REPORT ===
            smdAgentOsh = application.getOsh()
            vector = context.resultsVector
            endpointReporter = netutils.EndpointReporter(netutils.ServiceEndpointBuilder())
            configFileReporter = file_topology.Reporter(file_topology.Builder())
            linkReporter = sap.LinkReporter()
            smdAgentBuilder = sap_smd.Builder()
            softwareBuilder = sap.SoftwareBuilder()
            softwareReporter = sap.SoftwareReporter(sap.SoftwareBuilder())
            resolverByShell = netutils.DnsResolverByShell(shell)
            processOsh = mainProcess.getOsh()

            # x) update name of application using instance name
            softwareBuilder.updateName(smdAgentOsh, sapInstance.getName())
            # x) configuration files related to running_software
            vector.add(configFileReporter.report(profileFile, smdAgentOsh))

            if traceConfig:
                # x) update version information in application
                smdAgentOsh = softwareBuilder.updateVersionInfo(
                    smdAgentOsh, traceConfig.versionInfo)
                if traceConfig.jstartVersionInfo:
                    smdAgentOsh = smdAgentBuilder.updateJstartVersionInfo(
                        smdAgentOsh, traceConfig.jstartVersionInfo)

            # x) show relation between agent and
            # - SMD server / no enough information /
            # - message server of SCS OR Solution Manager, represented as agent connection endpoint
            # - SLD
            if propertiesFile and runtimeConfig:
                # x) report properties file as configuration document
                vector.add(configFileReporter.report(propertiesFile, smdAgentOsh))
                # x) Report relation between agent and SLD server and SolMan
                # Resolve endpoint addresses
                # make function that will accept endpoint only
                resolveEndpointFn = fptools.partiallyApply(
                    self.__resolveEndpointAddress,
                    fptools.safeFunc(resolverByShell.resolveIpsByHostname, []),
                    fptools._
                )
                # - SLD relation
                if runtimeConfig.sldEndpoint:
                    for endpoint in resolveEndpointFn(runtimeConfig.sldEndpoint):
                        sldHostOsh = endpointReporter.reportHostFromEndpoint(endpoint)
                        vector.add(sldHostOsh)
                        sldEndpointOsh = endpointReporter.reportEndpoint(endpoint, sldHostOsh)
                        vector.add(sldEndpointOsh)
                        # this unknown server type must be SLD server
                        sldOsh = softwareReporter.reportUknownSoftware(sldHostOsh)
                        vector.add(sldOsh)
                        vector.add(linkReporter.reportUsage(sldOsh, sldEndpointOsh))
                        # report link between process and SLD server endpoint
                        vector.add(linkReporter.reportClientServerRelation(processOsh, sldEndpointOsh))

                # - Solution Manager relation
                agentConnectionEndpoint = runtimeConfig.getAgentConnecitonEndpoint()
                if agentConnectionEndpoint:
                    for endpoint in resolveEndpointFn(agentConnectionEndpoint):
                        hostOsh = endpointReporter.reportHostFromEndpoint(endpoint)
                        vector.add(hostOsh)
                        endpointOsh = endpointReporter.reportEndpoint(endpoint, hostOsh)
                        vector.add(endpointOsh)
                        softwareOsh = softwareReporter.reportUknownSoftware(hostOsh)
                        vector.add(softwareOsh)
                        vector.add(linkReporter.reportUsage(softwareOsh, endpointOsh))
                        # report link between process and SolMan end-point
                        vector.add(linkReporter.reportClientServerRelation(processOsh, endpointOsh))
Esempio n. 26
0
 def _get_keyname(self):
     return findFirst(methodcaller('startswith', '-k'), self.options)
Esempio n. 27
0
 def isApplicable(self, context):
     self._hdbDaemonProcess = findFirst(hana_discoverer.isHdbDaemonProcess, context.application.getMainProcesses())
     if self._hdbDaemonProcess:
         return isinstance(context.client, shellutils.Shell)
     logger.debug('Hanadb daemon process not found')
Esempio n. 28
0
def get_db2_version(sql_executor):
    sqlbased_discoverers = registry.get_discoverers()
    discover_version = Fn(safeFn(__discover_version), sql_executor, fptools._)
    return findFirst(lambda x: x,
                                ifilter(None, imap(discover_version,
                                                   sqlbased_discoverers)))
Esempio n. 29
0
                        logger.info(
                            "\tServer(fullName = %s) is cluster member" %
                            member.getFullName())
                        member.addRole(
                            jee.ClusterMemberServerRole(clusterName))

                # report domain topology (servers, clusters, nodes, servers)
                domainTopologyReporter = reporterCreator.getDomainReporter()
                domainVector = domainTopologyReporter.reportNodesInDomainDnsEnabled(
                    cell, dnsResolver, *cell.getNodes())
                domainVector.addAll(
                    domainTopologyReporter.reportClusters(
                        cell, *cell.getClusters()))

                # determine whether we have at least one server with resolved IP address. Stop report if we haven't.
                if not findFirst(lambda srvr: srvr.ip.value(),
                                 serverByFullName.values()):
                    logger.warn("%s and related topology won't be reported \
as there is no at least one server with resolved IP address" % cell)
                    continue
                _domainVector = domainVector.deepClone()
                _sendVectorImmediately(Framework,
                                       domainVector,
                                       forceVectorClean=0)

                sendVectorWithDomain = curry(sendTopologyWithDomainVector,
                                             Framework, _, _domainVector)
                # discover resources
                jndiNamedResourceManager = discoverResourcesInDomain(
                    cell, cellLayout, fs, parser, reporterCreator,
                    sendVectorWithDomain)
Esempio n. 30
0
        kernelProcName = self._getMainProcessName()
        kernelProc = context.application.getProcess(kernelProcName)
        logger.debug('Kernel proc cmdLine: %s' % kernelProc.commandLine)
        fs = file_system.createFileSystem(shell)
        dbmCliWithPath = maxdb_discoverer.findDbmCliPath(
            fs, kernelProc.commandLine)
        dbmCli = maxdb_discoverer.getDbmCli(shell, dbmCliWithPath)
        appOsh = context.application.applicationOsh
        try:
            allDbEnums = dbmCli.db_enum().process()
        except maxdb_discoverer.DbmCliException, dce:
            logger.debugException(str(dce))
        else:
            dbEnums = filter(DbEnumResult.isOnline, allDbEnums) or allDbEnums
            equal_cmdlines = partial(_equals_cmdlines, kernelProc)
            currentDbEnum = findFirst(equal_cmdlines, dbEnums)
            if currentDbEnum:
                _update_instance_info(currentDbEnum, kernelProc, appOsh)
                _discover_paths(dbmCli, currentDbEnum.dbName, appOsh)
            else:
                msg = ('Current kernel process is not found '
                       'among registered database instances')
                raise applications.IgnoreApplicationException(msg)


def _equals_cmdlines(process, dbenum):
    '@types: Process, DbEnumResult -> bool'
    process_cmdline = process.commandLine.lower().strip('" ')
    dbenum_cmdline = dbenum.dependentPath.lower().strip('" ')
    return process_cmdline.startswith(dbenum_cmdline)
Esempio n. 31
0
                    clusterName = cluster.getName()
                    for member in filter(None,
                        map(curry(getClusterMemberFromRuntimeGroup, _, serverByFullName),
                            members
                        )
                    ):
                        logger.info("\tServer(fullName = %s) is cluster member" % member.getFullName())
                        member.addRole(jee.ClusterMemberServerRole(clusterName))

                # report domain topology (servers, clusters, nodes, servers)
                domainTopologyReporter = reporterCreator.getDomainReporter()
                domainVector = domainTopologyReporter.reportNodesInDomainDnsEnabled(cell, dnsResolver, *cell.getNodes())
                domainVector.addAll(domainTopologyReporter.reportClusters(cell, *cell.getClusters()))

                # determine whether we have at least one server with resolved IP address. Stop report if we haven't.
                if not findFirst(lambda srvr: srvr.ip.value(), serverByFullName.values()):
                    logger.warn("%s and related topology won't be reported \
as there is no at least one server with resolved IP address" % cell)
                    continue
                _domainVector = domainVector.deepClone()
                _sendVectorImmediately(Framework, domainVector, forceVectorClean = 0)

                sendVectorWithDomain = curry(sendTopologyWithDomainVector,
                                            Framework, _, _domainVector
                )
                # discover resources
                jndiNamedResourceManager = discoverResourcesInDomain(
                                cell, cellLayout, fs, parser,
                                reporterCreator, sendVectorWithDomain
                )
Esempio n. 32
0
    def parse_fc_vpd(lines):
        '''Parses fibre channel vpd data to a FcDescriptor instance

        @param lines: fibre channel vpd output splitted in lines
        @type lines: seq[str]
        @return: parsed fc hba descriptor
        @rtype: vital_product_data.FcDescriptor
        '''
        devicename = None
        location = None
        description = None
        driverid = None
        m = re.search('(fcs\d+)\s+(.*?)\s\s(.+\(([0-9a-fA-F]+)\))', lines[0])
        if m:
            devicename, location, description, driverid = m.groups()

        tag = 'PLATFORM SPECIFIC'
        tag_index = findFirst(identity,
                              (i
                               for i, line in enumerate(lines) if tag in line))

        base_attrs = {}
        device_specific_attrs = {}
        for line in lines[1:tag_index]:
            m = re.match('(.+?)\.\.+(.+)', line)
            if m:
                name, value = m.groups()
                name = name.strip()
                value = value.strip()
                if name.startswith('Device Specific.'):
                    _, name = re.split('\.', name, maxsplit=1)
                    device_specific_attrs[name.strip('()')] = value
                else:
                    base_attrs[name] = value

        platform_specific_attrs = {}
        for line in ifilter(identity, lines[tag_index + 1:]):
            name, value = re.split('\:', line, maxsplit=1)
            platform_specific_attrs[name.strip()] = value.strip()

        name = platform_specific_attrs['Name']
        model = platform_specific_attrs['Model']
        node = platform_specific_attrs['Node']
        device_type = platform_specific_attrs['Device Type']
        physical_location = platform_specific_attrs['Physical Location']

        platform_specific = FcPlatfromSpecificDescriptor(
            name, model, node, device_type, physical_location)
        part_number = base_attrs.get('Part Number')
        serial_number = base_attrs.get('Serial Number')
        manufacturer = base_attrs.get('Manufacturer')
        ec_level = base_attrs.get('EC Level')
        customer_card_id_number = base_attrs.get('Customer Card ID Number')
        fru_number = base_attrs.get('FRU Number')
        network_address = base_attrs.get('Network Address')
        ros_level_and_id = base_attrs.get('ROS Level and ID')
        hardware_location_code = base_attrs.get('Hardware Location Code')
        return FcDescriptor(devicename, location, driverid, description,
                            part_number, serial_number, manufacturer, ec_level,
                            customer_card_id_number, fru_number,
                            network_address, ros_level_and_id,
                            hardware_location_code, device_specific_attrs,
                            platform_specific)
def get_version_by_instance_name(shell, instance_name):
    discover_version = partial(fptools.safeFunc(__version_by_instance_name),
                               shell, instance_name)
    return fptools.findFirst(
        lambda x: x,
        ifilter(None, imap(discover_version, registry.get_discoverers())))
Esempio n. 34
0
 def _has_instance_option(self):
     return bool(findFirst(methodcaller('startswith', '-i'), self.options))
Esempio n. 35
0
def get_db2_version(sql_executor):
    sqlbased_discoverers = registry.get_discoverers()
    discover_version = Fn(safeFn(__discover_version), sql_executor, fptools._)
    return findFirst(
        lambda x: x, ifilter(None, imap(discover_version,
                                        sqlbased_discoverers)))
Esempio n. 36
0
    def parse_fc_vpd(lines):
        '''Parses fibre channel vpd data to a FcDescriptor instance

        @param lines: fibre channel vpd output splitted in lines
        @type lines: seq[str]
        @return: parsed fc hba descriptor
        @rtype: vital_product_data.FcDescriptor
        '''
        devicename = None
        location = None
        description = None
        driverid = None
        m = re.search('(fcs\d+)\s+(.*?)\s\s(.+\(([0-9a-fA-F]+)\))', lines[0])
        if m:
            devicename, location, description, driverid = m.groups()

        tag = 'PLATFORM SPECIFIC'
        tag_index = findFirst(identity,
                              (i for i, line in enumerate(lines) if tag in line))

        base_attrs = {}
        device_specific_attrs = {}
        for line in lines[1: tag_index]:
            m = re.match('(.+?)\.\.+(.+)', line)
            if m:
                name, value = m.groups()
                name = name.strip()
                value = value.strip()
                if name.startswith('Device Specific.'):
                    _, name = re.split('\.', name, maxsplit=1)
                    device_specific_attrs[name.strip('()')] = value
                else:
                    base_attrs[name] = value

        platform_specific_attrs = {}
        for line in ifilter(identity, lines[tag_index + 1:]):
            name, value = re.split('\:', line, maxsplit=1)
            platform_specific_attrs[name.strip()] = value.strip()

        name = platform_specific_attrs['Name']
        model = platform_specific_attrs['Model']
        node = platform_specific_attrs['Node']
        device_type = platform_specific_attrs['Device Type']
        physical_location = platform_specific_attrs['Physical Location']

        platform_specific = FcPlatfromSpecificDescriptor(name, model,
                                                         node, device_type,
                                                         physical_location)
        part_number = base_attrs.get('Part Number')
        serial_number = base_attrs.get('Serial Number')
        manufacturer = base_attrs.get('Manufacturer')
        ec_level = base_attrs.get('EC Level')
        customer_card_id_number = base_attrs.get('Customer Card ID Number')
        fru_number = base_attrs.get('FRU Number')
        network_address = base_attrs.get('Network Address')
        ros_level_and_id = base_attrs.get('ROS Level and ID')
        hardware_location_code = base_attrs.get('Hardware Location Code')
        return FcDescriptor(devicename, location, driverid,
                            description, part_number, serial_number,
                            manufacturer, ec_level, customer_card_id_number,
                            fru_number, network_address, ros_level_and_id,
                            hardware_location_code, device_specific_attrs,
                            platform_specific)
Esempio n. 37
0
 def _has_instance_option(self):
     return bool(findFirst(methodcaller('startswith', '-i'), self.options))
Esempio n. 38
0
                )

                # find corresponding process for each discovered server to
                # provide additional information that can be overridden
                resolvedServers = []
                servers = domainDescriptor.getServers()
                # for 7-8 versions config.xml hasn't info about admin-server at all
                # try to get 1st server created by config wizard to set is as admin:
                if platformTrait.majorVersion.value() < 9:
                    try:
                        startScriptXmlFile = domainLayout.getFileContent(domainLayout.getStartupScriptPath())
                        adminServerName = parser.parseAdminServerNameInStartupScriptContent(startScriptXmlFile.content)
                    except (Exception, JException):
                        logger.warnException("Failed to process startscript.xml to get admin-server")
                    else:
                        adminServer = fptools.findFirst((lambda x: x.getName() == adminServerName), servers)
                        adminServer and adminServer.addRole(jee.AdminServerRole())
                # if domain has just one server it is stand-alone server,
                # it has admin-console and is administrative server for itself
                if len(servers) == 1 and not servers[0].hasRole(jee.AdminServerRole):
                    servers[0].addRole(jee.AdminServerRole())
                for server in servers:
                    logger.debug("Server %s" % server)
                    # find server with name present between running processes
                    runtime = runtimeByServerName.get(server.getName())
                    serverRole = server.getRole(weblogic.ServerRole)
                    if runtime:
                        # such data can be overridden
                        # - LISTEN ADDRESS
                        #     - -Dweblogic.ListenAddress=host
                        server.address = server.address or destinationIp
Esempio n. 39
0
 def isApplicable(self, context):
     r''' @types: applications.ApplicationSignatureContext '''
     return (isinstance(context.client, shellutils.Shell)
             # has daemon process
             and findFirst(isMainTrexProcess,
                           context.application.getProcesses()) is not None)
Esempio n. 40
0
 def isApplicable(self, context):
     r''' Determine whether plugin can be applicable, main process 'sapstartsrv'
     is present and has path to the profile
     @types: applications.ApplicationSignatureContext -> bool
     '''
     return fptools.findFirst(hasProfileInCmdline, context.application.getMainProcesses())
Esempio n. 41
0
 def _get_keyname(self):
     return findFirst(methodcaller('startswith', '-k'), self.options)
Esempio n. 42
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess,
                                context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(
            mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(
            Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line"                                                        | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(
            sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(
            sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(
                profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
        #        # master by default, if topology file is not found that means
        #        # that current one is the only instance
        #        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
            mainProcess.getExecutablePath(), systemName)
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(
                pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(
                trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(
                pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(
                    defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType(
                ) == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(
                    profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(
                    destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(
                sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                                and systemLayout.getTopologyIniPath()
                                or discoverTopologyIniFilePath(
                                    fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(
                topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                        configParser.parse(topologyFile.content))
                    # find instance between master end-points


#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException(
                        "Failed to parse topology configuration")
            else:
                logger.warn(
                    "Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(
                    sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(
                    sap_discoverer.parseSapSystemFromInstanceProfileName)(
                        profileFile.getName())
                if profileSystem:
                    hostname = first(
                        profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(
                        instanceLayout.composeUpdateConfigIniFilePath(
                            hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(
                        updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (
                isBiaProduct and systemLayout.getRfcServerConfigFilePath()
                or instanceLayout.composeTrexRfcServerIniFilePath(
                    instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)(
                        rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(
                trexOsh, sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                                    fptools._, trexTopology,
                                                    isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)
Esempio n. 43
0
 servers = domainDescriptor.getServers()
 # for 7-8 versions config.xml hasn't info about admin-server at all
 # try to get 1st server created by config wizard to set is as admin:
 if platformTrait.majorVersion.value() < 9:
     try:
         startScriptXmlFile = domainLayout.getFileContent(
             domainLayout.getStartupScriptPath())
         adminServerName = parser.parseAdminServerNameInStartupScriptContent(
             startScriptXmlFile.content)
     except (Exception, JException):
         logger.warnException(
             "Failed to process startscript.xml to get admin-server"
         )
     else:
         adminServer = fptools.findFirst(
             (lambda x: x.getName() == adminServerName),
             servers)
         adminServer and adminServer.addRole(
             jee.AdminServerRole())
 # if domain has just one server it is stand-alone server,
 # it has admin-console and is administrative server for itself
 if len(servers) == 1 and not servers[0].hasRole(
         jee.AdminServerRole):
     servers[0].addRole(jee.AdminServerRole())
 for server in servers:
     logger.debug("Server %s" % server)
     # find server with name present between running processes
     runtime = runtimeByServerName.get(server.getName())
     serverRole = server.getRole(weblogic.ServerRole)
     if runtime:
         # such data can be overridden
Esempio n. 44
0
        shell = context.client
        kernelProcName = self._getMainProcessName()
        kernelProc = context.application.getProcess(kernelProcName)
        logger.debug('Kernel proc cmdLine: %s' % kernelProc.commandLine)
        fs = file_system.createFileSystem(shell)
        dbmCliWithPath = maxdb_discoverer.findDbmCliPath(fs, kernelProc.commandLine)
        dbmCli = maxdb_discoverer.getDbmCli(shell, dbmCliWithPath)
        appOsh = context.application.applicationOsh
        try:
            allDbEnums = dbmCli.db_enum().process()
        except maxdb_discoverer.DbmCliException, dce:
            logger.debugException(str(dce))
        else:
            dbEnums = filter(DbEnumResult.isOnline, allDbEnums) or allDbEnums
            equal_cmdlines = partial(_equals_cmdlines, kernelProc)
            currentDbEnum = findFirst(equal_cmdlines, dbEnums)
            if currentDbEnum:
                _update_instance_info(currentDbEnum, kernelProc, appOsh)
                _discover_paths(dbmCli, currentDbEnum.dbName, appOsh)
            else:
                msg = ('Current kernel process is not found '
                       'among registered database instances')
                raise applications.IgnoreApplicationException(msg)


def _equals_cmdlines(process, dbenum):
    '@types: Process, DbEnumResult -> bool'
    process_cmdline = process.commandLine.lower().strip('" ')
    dbenum_cmdline = dbenum.dependentPath.lower().strip('" ')
    return process_cmdline.startswith(dbenum_cmdline)
Esempio n. 45
0
def get_version_by_shell_from_dbmcli(shell, dbmCliPath=None):
    "@types: Shell, str -> DbmVersionResult?"
    discover_version = Sfn(__version_by_dbm_cli)
    versions = (discover_version(cls, shell, dbmCliPath) for cls in DBMCLI_IMPLEMENTATIONS)
    return findFirst(bool, versions)
Esempio n. 46
0
def get_db2_version_by_home_path(executor, db2_home_path):
    discover_version = Fn(fptools.safeFunc(__discover_version),
                         executor, fptools._, db2_home_path)
    return fptools.findFirst(lambda x: x,
                                        ifilter(None, imap(discover_version,
                                               registry.get_discoverers())))
Esempio n. 47
0
def is_reserved_schema_name(name):
    return fptools.findFirst(lambda fn: fn(name),
                             _is_reserved_schema_name_predicates)
Esempio n. 48
0
def get_version_by_shell_from_dbmcli(shell, dbmCliPath=None):
    '@types: Shell, str -> DbmVersionResult?'
    discover_version = Sfn(__version_by_dbm_cli)
    versions = (discover_version(cls, shell, dbmCliPath)
                for cls in DBMCLI_IMPLEMENTATIONS)
    return findFirst(bool, versions)
Esempio n. 49
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess, context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line" | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
#        # master by default, if topology file is not found that means
#        # that current one is the only instance
#        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
                            mainProcess.getExecutablePath(), systemName )
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType() == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                and systemLayout.getTopologyIniPath()
                or  discoverTopologyIniFilePath(fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                                configParser.parse(topologyFile.content))
                    # find instance between master end-points
#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException("Failed to parse topology configuration")
            else:
                logger.warn("Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(sap_discoverer.parseSapSystemFromInstanceProfileName)(profileFile.getName())
                if profileSystem:
                    hostname = first(profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(instanceLayout.composeUpdateConfigIniFilePath(hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (isBiaProduct
                    and systemLayout.getRfcServerConfigFilePath()
                    or instanceLayout.composeTrexRfcServerIniFilePath(instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)
                        (rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(trexOsh,
                                    sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                     fptools._, trexTopology, isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)
Esempio n. 50
0
    def process(self, context):
        r'''
        @types: applications.ApplicationSignatureContext
        '''
        # ==================== DISCOVERY
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # 1) get process related application
        application = context.application
        connectionIp = application.getConnectionIp()
        # 2) find out process where path to the instance profile is stored
        logger.info(" Get executable path of main process ")
        mainProcess = application.getMainProcesses()[0]
        # 3)
        logger.info("Found out path to instance profile")
        instanceProfilePath = self.__getProfilePath(mainProcess)
        # 4)
        logger.info("Instance profile path: ", instanceProfilePath,
                    ". Get content")
        getContent = fptools.safeFunc(self.__getContent, Exception)
        profileFile = (instanceProfilePath
                       and getContent(shell, pathtools, instanceProfilePath))
        if not profileFile:
            logger.warn("Failed to get content of instance profile")
            return
        # 5) parse content using instance and default profile parsers
        logger.info("Make configuration parsing")
        iniParser = sap_discoverer.IniParser()
        instancePfParser = sap_discoverer.InstanceProfileParser(iniParser)
        try:
            instanceProfile = instancePfParser.parseContent(
                profileFile.content)
        except Exception:
            logger.warnException("Failed to parse instance profile")
        else:
            traceConfig = None
            runtimeConfig = None
            sapInstance = instanceProfile.instance
            sapInstance = sap.Instance(sapInstance.name + sapInstance.number,
                                       sapInstance.number,
                                       sapInstance.hostname)

            # 6) Process runtime.properties that contains information about
            #    Solution Manager and SLD if present
            logger.info("Create agent layout")
            logger.info("Get content of runtime properties")
            agentLayout = fptools.safeFunc(
                sap_smd_discoverer.createAgentLayoutFromBinPath)(
                    (pathtools.isAbsolute(mainProcess.executablePath)
                     and mainProcess.executablePath
                     or discoverExecutablePath(shell, mainProcess)), fs,
                    pathtools)
            if agentLayout:
                propertiesFile = getContent(
                    shell, pathtools, agentLayout.getRuntimePropertiesPath())
                if propertiesFile:
                    parser = sap_smd_discoverer.RuntimePropertiesParser(
                        sap_discoverer.IniParser())
                    try:
                        runtimeConfig = parser.parse(propertiesFile.content)
                    except Exception:
                        logger.warnException(
                            "Failed to parse runtime properties")

                logger.info("Find out version information")
                devSmdAgentFile = getContent(
                    shell, pathtools, agentLayout.getDevSmdAgentConfigFile())
                if devSmdAgentFile:
                    configParser = sap_smd_discoverer.DevSmdAgentConfigParser()
                    # find config with corresponding PID (of main process)
                    hasMainProcessPid = lambda c, pid=mainProcess.getPid(
                    ): c.pid == pid
                    traceConfig = fptools.findFirst(
                        hasMainProcessPid,
                        configParser.parse(devSmdAgentFile.content))
                    if not traceConfig:
                        logger.warn(
                            "Failed to find trace information for the main process"
                        )

            # === REPORT ===
            smdAgentOsh = application.getOsh()
            vector = context.resultsVector
            endpointReporter = netutils.EndpointReporter(
                netutils.ServiceEndpointBuilder())
            configFileReporter = file_topology.Reporter(
                file_topology.Builder())
            linkReporter = sap.LinkReporter()
            smdAgentBuilder = sap_smd.Builder()
            softwareBuilder = sap.SoftwareBuilder()
            softwareReporter = sap.SoftwareReporter(sap.SoftwareBuilder())
            resolverByShell = netutils.DnsResolverByShell(shell)
            processOsh = mainProcess.getOsh()

            # x) update name of application using instance name
            softwareBuilder.updateName(smdAgentOsh, sapInstance.getName())
            # x) configuration files related to running_software
            vector.add(configFileReporter.report(profileFile, smdAgentOsh))

            if traceConfig:
                # x) update version information in application
                smdAgentOsh = softwareBuilder.updateVersionInfo(
                    smdAgentOsh, traceConfig.versionInfo)
                if traceConfig.jstartVersionInfo:
                    smdAgentOsh = smdAgentBuilder.updateJstartVersionInfo(
                        smdAgentOsh, traceConfig.jstartVersionInfo)

            # x) show relation between agent and
            # - SMD server / no enough information /
            # - message server of SCS OR Solution Manager, represented as agent connection endpoint
            # - SLD
            if propertiesFile and runtimeConfig:
                # x) report properties file as configuration document
                vector.add(
                    configFileReporter.report(propertiesFile, smdAgentOsh))
                # x) Report relation between agent and SLD server and SolMan
                # Resolve endpoint addresses
                # make function that will accept endpoint only
                resolveEndpointFn = fptools.partiallyApply(
                    self.__resolveEndpointAddress,
                    fptools.safeFunc(resolverByShell.resolveIpsByHostname, []),
                    fptools._)
                # - SLD relation
                if runtimeConfig.sldEndpoint:
                    for endpoint in resolveEndpointFn(
                            runtimeConfig.sldEndpoint):
                        sldHostOsh = endpointReporter.reportHostFromEndpoint(
                            endpoint)
                        vector.add(sldHostOsh)
                        sldEndpointOsh = endpointReporter.reportEndpoint(
                            endpoint, sldHostOsh)
                        vector.add(sldEndpointOsh)
                        # this unknown server type must be SLD server
                        sldOsh = softwareReporter.reportUknownSoftware(
                            sldHostOsh)
                        vector.add(sldOsh)
                        vector.add(
                            linkReporter.reportUsage(sldOsh, sldEndpointOsh))
                        # report link between process and SLD server endpoint
                        vector.add(
                            linkReporter.reportClientServerRelation(
                                processOsh, sldEndpointOsh))

                # - Solution Manager relation
                agentConnectionEndpoint = runtimeConfig.getAgentConnecitonEndpoint(
                )
                if agentConnectionEndpoint:
                    for endpoint in resolveEndpointFn(agentConnectionEndpoint):
                        hostOsh = endpointReporter.reportHostFromEndpoint(
                            endpoint)
                        vector.add(hostOsh)
                        endpointOsh = endpointReporter.reportEndpoint(
                            endpoint, hostOsh)
                        vector.add(endpointOsh)
                        softwareOsh = softwareReporter.reportUknownSoftware(
                            hostOsh)
                        vector.add(softwareOsh)
                        vector.add(
                            linkReporter.reportUsage(softwareOsh, endpointOsh))
                        # report link between process and SolMan end-point
                        vector.add(
                            linkReporter.reportClientServerRelation(
                                processOsh, endpointOsh))