def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    protocol = Framework.getDestinationAttribute('Protocol')
    protocolName = errormessages.protocolNames.get(protocol) or protocol

    hostId = Framework.getDestinationAttribute('hostId')
    isSuccessfull = 1
    try:
        client = None
        try:

            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)

            triggerConfigs = emc_autostart_discover.createTriggerConfigs(
                Framework)
            logger.debug("Found %d configurations" % len(triggerConfigs))

            topology = None

            for triggerConfig in triggerConfigs:
                try:
                    layout = emc_autostart_discover.createLayout(shell)
                    discoverer = emc_autostart_discover.createDiscoverer(
                        shell, Framework, layout)

                    topology = discoverer.discover(triggerConfig)

                    if topology is not None:
                        reporter = emc_autostart_report.createAutoStartReporter(
                            Framework, hostId)
                        resultsVector = reporter.report(topology)
                        OSHVResult.addAll(resultsVector)
                        break

                except emc_autostart_discover.NoApplicationFoundException, ex:
                    msg = "Skipping configuration %r, reason: %s" % (
                        triggerConfig, str(ex))
                    logger.warn(msg)

        finally:
            client and client.close()

    except emc_autostart_discover.InsufficientPermissionsException, ex:
        msg = "Command execution failed due to insufficient permissions"
        errormessages.resolveAndReport(msg, protocolName, Framework)
        isSuccessfull = 0
        logger.error(
            "Failed to execute '%s' command due to insufficient permissions, verify sudo/credentials configuration"
            % str(ex))
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    protocol = Framework.getDestinationAttribute('Protocol')
    protocolName = errormessages.protocolNames.get(protocol) or protocol
    
    hostId = Framework.getDestinationAttribute('hostId')
    isSuccessfull = 1
    try:
        client = None
        try:

            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)

            
            triggerConfigs = emc_autostart_discover.createTriggerConfigs(Framework)
            logger.debug("Found %d configurations" % len(triggerConfigs))
            
            topology = None
            
            for triggerConfig in triggerConfigs:
                try:
                    layout = emc_autostart_discover.createLayout(shell)
                    discoverer = emc_autostart_discover.createDiscoverer(shell, Framework, layout)
                    
                    topology = discoverer.discover(triggerConfig)
                    
                    if topology is not None:
                        reporter = emc_autostart_report.createAutoStartReporter(Framework, hostId)
                        resultsVector = reporter.report(topology)
                        OSHVResult.addAll(resultsVector)
                        break
                    
                except emc_autostart_discover.NoApplicationFoundException, ex:
                    msg = "Skipping configuration %r, reason: %s" % (triggerConfig, str(ex)) 
                    logger.warn(msg)
            
        finally:
            client and client.close()
    
    except emc_autostart_discover.InsufficientPermissionsException, ex:
        msg = "Command execution failed due to insufficient permissions"
        errormessages.resolveAndReport(msg, protocolName, Framework)
        isSuccessfull = 0
        logger.error("Failed to execute '%s' command due to insufficient permissions, verify sudo/credentials configuration" % str(ex))
Example #3
0
    def process(self, context):
        r'''
         @types: applications.ApplicationSignatureContext
        '''
        self.__shell = context.client
        osh = context.application.applicationOsh
        hostOsh = context.hostOsh
        processes = context.application.getProcesses()
        vector = context.resultsVector
        layout = emc_autostart_discover.createLayout(self.__shell)
        clusterVersion = None

        for processFtAgent in filter(isFtAgentProcess, processes):
            process = _createFixedFtAgentProcess(processFtAgent)
            reporter = process_module.Reporter()
            builder = process_module.ProcessBuilder()
            processOsh, pVector = reporter.report(hostOsh, process, builder)
            vector.addAll(pVector)
            vector.add(modeling.createLinkOSH('dependency', osh, processOsh))

            if not clusterVersion:
                layout.initWithAgentPath(process.executablePath)
                self.ftCli = emc_autostart_discover.createCli(self.__shell, layout.getBinFolder())
                version = emc_autostart_discover.getVersionByFtCli(self.__shell, self.ftCli)
                clusterVersion = version.fullString or version.shortString
                osh.setAttribute("application_version", clusterVersion)
                osh.setAttribute("application_version_number",
                                 version.shortString)

        if clusterVersion:
            # discover cluster
            domainName = context.application.getOsh().getAttribute("name").getStringValue()
            clusterOsh = buildEMCClusterOsh(domainName, clusterVersion)
            vector.add(clusterOsh)
            vector.add(modeling.createLinkOSH('membership', clusterOsh, osh))

            # discover group
            discoverer = emc_autostart_discover.createDiscoverer(self.__shell, None, layout)
            discoverer.ftCli = self.ftCli
            resourceGroupsByName = discoverer.discoverResourceGroups()

            # discover IP
            managedIpsByName = discoverer.discoverManagedIps()

            if resourceGroupsByName:
                for key in resourceGroupsByName:
                    group = resourceGroupsByName.get(key)
                    resources = group.resources
                    if resources:
                        for resource in resources:
                            if resource.getType() == "IP":
                                ipName = resource.getName()
                                managedIp = managedIpsByName.get(ipName, None)
                                if managedIp:
                                    ipAddress = managedIp.ipAddress
                                    groupOsh = buildResourceGroupOsh(group.getName(), domainName)
                                    vector.add(groupOsh)
                                    vector.add(modeling.createLinkOSH('contained', clusterOsh, groupOsh))

                                    ipOsh = modeling.createIpOSH(ipAddress)
                                    vector.add(modeling.createLinkOSH('contained', groupOsh, ipOsh))
                                    vector.add(ipOsh)
                                    context.crgMap[str(ipAddress)] = groupOsh