def process(self, context):
        self.shell = context.client
        appOsh = context.application.applicationOsh

        process = first(keep(context.application.getProcess, self.PROCESSES))
        binPath = process.executablePath
        logger.debug('Got process %s' % process)
        logger.debug('Process path is %s' % process.executablePath)
        self._discoverVersionInfo(process, appOsh)
        processes = context.application.getProcesses()
        configurations = (self._discoverConfiguration(p, binPath, appOsh)
                          for p in processes)
        oshs = first(ifilter(bool, configurations))
        oshs and context.resultsVector.addAll(oshs)
예제 #2
0
    def process(self, context):
        self.shell = context.client
        appOsh = context.application.applicationOsh

        process = first(keep(context.application.getProcess, self.PROCESSES))
        binPath = process.executablePath
        logger.debug('Got process %s' % process)
        logger.debug('Process path is %s' % process.executablePath)
        self._discoverVersionInfo(process, appOsh)
        processes = context.application.getProcesses()
        configurations = (self._discoverConfiguration(p, binPath, appOsh)
                          for p in processes)
        oshs = first(ifilter(bool, configurations))
        oshs and context.resultsVector.addAll(oshs)
예제 #3
0
def find(executor, alternatives=None):
    '''Finds lsdev binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev.Cmd
    @raise command.NotFoundException: in case if `lsdev` command is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException(
            'No lsdev binary found among provided path alternatives.')

    lsdev_impls = service_loader.global_lookup[Cmd]
    for lsdev_impl in lsdev_impls:
        if Sfn(lsdev_impl.is_applicable)(bin, executor):
            return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #4
0
    def report(self, oshVector, interaction):
        if self.acceptorEngine.accepts(interaction.srcNode) and\
           self.acceptorEngine.accepts(interaction.dstNode) and interaction.isClientServerRelationDefined():

            client, server, connection = interaction.getClient(), interaction.getServer(), interaction.connection

            server.serviceAddressOsh = server.serviceAddressOsh or self._buildAndReportServiceAddress(server, connection, self.knownPortsConfigFile, oshVector)

            client.processOsh = client.processOsh or self._buildAndReportProcess(client, oshVector)

            serverPortNames = self.getPortNamesByPortNr(server.port, server.ip, connection.protocol, self.knownPortsConfigFile)

            csLink = None
            if client.processOsh is not None and server.serviceAddressOsh is not None:
                csLink = modeling.createLinkOSH('client_server', client.processOsh, server.serviceAddressOsh)
            elif client.hostOsh is not None and server.serviceAddressOsh is not None:
                csLink = modeling.createLinkOSH('client_server', client.hostOsh, server.serviceAddressOsh)
            if not csLink:
                return

            csLink.setStringAttribute('clientserver_protocol', connection.protocol == modeling.TCP_PROTOCOL and 'TCP' or 'UDP')
            if serverPortNames:
                csLink.setStringAttribute('data_name', first(serverPortNames))
            csLink.setLongAttribute('clientserver_destport', int(server.port))

            if self.reportTrafficDetails:
                connection.dPkgs and csLink.setLongAttribute('clientserver_pkts', connection.dPkgs)
                connection.dOctets and csLink.setLongAttribute('clientserver_octets', connection.dOctets)

            oshVector.add(csLink)
예제 #5
0
def find(executor, alternatives=None):
    '''Finds fcinfo binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: fcinfo command implementation
    @rtype: fcinfo_solaris.Cmd
    @raise command.NotFoundException: in case if `fcinfo`
                                        command is not available
    @raise service_loader.NoImplementationException: in case if no
                                                    `fcinfo` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException('No fcinfo binary found')

    fcinfo_impls = [
        Cmd,
    ]
    for fcinfo_impl in fcinfo_impls:
        if fcinfo_impl.is_applicable(bin, executor):
            return partial(fcinfo_impl, bin=bin)
    raise service_loader.NoImplementationException('No fcinfo impl found')
예제 #6
0
def find(executor, alternatives=None):
    '''Finds vmkmgmt_keyval binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: vmkmgmt_keyval command implementation
    @rtype: vmkmgmt_keyval.Cmd
    @raise command.NotFoundException: in case if `vmkmgmt_keyval` command is not available
    @raise service_loader.NoImplementationException: in case if no `vmkmgmt_keyval` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException(
            'No vmkmgmt_keyval binary found among provided path alternatives')

    vmkmgmt_keyval_impls = (Cmd, )
    for vmkmgmt_keyval_impl in vmkmgmt_keyval_impls:
        if Sfn(vmkmgmt_keyval_impl.is_applicable)(bin, executor):
            return partial(vmkmgmt_keyval_impl, bin=bin)
    raise service_loader.NoImplementationException(
        'No vmkmgmt_keyval impl found')
def find(executor, alternatives=None):
    '''Finds lsdev binary and creates vio lsdev wrapper on success

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev_aix_vio_server_impl.Cmd
    @raise command.NotFoundException: in case if `lsdev` command
                                        is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev`
                                                        wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException('No lsdev binary found')

    lsdev_impl = Cmd
    if lsdev_impl.is_applicable(bin, executor):
        return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #8
0
def find(executor, alternatives=None):
    '''Finds vmkmgmt_keyval binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: vmkmgmt_keyval command implementation
    @rtype: vmkmgmt_keyval.Cmd
    @raise command.NotFoundException: in case if `vmkmgmt_keyval` command is not available
    @raise service_loader.NoImplementationException: in case if no `vmkmgmt_keyval` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException('No vmkmgmt_keyval binary found among provided path alternatives')

    vmkmgmt_keyval_impls = (Cmd, )
    for vmkmgmt_keyval_impl in vmkmgmt_keyval_impls:
        if Sfn(vmkmgmt_keyval_impl.is_applicable)(bin, executor):
            return partial(vmkmgmt_keyval_impl, bin=bin)
    raise service_loader.NoImplementationException('No vmkmgmt_keyval impl found')
예제 #9
0
def find(executor, alternatives=None):
    '''Finds lsdev binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev.Cmd
    @raise command.NotFoundException: in case if `lsdev` command is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev` wrapper available
    '''
    alternatives = alternatives or bin_alternatives

    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException('No lsdev binary found among provided path alternatives.')

    lsdev_impls = service_loader.global_lookup[Cmd]
    for lsdev_impl in lsdev_impls:
        if Sfn(lsdev_impl.is_applicable)(bin, executor):
            return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #10
0
def find(executor, alternatives=None):
    '''Finds fcinfo binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: fcinfo command implementation
    @rtype: fcinfo_solaris.Cmd
    @raise command.NotFoundException: in case if `fcinfo`
                                        command is not available
    @raise service_loader.NoImplementationException: in case if no
                                                    `fcinfo` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException('No fcinfo binary found')

    fcinfo_impls = [Cmd, ]
    for fcinfo_impl in fcinfo_impls:
        if fcinfo_impl.is_applicable(bin, executor):
            return partial(fcinfo_impl, bin=bin)
    raise service_loader.NoImplementationException('No fcinfo impl found')
예제 #11
0
def discoverSwitches(client, ips_set, allowDnsLookup, ignoreNodesWithoutIP):
    '''
    @types: Client, set[IPAddress], bool, bool -> generator

    @return: generator of tuples witch such elements
        storage array osh
        list[tuple[Port, osh]]
        list[tuple[Hba, osh]]
        list[tuple[LogicalVolume, osh]]
    @types: Client, set[IPAddress], bool, bool  -> iterable[osh]

    '''
    try:
        switches = _query_switches(client)
    except (Exception, JException):
        logger.warnException("Failed to get switches")
    else:
        for switch in switches:
            ips = _discover_switch_ips(switch, ips_set, allowDnsLookup)
            if ips:
                # change address of switch to IP as reporting depends on it
                switch = switch._replace(address=first(ips))
                each(ips_set.add, ips)
            elif ignoreNodesWithoutIP:
                logger.debug("%s is ignored due to missing IPs" % str(switch))
                continue

            switch_osh = _build_fc_switch_osh(switch)
            port_to_osh = _discoverPortsPerSwitch(client, switch, switch_osh)
            ip_oshs = chain(*[_report_ips(switch_osh, ip) for ip in ips])
            yield switch, switch_osh, port_to_osh, ip_oshs
예제 #12
0
def find(executor, alternatives=None):
    '''Finds lsdev binary and creates vio lsdev wrapper on success

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lsdev command implementation
    @rtype: lsdev_aix_vio_server_impl.Cmd
    @raise command.NotFoundException: in case if `lsdev` command
                                        is not available
    @raise service_loader.NoImplementationException: in case if no `lsdev`
                                                        wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)

    if not bin:
        raise command.NotFoundException('No lsdev binary found')

    lsdev_impl = Cmd
    if lsdev_impl.is_applicable(bin, executor):
        return partial(lsdev_impl, bin=bin)
    raise service_loader.NoImplementationException('No lsdev impl found')
예제 #13
0
def iterate_over_args(main_fn, framework, cred_args, proto_name, stop_on_first):
    '''
    @param cred_args: parameters you decided to iterate over
    '''
    vector = ObjectStateHolderVector()
    framework = flow.RichFramework(framework)
    creds_manager = flow.CredsManager(framework)
    # as cred_args possibly generator or iterator, realize only first
    first_ = first(cred_args)
    if first_ is None:
        logger.reportErrorObject(flow._create_missed_creds_error(proto_name))
    else:
        # restore cred_args
        cred_args = chain((first_,), cred_args)
        connection_exs = []
        discovery_exs = []
        warnings = []
        at_least_once_discovered = False
        for args in cred_args:
            try:
                oshs, warnings_ = main_fn(framework, creds_manager, *args)
                warnings.extend(warnings_ or ())
                vector.addAll(oshs)
                at_least_once_discovered = True
                if stop_on_first:
                    break
            except flow.ConnectionException, ce:
                logger.debugException(str(ce))
                connection_exs.append(ce)
            except (flow.DiscoveryException, Exception, JException), de:
                logger.debugException(str(de))
                discovery_exs.append(de)
예제 #14
0
def find(executor, alternatives=None):
    '''Finds lscfg binary and appropriate wrapper implementation

    @param executor: a command executor instance
    @type executor: command.Executor
    @return: lscfg command implementation
    @rtype: lscfg_aix.Cmd
    @raise command.NotFoundException: in case if `lscfg`
                                        command is not available
    @raise service_loader.NoImplementationException: in case if no
                                                    `lscfg` wrapper available
    '''
    alternatives = alternatives or bin_alternatives
    try:
        bin = is_command_available.find_first(alternatives, executor)
    except service_loader.NoImplementationException:
        bin = first(alternatives)
    if not bin:
        raise command.NotFoundException('No lscfg binary found')

    lscfg_impls = [Cmd, ]
    for lscfg_impl in lscfg_impls:
        if lscfg_impl.is_applicable(bin, executor):
            return partial(lscfg_impl, bin=bin)
    raise service_loader.NoImplementationException('No lscfg impl found')
예제 #15
0
 def process(self, context):
     self.shell = context.client
     appOsh = context.application.applicationOsh
     vector = context.resultsVector
     processes = context.application.getProcesses()
     processes = ifilter(isRequiredProcess, processes)
     configs = (self.discoverConfiguration(p, appOsh) for p in processes)
     vector.addAll(first(ifilter(bool, configs)))
예제 #16
0
def _findJavaSysParameter(params, name):
    r'@types: list[str], str -> str?'
    fullParamName = "-D%s=" % name
    isSysParam = lambda p: p.startswith(fullParamName)
    param = first(filter(isSysParam, params))
    if param:
        value = second(param.split('=', 1))
        return value
예제 #17
0
def resolve_servicename(network_services, svcename, protocol=u'tcp'):
    '''[db2_base_shell_discoverer.NetworkService], str, str? -> db2_base_shell_discoverer.NetworkService'''
    def svcename_protocol_pairs(network_service):
        return network_service.service_name, network_service.protocol

    make_key = juxt(NetworkService.service_name.fget,
                    NetworkService.protocol.fget)
    network_serivces_by_name = fptools.groupby(make_key, network_services)

    return first(network_serivces_by_name.get((svcename.strip(), protocol)))
def resolve_servicename(network_services, svcename, protocol=u"tcp"):
    """[db2_base_shell_discoverer.NetworkService], str, str? -> db2_base_shell_discoverer.NetworkService"""

    def svcename_protocol_pairs(network_service):
        return network_service.service_name, network_service.protocol

    make_key = juxt(NetworkService.service_name.fget, NetworkService.protocol.fget)
    network_serivces_by_name = fptools.groupby(make_key, network_services)

    return first(network_serivces_by_name.get((svcename.strip(), protocol)))
예제 #19
0
def reportScsBasedOnMsgPort(system, hostname, msgEndpoints, systemOsh, clusterOsh,
                            enqEndpoints=(), reportName=False):
    r'''
    @param reportName: influence on `name` attribute reporting. In some cases
        composite name attribute may contain not correct host information that
        has impact on reconciliation. Better do not report data we are not
        sure
    @types: sap.System, str, list[Endpoint], osh, list[Endpoint], bool -> oshv
    '''
    vector = ObjectStateHolderVector()
    if not msgEndpoints:
        logger.warn("Failed to discover SCS - no message server information")
        return vector
    ips = (map(netutils.Endpoint.getAddress, msgEndpoints)
         + map(netutils.Endpoint.getAddress, enqEndpoints))
    hostReporter = sap.HostReporter(sap.HostBuilder())
    hostOsh, hVector = hostReporter.reportHostWithIps(*ips)
    vector.addAll(hVector)

    systemOsh.setStringAttribute('data_note', 'This SAP System link to ' + hostOsh.getAttributeValue('host_key'))
    vector.add(systemOsh)

    instIp = sap.createIp(first(ips))

    msgEndpoint = first(msgEndpoints)
    number = sap_discoverer.parseInstNrInMsgServerPort(msgEndpoint.getPort())
    inst = sap.Instance('SCS', number, hostname=hostname)
    pdo = sap_jee.InstanceBuilder.InstancePdo(inst, system, ipAddress=instIp)

    scsBuilder = sap_jee.ScsInstanceBuilder(reportName=reportName)
    instReporter = sap_jee.InstanceReporter(scsBuilder)
    instOsh = instReporter.reportInstancePdo(pdo, hostOsh)
    vector.add(instOsh)

    linkReporter = sap.LinkReporter()
    vector.add(linkReporter.reportMembership(clusterOsh, instOsh))
    vector.add(linkReporter.reportMembership(systemOsh, instOsh))

    for endpoint in (msgEndpoints + enqEndpoints):
        _, eVector = sap._reportEndpointLinkedToSoftware(endpoint,
                                                        hostOsh, instOsh)
        vector.addAll(eVector)
    return vector
예제 #20
0
 def _executeClusterQuery(self, attributes=()):
     r'@types: -> Properties'
     query = '*:*,j2eeType=SAP_J2EECluster'
     client = self._getClient()
     attributes = ("InstanceNames",) + attributes
     items = client.getMbeansByNamePattern(query, attributes)
     if not items:
         logger.warn("No cluster information was found on the system")
         raise self.NoClusterException()
     return first(items)
def _parse_network_service(content):
    "@types: str -> NetworkService?"
    content = first(content.split("#", 2))
    m = re.match(r"(.+?)\s+(\d+)/(\w+)\s*(.+)?", content)
    if m:
        servicename = m.group(1)
        port = int(m.group(2))
        protocol = m.group(3)
        aliases = m.group(4)
        aliases = aliases and tuple(ifilter(identity, re.split(r"\s+", aliases))) or ()
        return NetworkService(servicename, port, protocol, aliases)
예제 #22
0
def _report_remote(host, svcename, instance_name, version, dbname):
    oshs = []
    db_oshs = None
    if host:
        node_osh, _, oshs_ = db2_host.Reporter().reportHost(host)
        oshs.extend(oshs_)

        oshs_, db_oshs = _report(node_osh, first(host.ips), svcename,
                           instance_name, version, dbname)
        oshs.extend(oshs_)
    return oshs, db_oshs
예제 #23
0
def _report_remote(host, svcename, instance_name, version, dbname):
    oshs = []
    db_oshs = None
    if host:
        node_osh, _, oshs_ = db2_host.Reporter().reportHost(host)
        oshs.extend(oshs_)

        oshs_, db_oshs = _report(node_osh, first(host.ips), svcename,
                                 instance_name, version, dbname)
        oshs.extend(oshs_)
    return oshs, db_oshs
예제 #24
0
def discover_profiles(sap_utils):
    '''
    @return: default profile pair (path and content) and list of pairs of
            instance profiles
    @types: SapUtils -> tuple[tuple[str, str]?, list[tuple[str, str]]]
    '''
    try:
        profiles = get_profiles(sap_utils)
        default_pfs, other_pfs = partition(is_default_pf, profiles)
        return first(default_pfs), other_pfs
    except (Exception, JException), e:
        logger.warnException("Failed to discover profiles. %s" % e)
예제 #25
0
    def _discover_remote_databases(self, context, instname, db2_home_path,
                                   discoverer, executor, interpreter):
        local_dbserver_osh = context.application.applicationOsh
        get_remote_databases = safeFn(discoverer.get_remote_databases)
        node_db_pairs = get_remote_databases(executor, interpreter, instname, db2_home_path=db2_home_path) or ()

        get_node = safeFn(discoverer.get_node)
        reporter = db2_topology.Reporter()
        node_reporter = host_topology.Reporter()

        shell = context.client
        resolvers = (NsLookupDnsResolver(shell), SocketDnsResolver())
        resolve_ips_fn = FallbackResolver(resolvers).resolve_ips
        for nodename, remote_dbs in node_db_pairs:
            node = get_node(executor, interpreter, instname,
                            nodename, db2_home_path=db2_home_path)
            if node:
                host_osh = None
                address = None
                instance_name_ = None
                if node.is_local():
                    host_osh = context.hostOsh
                    address = context.application.getApplicationIp()
                    instance_name_ = node.instance_name
                else:
                    host = host_base_parser.parse_from_address(node.hostname,
                                     fptools.safeFunc(resolve_ips_fn))
                    if host and host.ips:
                        instance_name_ = node.remote_instance_name
                        address = first(host.ips)
                        host_osh, _, oshs_ = node_reporter.report_host_with_ips(host.ips)
                        context.resultsVector.addAll(oshs_)

                if host_osh:
                    get_port_fn = safeFn(discoverer.get_instance_port_by_node)
                    port = get_port_fn(executor, interpreter, node, db2_home_path=db2_home_path)

                    remote_instance = DatabaseServer(address, port)

                    remote_inst_osh, endpoint_osh, _, vector = reporter.reportServerAndDatabases(remote_instance, host_osh)
                    if instance_name_:
                        SoftwareBuilder.updateName(remote_inst_osh, instance_name_)
                        context.resultsVector.addAll(vector)
                        _, oshs = reporter.reportRemoteDatabases(remote_dbs, local_dbserver_osh, remote_inst_osh)
                        context.resultsVector.addAll(oshs)
                    else:
                        logger.debug('No instance name')
                        if endpoint_osh:
                            context.resultsVector.add(endpoint_osh)
                else:
                    logger.debug('Host is not resolved %s' % node.hostname)
            else:
                logger.debug('No node found with name %s' % nodename)
예제 #26
0
def discover_profiles(sap_utils):
    '''
    @return: default profile pair (path and content) and list of pairs of
            instance profiles
    @types: SapUtils -> tuple[tuple[str, str]?, list[tuple[str, str]]]
    '''
    try:
        profiles = get_profiles(sap_utils)
        default_pfs, other_pfs = partition(is_default_pf, profiles)
        return first(default_pfs), other_pfs
    except (Exception, JException), e:
        logger.warnException("Failed to discover profiles. %s" % e)
예제 #27
0
def _parse_network_service(content):
    '@types: str -> NetworkService?'
    content = first(content.split('#', 2))
    m = re.match(r'(.+?)\s+(\d+)/(\w+)\s*(.+)?', content)
    if m:
        servicename = m.group(1)
        port = int(m.group(2))
        protocol = m.group(3)
        aliases = m.group(4)
        aliases = aliases and tuple(
            ifilter(identity, re.split(r'\s+', aliases))) or ()
        return NetworkService(servicename, port, protocol, aliases)
예제 #28
0
    def _buildIpServiceEndpoint(self, server, connection, knownPortsConfigFile):
        protocolType = __getProtocolType(connection.protocol)
        names = self.getPortNamesByPortNr(server.port, server.ip, connection.protocol, knownPortsConfigFile)

        portType = first(names)
        endpoint = Endpoint(int(server.port), protocolType, server.ip,
                            portType=portType)
        reporter = EndpointReporter(ServiceEndpointBuilder())
        endpointOsh = reporter.reportEndpoint(endpoint, server.hostOsh)
        if names:
            ServiceEndpointBuilder.updateServiceNames(endpointOsh, names)
        return endpointOsh
예제 #29
0
def reportInstanceWithSystem(instance_info, ips, system,
                             systemp_osh, client_number=None,
                             application_ip=None,
                             cred_id=None):
    if cred_id:
        logger.info("Credentials are set on %s" % str(instance_info.instance))
    linkReporter = sap.LinkReporter(sap.LinkBuilder())
    server_osh, vector = reportInstanceInfo(instance_info, ips, system,
                                        credsId=cred_id,
                                        connectionClientNr=client_number,
                                        application_ip=first(instance_info.host.address.ips), system_osh=systemp_osh)
    vector.add(linkReporter.reportMembership(systemp_osh, server_osh))
    return server_osh, vector
예제 #30
0
def reportRfcConfig(config, trexHostOsh, resolver):
    r'@types: RfcConfiguration, osh, DnsResolver -> oshv'
    oshs = []
    endpoints = _resolveEndpoint(resolver, config.createGatewayEndpoint())
    if endpoints:
        sapOsh = sap.Reporter(sap.Builder()).reportSystem(config.system)
        oshs.append(sapOsh)
        system = config.system
        inst = first(system.getInstances())
        oshs.extend(reportBareSapInstByEndpoints(endpoints, inst, system, sapOsh))
        # connect served sap system with TREX host by rfc-connection link
        oshs.extend(_reportRfc(inst.getNumber(), sapOsh, trexHostOsh))
    return oshs
예제 #31
0
    def report(self, oshVector, interaction):
        srcNode, dstNode, connection = interaction.srcNode, interaction.dstNode, interaction.connection

        if interaction.isClientServerRelationDefined() and self.acceptorEngine.accepts(srcNode) and self.acceptorEngine.accepts(dstNode) and srcNode.ip != dstNode.ip:
            server = interaction.getServer()
            client = interaction.getClient()
            nodeDependencyLink = modeling.createLinkOSH('node_dependency', client.hostOsh, server.hostOsh)

            portNames = self.getPortNamesByPortNr(server.port, server.ip, connection.protocol, self.knownPortsConfigFile)
            if portNames:
                nodeDependencyLink.setAttribute('dependency_source', first(portNames))
            nodeDependencyLink.setAttribute('dependency_name', str(server.port))
            oshVector.add(nodeDependencyLink)
예제 #32
0
def discoverServers(client, ips_set, ignoreNodesWithoutIP, allowDnsLookup):
    ''' Discover host resources

    @types: Client, set[IPAddress], bool, bool -> generator
    @return: generator of tuples witch such elements
        host osh
        seq[osh] - built IPs
        seq[osh] - built CPUs
        list[tuple[Port, osh]]
        list[tuple[HostHba, osh]]
        list[tuple[LogicalVolume, osh]]
    '''
    try:

        hosts = _query_hosts(client)
        name_to_host = zip(imap(_get_host_name, hosts), hosts)
        has_hostname = comp(any, first)
        name_to_host = _drop("Hosts without hostname", has_hostname, name_to_host)
        for (hostName, hostDnsName), host in name_to_host:
            logger.info("Discover (%s:%s) host topology" % (host.name, host.ip))
            ips = _discover_host_ips(host, hostName, hostDnsName, ips_set, allowDnsLookup)
            if ips:
                each(ips_set.add, ips)
                host = host._replace(ip=first(ips))
            elif ignoreNodesWithoutIP:
                logger.debug("(%s: %s) is ignored due to missing "
                             "or duplicated IP" % (host.id, host.name))
                continue

            hostOSH = _build_host(host, hostName)
            ipOshs = chain(*[_report_ips(hostOSH, ip, hostDnsName) for ip in ips])

            cpuOshs = _report_cpus(host, hostOSH)

            ports = _query_ports(partial(_query_host_ports, client, host.id))
            portOshs = (_report_port(hostOSH, port) for port in ports)
            port_2_osh = zip(ports, portOshs)

            host_hbas = _query_host_hbas(client, host.id)
            hbaOshs = (_report_host_hba(hostOSH, hba) for hba in host_hbas)
            hba_2_osh = zip(host_hbas, hbaOshs)

            volumes = _query_host_logical_volumes(client, host.id)
            volumes = ifilter(LogicalVolume.name.fget, volumes)
            volumeOshs = (_report_logical_volume(hostOSH, v) for v in volumes)
            volume_2_osh = zip(volumes, volumeOshs)
            yield hostOSH, ipOshs, cpuOshs, port_2_osh, hba_2_osh, volume_2_osh
    except:
        excInfo = logger.prepareJythonStackTrace('')
        logger.warn('[' + SCRIPT_NAME + ':discoverServers] Exception: <%s>' % excInfo)
예제 #33
0
def _getDatabase(client):
    r'''Get detabase information.
    Applicable only in new SAP MBean model
    @types: BaseSapJmxClient -> sap_discoverer.DbInfo?
    '''
    attributes = ('DB',)
    query = ('*:cimclass=SAP_ITSAMJ2eeCluster,*')
    props = first(client.getMbeansByNamePattern(query, attributes))
    if props and props.get("DB"):
        compositeDataSupport = props.get("DB")
        name = compositeDataSupport.get("ElementName")
        hostname = compositeDataSupport.get("Host")
        type_ = compositeDataSupport.get("Type")
        return sap_db.DbInfo(name, hostname, type_, None, True)
예제 #34
0
def reportRfcConfig(config, trexHostOsh, resolver):
    r'@types: RfcConfiguration, osh, DnsResolver -> oshv'
    oshs = []
    endpoints = _resolveEndpoint(resolver, config.createGatewayEndpoint())
    if endpoints:
        sapOsh = sap.Reporter(sap.Builder()).reportSystem(config.system)
        oshs.append(sapOsh)
        system = config.system
        inst = first(system.getInstances())
        oshs.extend(
            reportBareSapInstByEndpoints(endpoints, inst, system, sapOsh))
        # connect served sap system with TREX host by rfc-connection link
        oshs.extend(_reportRfc(inst.getNumber(), sapOsh, trexHostOsh))
    return oshs
예제 #35
0
    def parse_show(lines):
        # first line is a server name
        name = lines[0]
        lines = lines[1:]
        grouped = first(command.parser.groupby_unique_key(lines))
        hostname = grouped.get("Hostname")
        description = grouped.get("Description")
        principal = grouped.get("Principal")
        admin_request_port = grouped.get("Administration Request Port")
        is_listening = grouped.get("Listening for authorization database update notifications")

        azn_admin_services = lines[lines.index("AZN Administration Services:") + 1 :]
        return Server.Descriptor(
            name, description, hostname, principal, admin_request_port, is_listening, tuple(azn_admin_services)
        )
예제 #36
0
파일: pdadmin.py 프로젝트: deezeesms/dd-git
    def parse_show(lines):
        #first line is a server name
        name = lines[0]
        lines = lines[1:]
        grouped = first(command.parser.groupby_unique_key(lines))
        hostname = grouped.get('Hostname')
        description = grouped.get('Description')
        principal = grouped.get('Principal')
        admin_request_port = grouped.get('Administration Request Port')
        is_listening = grouped.get('Listening for authorization database update notifications')

        azn_admin_services = lines[lines.index('AZN Administration Services:') + 1:]
        return Server.Descriptor(name, description, hostname, principal,
                                 admin_request_port, is_listening,
                                 tuple(azn_admin_services))
예제 #37
0
def getCredentialId(framework):
    config = (flow.DiscoveryConfigBuilder(framework)
              .dest_data_params_as_list(
        # generic application server instance and client numbers
        'instance_number', 'connection_client')
              .dest_data_required_params_as_str('ip_address')
              .build())
    framework = flow.RichFramework(framework)
    creds_manager = flow.CredsManager(framework)
    cred_args = _getCredsArgsForTopologyJob(creds_manager, config)
    cred_args = _makeSetOfSystemNamesAsLastArgument(cred_args, set())
    first_ = first(cred_args)
    if first_ is None:
        return None
    else:
        return chain((first_,), cred_args)
예제 #38
0
def checkDoubleStack(doc):
    r''' In double stack must be present Java SCS and at least
    one abap instance which central or SCS, one database but two schemas,
    optionally two message servers

    @types: IniDocument -> bool'''
    system = sap_discoverer.parse_system_in_pf(doc)
    instance = sap_discoverer.ProfileParser.parseInstance(doc)
    isAbapMsPresent = first(_parseUsedAbapMsDetails(doc)) is not None
    isJavaMsPresent = _parseUsedJavaMsDetails(doc) is not None
    isAbapCentral = None
    isAbapScs = sap_abap.isCentralServicesInstance(instance)

    return (system.type == sap.SystemType.DS
                     or (isAbapMsPresent and isJavaMsPresent)
                     or (isJavaMsPresent and (isAbapCentral or isAbapScs)))
예제 #39
0
 def _discoverConfiguration(self, process, binPath, appOsh):
     '''
     @types: Process, str, osh -> list[osh]
     @param binPath: main process binary path
     '''
     oshs = []
     cmdline = process.commandLine
     pfPath = sap_discoverer.getProfilePathFromCommandline(cmdline)
     logger.debug('Config File Path %s' % pfPath)
     configFile = getConfigFile(self.shell, pfPath)
     if configFile:
         configDocOsh = modeling.createConfigurationDocumentOshByFile(configFile, appOsh)
         oshs.append(configDocOsh)
         sysName = self.getSapSystemValues(configFile.content).get('sysName')
         if sysName:
             configs = self._discoverGatewayConfigs(sysName, binPath, appOsh)
             oshs.extend(first(configs))
     return oshs
예제 #40
0
def _discoverRfcDestinations(sapUtils, systemOsh, config):
    r'@types: SapUtils, osh, flow.DiscoveryConfigBuilder -> oshv'
    if not config.discoverRFCConnections:
        return ObjectStateHolderVector()

    logger.info('Discover RFC connections')
    getRfcCmd = sap_abap_discoverer.GetRfcDestinationsRfcCommand()
    connections = Sfn(getRfcCmd.getAllRfcConnections)(sapUtils) or ()
    logger.info("Found %s possible RFC connections" % len(connections))
    connections = filter(comp(sap_abap_discoverer.isEnglishVersion, third),
                         connections)
    logger.info("Found %s RFC connections with EN language" % len(connections))
    connByName = applyMapping(first, connections)
    destinations = getRfcCmd.getAllRfcDestinations(sapUtils)
    logger.info("Found %s RFC destinations" % len(destinations))
    # get destinations with valid host
    destinations = [d for d in destinations if _isDestFull(d)]
    logger.info("Found %s destinations with host available" % len(destinations))
    destinationsByHost = groupby(lambda d: d.targetHost, destinations)
    ips = map(Sfn(_resolve), destinationsByHost.iterkeys())

    pairIpToDestinations = zip(ips, destinationsByHost.itervalues())
    resolved, notResolved = partition(first, pairIpToDestinations)

    if notResolved:
        skippedDestsCount = sum([len(dests) for ip, dests in notResolved])
        logger.debug("%s destinations skipped due to not resolved %s hosts" %
                     (skippedDestsCount, len(notResolved)))

    vector = ObjectStateHolderVector()
    for ip, destinations in resolved:
        # TODO:
        # 1) query RFC connections (to get description) only for these
        # destinations as it will reduce amount of data fetched from system
        # One query for connections returns ~8K rows of data, while we are
        # interested in less than ~50 or even less
        # 2) another improvement query only records in English language
        countOfDests = len(destinations)
        host = first(destinations).targetHost
        reportDst = Sfn(_reportRfcDestination)
        logger.debug("%s destinations resolved for %s" % (countOfDests, host))
        vectors = (reportDst(dst, ip, connByName, systemOsh) for dst in destinations)
        each(vector.addAll, ifilter(None, vectors))
    return vector
 def process(self, context):
     shell = context.client
     fs = file_system.createFileSystem(shell)
     path_util = file_system.getPath(fs)
     application = context.application
     osh = application.getOsh()
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     jvm_cmd_line_descriptor = jee.JvmCommandLineDescriptor(cmd_line)
     cmd_line_elements = jvm_cmd_line_descriptor.parseElements()
     java_options = filter(self.__is_java_option, cmd_line_elements)
     parse_fn = partiallyApply(self.parse_server_name, fptools._, path_util)
     server_name = first(keep(parse_fn, java_options))
     logger.debug('server name: %s' % server_name)
     if server_name is not None:
         osh.setAttribute('j2eeserver_servername', server_name)
         #TODO: replace to jee.ServerTopologyBuilder._composeFullName
         osh.setAttribute('j2eeserver_fullname', server_name)
     modeling.setAppServerType(osh)
 def process(self, context):
     shell = context.client
     fs = file_system.createFileSystem(shell)
     path_util = file_system.getPath(fs)
     application = context.application
     osh = application.getOsh()
     process = application.getMainProcesses()[0]
     cmd_line = process.commandLine
     jvm_cmd_line_descriptor = jee.JvmCommandLineDescriptor(cmd_line)
     cmd_line_elements = jvm_cmd_line_descriptor.parseElements()
     java_options = filter(self.__is_java_option, cmd_line_elements)
     parse_fn = partiallyApply(self.parse_server_name, fptools._, path_util)
     server_name = first(keep(parse_fn, java_options))
     logger.debug('server name: %s' % server_name)
     if server_name is not None:
         osh.setAttribute('j2eeserver_servername', server_name)
         #TODO: replace to jee.ServerTopologyBuilder._composeFullName
         osh.setAttribute('j2eeserver_fullname', server_name)
     modeling.setAppServerType(osh)
예제 #43
0
def reportInstanceWithSystem(instance_info,
                             ips,
                             system,
                             systemp_osh,
                             client_number=None,
                             application_ip=None,
                             cred_id=None):
    if cred_id:
        logger.info("Credentials are set on %s" % str(instance_info.instance))
    linkReporter = sap.LinkReporter(sap.LinkBuilder())
    server_osh, vector = reportInstanceInfo(
        instance_info,
        ips,
        system,
        credsId=cred_id,
        connectionClientNr=client_number,
        application_ip=first(instance_info.host.address.ips),
        system_osh=systemp_osh)
    vector.add(linkReporter.reportMembership(systemp_osh, server_osh))
    return server_osh, vector
예제 #44
0
 def _discoverConfiguration(self, process, binPath, appOsh):
     '''
     @types: Process, str, osh -> list[osh]
     @param binPath: main process binary path
     '''
     oshs = []
     cmdline = process.commandLine
     pfPath = sap_discoverer.getProfilePathFromCommandline(cmdline)
     logger.debug('Config File Path %s' % pfPath)
     configFile = getConfigFile(self.shell, pfPath)
     if configFile:
         configDocOsh = modeling.createConfigurationDocumentOshByFile(
             configFile, appOsh)
         oshs.append(configDocOsh)
         sysName = self.getSapSystemValues(
             configFile.content).get('sysName')
         if sysName:
             configs = self._discoverGatewayConfigs(sysName, binPath,
                                                    appOsh)
             oshs.extend(first(configs))
     return oshs