def parseServedSystem(self, value): r''' Parse information about SAP system and server that is entry point for web dispatcher (attribute name "wdisp/system_<xx>") SID=<sap-sid>, [MSHOST=<ms-host>, [MSPORT=<ms-http-port> | MSSPORT=<ms-https-port>] | SILOC=<info-file> | EXTSRV=<external-server-list>], [SRCSRV=<src-host>:<source-ports>,] [SRCURL=<source-urls>,] [NR=<sys-no>,] [SCSHOST=<scs-host>] With SAP NetWeaver Kernel 7.20 there is the possibility to manage with one SAP Web Dispatcher several SAP Systems. @types: str -> sap_webdisp.ServedSystem ''' value = value.replace(',', '\n') valueByName = self._getIniParser().\ parseValueByNameMapping(value, valueTransformationFn=string.strip) sapSystem = sap.System(valueByName.get('SID')) #) Collect sources with meta-data of the system's application servers # - message server # - siloc URI # - list of external servers of NON-SAP system metadataSources = [] # system message server if 'MSHOST' in valueByName: port, portType = ('MSPORT' in valueByName and (valueByName.get('MSPORT'), netutils.PortTypeEnum.HTTP) or (valueByName.get('MSSPORT'), netutils.PortTypeEnum.HTTPS)) metadataSources.append(sap_webdisp.MessagingServerSource( netutils.createTcpEndpoint( valueByName.get('MSHOST'), port, portType))) # file path metadataSources.extend(self._findSilocMetadataSourcesIn(valueByName)) # external server list externalServersEndpoints = [] for destination in filter(None, valueByName.get('EXTSRV', '').split(';')): # value can be prefixed with protocol like 'http://' # only address and port must be parsed matchObj = re.match('.*?://(.*?):(\d+)', destination) if matchObj: externalServersEndpoints.append( netutils.createTcpEndpoint(matchObj.group(1), matchObj.group(2))) #) Check for the mapping of served instance to dispatcher service # In case if web-dispatcher has several opened ports for request processing # we can make routing of requests to served systems by different criterias dispatchOptions = [] # criteria # - SRCSRV for serviceStr in filter(None, valueByName.get('SRCSRV', '').split(';')): # such dispatch combination means - if request goes through one of the # specified combination (web-dispatcher host and port) redirect request # to this SAP system dispatchOptions.append(sap_webdisp.HostPortCombination( *serviceStr.split(':'))) # - SRCURL (is not supported by discovery) return sap_webdisp.ServedSystem(sapSystem, metadataSources, externalServersEndpoints, dispatchOptions)
def getHanaDbInstanceEndpoints(self, hostname): services = self.getHanaDbServices(hostname) endpoints = [] for service in services: endpoints.append(netutils.createTcpEndpoint(service.host, service.port)) service.sqlPort and endpoints.append(netutils.createTcpEndpoint(service.host, service.sqlPort, hana.PortTypeEnum.HANA)) return endpoints
def getHanaDbInstanceEndpoints(self, hostname): services = self.getHanaDbServices(hostname) endpoints = [] for service in services: endpoints.append( netutils.createTcpEndpoint(service.host, service.port)) service.sqlPort and endpoints.append( netutils.createTcpEndpoint(service.host, service.sqlPort, hana.PortTypeEnum.HANA)) return endpoints
def parseServerEndpoint(self, value): r''' Parse value of "icm/server_port" attribute in instance profile PROT=<protocol name>, PORT=<port or service name>[, TIMEOUT=<timeout>, PROCTIMEOUT=<proctimeout>, EXTBIND=1, HOST=<host name>, VCLIENT=<SSL Client Verification>] Possible values for PROT are (http, https, smpt, route), route value is note supported @types: str -> netutils.Endpoint or None @return: In case if host is not specified endpoint has '*' as address value which means - bound to all host names (by default) ''' if not value: return None value = value.strip().replace(',', '\n') valueByName = self._getIniParser().\ parseValueByNameMapping(value, valueTransformationFn=string.strip) return (valueByName and netutils.createTcpEndpoint( # if host is not specified mark with asterisk # available to all interfaces valueByName.get('HOST') or '*', valueByName.get('PORT'), netutils.PortTypeEnum.findByName(valueByName.get('PROT')) ) or None )
def parse(self, result): r''' r'@types: IniDoc -> sap.DefaultProfile' ''' profile = sap_discoverer.DefaultProfileParser.parse(self, result) #TODO: find out whether HTTPs can be there msgServerEndpoint = None # Find end-point where message server is located # These parameters specify the host/port on which the message server runs # This entry must be identical for all application servers of an SAP # system and should therefore be set only in the default profile # mshost value - must be known in the hosts database # parameters are outdated if 'rdisp/mshost' in result: port = portType = None # differentiate between HTTP and HTTPs port type port, portType = ('ms/http_port' in result and (result.get('ms/http_port'), netutils.PortTypeEnum.HTTP) or (result.get('ms/https_port'), netutils.PortTypeEnum.HTTPS)) msgServerEndpoint = netutils.createTcpEndpoint( result.get('rdisp/mshost'), port, portType ) return sap_webdisp.DefaultProfile(profile.getSystem(), messageServerEndpoint=msgServerEndpoint )
def _parsePortDeclarationToEndpoint(declaration, number, hostname): r'''Parse string of format PROT=<protocol>, PORT=<number>, TIMEOUT=<number>, where PORT may contain $$ substring that has to be replaced with instance number where this port is opened An example: PROT=HTTPS,PORT=443, HOST=hostname, TIMEOUT=3600, EXTBIND=1 @types: str, str, str -> Endpoint or None @param number: instance number @param hostname: instance hostname ''' declarationAsIni = declaration.replace(',', '\n') iniParser = IniParser() iniDoc = iniParser.parseValueByNameMapping(declarationAsIni, string.strip, string.strip) protocol, port = iniDoc.get('PROT'), iniDoc.get('PORT') if not hostname: hostname = iniDoc.get('HOST') endpoint = None if port and hostname: # check for the substitution placeholder `$$` if port.find('$$') != -1: port = port.replace('$$', number) # determine port type portType = sap.PortTypeEnum.findByName(protocol) endpoint = netutils.createTcpEndpoint(hostname, port, portType) return endpoint
def discoverOAMEndpoint(shell, configFile): """ Discover OAM endpoint in ObAccessClient.xml @types: str -> Endpoint """ logger.debug('find OAM server') root = _buildDocumentForXpath(configFile, 0) xpath = _getXpath() servers = xpath.evaluate( '//CompoundList/ValNameList[@ListName="primaryServer1"]', root, XPathConstants.NODESET) for i in range(0, servers.getLength()): server = servers.item(i) host = xpath.evaluate('//NameValPair[@ParamName="host"]/@Value', server, XPathConstants.STRING) port = xpath.evaluate('//NameValPair[@ParamName="port"]/@Value', server, XPathConstants.STRING) if host and port: logger.debug('got OAM server: %s:%s' % (host, port)) if netutils.isValidIp(host): ip = host else: ip = _resolveHostName(shell, host) if ip: return netutils.createTcpEndpoint(ip, port) else: logger.error('Cannot resolve ip from host name "%s"' % host) else: logger.error('failed to get OAM server') return None
def buildEndpointPdoFromEndpoint(resolve_ips, endpoint): ips = resolve_ips(endpoint.getAddress()) endpoints = [] if ips: for ip in ips: endpoints.append(netutils.createTcpEndpoint(ip, endpoint.getPort(), hana.PortTypeEnum.HANA)) return endpoints
def parse(self, content): r'''@types: str -> RuntimeConfig - smd.agent.connection.transport=ssl - smdserver.port to match the P4 SSL port. (5xxx6 by default) ''' result = self.__iniParser.parseValueByNameMapping(content, string.lower, string.strip) # find out whether SLD information is present sldEndpoint = None sldHostname = result.get('sld.hostname') if sldHostname: sldEndpoint = netutils.createTcpEndpoint( sldHostname, result.get('sld.hostport'), netutils.PortTypeEnum.findByName( result.get('sld.hostprotocol') ) ) return RuntimeConfig( result.get('smd.agent.connection.url'), result.get('sap.solution.manager.server.name'), sldEndpoint )
def createOAMRunningSoftwareOsh(scpId, ip, port, protocolId, version, apacheOsh, vector): """ Create OAM osh on oam endpoint, oam node & client server relation """ logger.debug('submit OAM endpoint: %s:%s' % (ip, port)) endpoint = netutils.createTcpEndpoint(ip, port) builder = netutils.ServiceEndpointBuilder() reporter = netutils.EndpointReporter(builder) nodeOsh = reporter.reportHostFromEndpoint(endpoint) endpointOsh = reporter.reportEndpoint(endpoint, nodeOsh) linkOsh = modeling.createLinkOSH('client_server', apacheOsh, endpointOsh) linkOsh.setStringAttribute('clientserver_protocol', 'tcp') oamServerOsh = modeling.createApplicationOSH('running_software', 'Oracle Access Management', nodeOsh, None, 'oracle_corp') oamServerOsh.setStringAttribute('credentials_id', protocolId) oamServerOsh.setStringAttribute('version', version) usageOsh = modeling.createLinkOSH('usage', oamServerOsh, endpointOsh) vector.add(nodeOsh) vector.add(endpointOsh) vector.add(linkOsh) vector.add(oamServerOsh) vector.add(usageOsh) logger.debug("create ownership between runningsoftware and scp") vector.addAll(scp.createOwnerShip(scpId, oamServerOsh)) logger.debug("create consumer-provider link between apache and runningsoftware") reference = 'connection_type=oam, server_host=%s, server_ip=%s, server_port=%s' % (ip, ip, port) vector.addAll(scp.createCPLinkByOsh(apacheOsh, oamServerOsh, scpId, reference))
def _createEndpointsOfScs(inst): r''' Create endpoints for message server and enqueue based on the parsed information @types: SapJEEMonitoringXmlParser.ScsInstance -> tuple[Endpoint?, Endpoint?] @return: pair of endpoints of message server and enqueue server ''' msgEndpoint, enqEndpoint = None, None if inst.host: address = inst.host.ip or inst.host.name msgPort = inst.messageServerPort if msgPort: msgEndpoint = netutils.createTcpEndpoint(address, msgPort) enqPort = inst.enqueueServerPort if enqPort: enqEndpoint = netutils.createTcpEndpoint(address, enqPort) return msgEndpoint, enqEndpoint
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() knownPortsConfigFile = Framework.getConfigFile(CollectorsParameters.KEY_COLLECTORS_SERVERDATA_PORTNUMBERTOPORTNAME) endpoint = Framework.getDestinationAttribute('ip_port_pair') address, port = endpoint.rsplit(':', 1) endpoint = netutils.createTcpEndpoint(address, port) ipServiceName = Framework.getDestinationAttribute('ip_service_name') if ipServiceName == 'sap_jmx': endpoint = convertToHttpEndpoint(endpoint) if endpoint: logger.debug('Current %s' % endpoint) vector, errors, warnings = _discover(Framework, knownPortsConfigFile, endpoint) logger.debug('Result vector size: %d' % vector.size()) logger.debug('Errors: %s' % errors) logger.debug('Warnings: %s' % warnings) fptools.each(logger.reportErrorObject, errors) fptools.each(logger.reportWarningObject, warnings) else: protocolName = 'sapjmxprotocol' protocolLabel = errormessages.protocolNames[protocolName] messagePattern = errormessages.NO_HTTP_ENDPOINTS_TO_PROCESS_ERROR msg = errormessages.makeErrorMessage(protocolName, pattern=messagePattern) errCode = errorcodes.NO_HTTP_ENDPOINTS_TO_PROCESS errobj = errorobject.createError(errCode, [protocolLabel], msg) logger.reportWarningObject(errobj) return vector
def __resolve(self, policy_server_info): webseal_name, instance_name, host_str, port = policy_server_info endpoints = [] if host_str.lower() == 'localhost': host_str = self.__local_host try: host = host_base_parser.parse_from_address( host_str, self.__dns_resolver.resolve_ips) except: logger.debug('Failed to resolve host %s' % host_str) if host_str.find('.') != -1: logger.debug( 'Host is an FQDN host, will try to resolve host name') host = host_base_parser.parse_from_address( host_str.split('.')[0], self.__dns_resolver.resolve_ips) else: raise ValueError('Failed to resolve WebSeal host.') host = host_base_parser.HostDescriptor(ips=host.ips, name=None, fqdns=[]) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) return webseal_topology.WebsealServerBuilder.create_pdo( name=webseal_name, instance_name=instance_name), host, endpoints
def discoverOAMEndpoint(shell, configFile): """ Discover OAM endpoint in ObAccessClient.xml @types: str -> Endpoint """ logger.debug('find OAM server') root = _buildDocumentForXpath(configFile, 0) xpath = _getXpath() servers = xpath.evaluate('//CompoundList/ValNameList[@ListName="primaryServer1"]', root, XPathConstants.NODESET) for i in range(0, servers.getLength()): server = servers.item(i) host = xpath.evaluate('//NameValPair[@ParamName="host"]/@Value', server, XPathConstants.STRING) port = xpath.evaluate('//NameValPair[@ParamName="port"]/@Value', server, XPathConstants.STRING) if host and port: logger.debug('got OAM server: %s:%s' % (host, port)) if netutils.isValidIp(host): ip = host else: ip = _resolveHostName(shell, host) if ip: return netutils.createTcpEndpoint(ip, port) else: logger.error('Cannot resolve ip from host name "%s"' % host) else: logger.error('failed to get OAM server') return None
def buildEndpointPdoFromEndpoint(resolve_ips, endpoint): ips = resolve_ips(endpoint.getAddress()) endpoints = [] if ips: for ip in ips: endpoints.append( netutils.createTcpEndpoint(ip, endpoint.getPort(), hana.PortTypeEnum.HANA)) return endpoints
def _parceLsofOutput(self, output): results = [] if output: matcher = re.compile('TCP\s+([\d\.]+)\:(\d+)\s+\(LISTEN') for block in re.split('\n', output): match = matcher.search(block) if match and netutils.isValidIp(match.group(1)) and not netutils.isLocalIp(match.group(1)): results.append(netutils.createTcpEndpoint(match.group(1), match.group(2))) return results
def __parseNameserverEndpoints(self, nameserverNode): r'''@types: BaseTopologyConfigParser.Node -> list[netutils.Endpoint] ''' infoNode, port = self.__parseNameserverInfoNode(nameserverNode) createEndpoint = lambda ip, port = port: netutils.createTcpEndpoint(ip, port) return map( createEndpoint, filter(netutils.isValidIp, infoNode.attributes.get('ip', '').split()) )
def _parseAbapMsEndpoint(self, document): r'@types: IniDocument -> Endpoint or None' hostname = document.get('rdisp/mshost') #TODO: any other parameter for port value ? #TODO: what to do with `rdisp/msserv` parameter ? port = document.get('rdisp/msserv_internal') if hostname and port: return netutils.createTcpEndpoint(hostname, port) return None
def _buildDatabaseServer(self, addressItem, sid=None): r'@types: OracleTnsRecordParser._Item -> db.DatabaseServer' address, port = self._decomposeAddressPort(addressItem) databaseServer = db.DatabaseServer(address, port, platform=self.getPlatform()) databaseServer.addEndpoint(netutils.createTcpEndpoint(address, port)) if sid: databaseServer.instance = sid return databaseServer
def _getScsEndpoints(client, clusterName): r'''Get SCS endpoints @return: tuple of hostname, message server end-point and enqueue end-point @types: ?, str -> tuple[str?, Endpoint?, Endpoint?]''' attributes = ('Host', 'MessageServerPort', 'EnqueueServerPort') query = '*:*,name=SCS,j2eeType=SAP_J2EEInstance,SAP_J2EECluster=%s' % clusterName instances = client.getMbeansByNamePattern(query, attributes) msgEndpoint, enqueueEndpoint, hostname = None, None, None if instances and instances[0].get('Host'): info = instances[0] hostname = info.get('Host') msgPort = info.get('MessageServerPort') if msgPort: msgEndpoint = netutils.createTcpEndpoint(hostname, msgPort) enqueuePort = info.get('EnqueueServerPort') if enqueuePort: enqueueEndpoint = netutils.createTcpEndpoint(hostname, enqueuePort) return hostname, msgEndpoint, enqueueEndpoint
def enrich_ports_information(servers, server_to_junction_local_port_map): result = [] for pdo, host, endpoints in servers: ports = server_to_junction_local_port_map.get(pdo.name) if ports and host and host.ips: for ip in host.ips: for port in ports: endpoints.append(netutils.createTcpEndpoint(ip, port)) result.append([pdo, host, endpoints]) return result
def __parseNameserverEndpoints(self, nameserverNode): r'''@types: BaseTopologyConfigParser.Node -> list[netutils.Endpoint] ''' infoNode, port = self.__parseNameserverInfoNode(nameserverNode) createEndpoint = lambda ip, port=port: netutils.createTcpEndpoint( ip, port) return map( createEndpoint, filter(netutils.isValidIp, infoNode.attributes.get('ip', '').split()))
def createGatewayEndpoint(self): r''' Creates GW endpoint using known address and instance number. GW can be accessible on every application server under the TCP port sapgw<nr> , where <nr> is the instance number of the application instance. @types: -> netutils.Endpoint ''' instanceNumber = self.system.getInstances()[0].getNumber() address = sap_discoverer.extractDestinationFromRoute(self.gwAddress) address = address or self.gwAddress port = sap_discoverer.composeGatewayServerPort(instanceNumber) return netutils.createTcpEndpoint(address, port)
def reportTnsListener(self, listener, containerOsh): vector = ObjectStateHolderVector() listenerOsh = listener.build(self._builder) listenerOsh.setContainer(containerOsh) vector.add(listenerOsh) vector.add(containerOsh) endpoint = netutils.createTcpEndpoint(listener.address, listener.getPort()) endpointOsh = self.__endpoint_reporter.reportEndpoint(endpoint, containerOsh) vector.add(endpointOsh) vector.add(modeling.createLinkOSH("usage", listenerOsh, endpointOsh)) return vector
def build_junction_pdo(self, junction_info, dnsresolver): junction, servers = junction_info junction_server_pdos = [] for server in servers: endpoints = [] host = host_base_parser.parse_from_address(server.hostname, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, server.port) endpoints.append(endpoint) junction_server_pdos.append((host, endpoints)) return junction.name, junction_server_pdos
def build_webseal_server_pdo(self, webseal_server, dnsresolver): webseal_server, host, port = webseal_server endpoints = [] host = host_base_parser.parse_from_address(host, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) version = self.__parse_version(webseal_server.version) pdo = webseal_topology.WebsealServerBuilder.create_pdo(webseal_server.name, version=version, application_version=webseal_server.version) return pdo, host, endpoints
def createGatewayEndpoint(self): r''' Creates GW endpoint using known address and instance number. GW can be accessible on every application server under the TCP port sapgw<nr> , where <nr> is the instance number of the application instance. @types: -> netutils.Endpoint ''' instanceNumber = self.system.getInstances()[0].getNumber() address = sap_discoverer.extractDestinationFromRoute( self.gwAddress) address = address or self.gwAddress port = sap_discoverer.composeGatewayServerPort(instanceNumber) return netutils.createTcpEndpoint(address, port)
def build_policy_server_pdo(self, policy_server_info, dnsresolver, local_host): policy_server, host, port = policy_server_info endpoints = [] if host.lower() == 'localhost': host = local_host host = host_base_parser.parse_from_address(host, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) return webseal_topology.PolicyServerBuilder.create_pdo(name=policy_server.name), host, endpoints
def build_ldap_pdo(self, ldap_info, dnsresolver): ldap, host, port = ldap_info endpoints = [] if ldap.type == 'remote': host = host_base_parser.parse_from_address(host, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port, PortTypeEnum.LDAP) endpoints.append(endpoint) ldap_pdo = webseal_topology.LdapBuilder.create_pdo() return ldap_pdo, host, endpoints
def _reportSystems(servedSystems, processOsh, shell, connectionIp, applicationOsh=None): resolveEndpoint = _getEndpResolveFn(shell, connectionIp) vector = ObjectStateHolderVector() softwareBuilder = sap.SoftwareBuilder() softwareReporter = sap.SoftwareReporter(softwareBuilder) linkR = sap.LinkReporter() #x) report details of served systems and relation with web-dispatcher for servedSystem in servedSystems: # report endpoints of external servers endpoints = servedSystem.getExternalServersEndpoints() endpoints = flatten(keep(resolveEndpoint, endpoints)) results = (_reportServerEndp(e, processOsh, applicationOsh) for e in endpoints) vector.addAll(map(third, results)) # report message server endpoint (metadata-source) # and application servers of served system sources = servedSystem.getMetadataSources() msgSources, sources = partition(isMessageServerSource, sources) logger.debug("Report %s msg sources" % len(msgSources)) logger.debug("Report %s other sources" % len(sources)) # process message server, report message server endpoints = keep(sap_webdisp.HasEndpoint.getEndpoint, msgSources) msgBuilder = sap.MessageServerBuilder() msgReporter = sap.CentralComponentReporter(msgBuilder) for e in flatten(keep(resolveEndpoint, endpoints)): e = netutils.createTcpEndpoint(e.getAddress(), e.getPort()) endpOsh, hostOsh, eVector = _reportServerEndp(e, processOsh) vector.addAll(eVector) msgOsh = msgReporter.reportAnonymous(hostOsh) vector.add(msgOsh) vector.add(linkR.reportUsage(msgOsh, endpOsh)) # process non message server sources sources = ifilter(isSourceWithEndpoint, sources) endpoints = keep(sap_webdisp.HasEndpoint.getEndpoint, sources) endpoints.extend(servedSystem.getApplicationServersEndpoints()) endpoints = flatten(keep(resolveEndpoint, endpoints)) for result in (_reportServerEndp(e, processOsh) for e in endpoints): endpOsh, hostOsh, eVector = result vector.addAll(eVector) appServerOsh = softwareReporter.reportUknownSoftware(hostOsh) vector.add(appServerOsh) vector.add(linkR.reportUsage(appServerOsh, endpOsh)) return vector
def __resolve(self, info): host, port = info endpoints = [] if host.lower() == 'localhost' or host.lower() == 'localhost.localdomain': host = self.__local_host host = host_base_parser.parse_from_address(host, self.__dns_resolver.resolve_ips) host = host_base_parser.HostDescriptor(ips=host.ips, name=None, fqdns=[]) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) return (host, endpoints)
def _parceLsofOutput(self, output): results = [] if output: matcher = re.compile('TCP\s+([\d\.]+)\:(\d+)\s+\(LISTEN') for block in re.split('\n', output): match = matcher.search(block) if match and netutils.isValidIp( match.group(1)) and not netutils.isLocalIp( match.group(1)): results.append( netutils.createTcpEndpoint(match.group(1), match.group(2))) return results
def parse(self, url): r'''@types: str -> tuple[db.DatabaseServer] ''' url = self.trimUrlPrefix(url) obj = OracleTnsRecordParser().parse(url) addresses = self._filterAddresses(obj) server = self._buildDatabaseServer(addresses.pop(0)) addEndpoint = lambda addressItem: server.addEndpoint( netutils.createTcpEndpoint(*self._decomposeAddressPort(addressItem))) fptools.each(addEndpoint, addresses) return (server, )
def _parseScsInstance(self, document): r'''@types: IniDocument -> tuple[sap.Instance, Endpoint or None] @return: tuple of SCS instance itself and message server endpoint ''' instance = None msEndpoint = None hostname = document.get('j2ee/scs/host') number = document.get('j2ee/scs/system') msPort = document.get('j2ee/ms/port') if hostname and number: instance = sap.Instance('SCS', number, hostname) if msPort: msEndpoint = netutils.createTcpEndpoint(hostname, msPort) return instance, msEndpoint
def _parsePFilesOutput(self, output): results = [] if output: matcher = re.compile('localaddr/port\s+=\s+([\w\.]+)\s*/\s*(\d+).*listening') for block in re.split('S_ISSOCK', output): match = matcher.search(block) ip = None if match: if not netutils.isValidIp(match.group(1)): ip = netutils.resolveIP(self._shell, match.group(1)) else: ip = match.group(1) if not netutils.isLocalIp(ip): results.append(netutils.createTcpEndpoint(ip, match.group(2))) return results
def build_webseal_server_pdo(self, webseal_server, dnsresolver): webseal_server, host, port = webseal_server endpoints = [] host = host_base_parser.parse_from_address(host, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) version = self.__parse_version(webseal_server.version) pdo = webseal_topology.WebsealServerBuilder.create_pdo( webseal_server.name, version=version, application_version=webseal_server.version) return pdo, host, endpoints
def build_policy_server_pdo(self, policy_server_info, dnsresolver, local_host): policy_server, host, port = policy_server_info endpoints = [] if host.lower() == 'localhost': host = local_host host = host_base_parser.parse_from_address(host, dnsresolver.resolve_ips) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) return webseal_topology.PolicyServerBuilder.create_pdo( name=policy_server.name), host, endpoints
def getHanaReplicationEndpoints(self, hostname): role = self.getCurrentDatabaseReplicationRole() if not role or role not in ReplicationRolesEnum.values(): raise ValueError('Not supported role: %r' % role) ports = None if ReplicationRolesEnum.is_primary(role): ports = GetSecondaryPortFromMServiceReplication(hostname) | self._executor elif ReplicationRolesEnum.is_secondary(role): ports = GetPortFromMServiceReplication(hostname) | self._executor endpoints = [] for port in ports: endpoints.append(netutils.createTcpEndpoint(hostname, port, hana.PortTypeEnum.HANA)) return endpoints
def get_service_endpoints(self, shell, system, endpoints, application_server): r''' Get endpoints used by message server fo SAP System logon via SAP Logon tool @types: Shell, System, list[Endpoint], Application -> list[Endpoint] ''' #sapms<SID> <PORT>/<tcp|udp> # comment service_name = 'sapms%s' % re.escape(system.getName()) service_port = get_service_endpoint_number(shell, service_name) if service_port: logger.debug('Services port %s' % service_port) endpoints = filter(lambda port: port.getPort() == service_port, endpoints) if not endpoints and application_server._applicationIp: address = application_server._applicationIp endpoints = [netutils.createTcpEndpoint(address, service_port)] return endpoints return ()
def getAgentConnecitonEndpoint(self): r''' Parse connection URL as Endpoint @types: -> netutils.Endpoint @tito: {r"ms\://ci.world.news.corp\:8100/P4": netutils.Endpoint("ci.world.news.corp", netutils.ProtocolType.TCP_PROTOCOL 8100) } ''' matchObj = re.match(r"(.*?)://(.*?)[\\:]+(\d+)", self.smdConnectionUrl) if matchObj: portType = (matchObj.group(1).lower().find('p4') != -1 and sap.PortTypeEnum.P4 or sap.PortTypeEnum.HTTP) return netutils.createTcpEndpoint(matchObj.group(2), matchObj.group(3), portType) return None
def __resolve(self, info): host, port = info endpoints = [] if host.lower() == 'localhost' or host.lower( ) == 'localhost.localdomain': host = self.__local_host host = host_base_parser.parse_from_address( host, self.__dns_resolver.resolve_ips) host = host_base_parser.HostDescriptor(ips=host.ips, name=None, fqdns=[]) for ip in host.ips: endpoint = netutils.createTcpEndpoint(ip, port) endpoints.append(endpoint) return (host, endpoints)
def _parsePFilesOutput(self, output): results = [] if output: matcher = re.compile( 'localaddr/port\s+=\s+([\w\.]+)\s*/\s*(\d+).*listening') for block in re.split('S_ISSOCK', output): match = matcher.search(block) ip = None if match: if not netutils.isValidIp(match.group(1)): ip = netutils.resolveIP(self._shell, match.group(1)) else: ip = match.group(1) if not netutils.isLocalIp(ip): results.append( netutils.createTcpEndpoint(ip, match.group(2))) return results
def getHanaReplicationEndpoints(self, hostname): role = self.getCurrentDatabaseReplicationRole() if not role or role not in ReplicationRolesEnum.values(): raise ValueError('Not supported role: %r' % role) ports = None if ReplicationRolesEnum.is_primary(role): ports = GetSecondaryPortFromMServiceReplication( hostname) | self._executor elif ReplicationRolesEnum.is_secondary(role): ports = GetPortFromMServiceReplication(hostname) | self._executor endpoints = [] for port in ports: endpoints.append( netutils.createTcpEndpoint(hostname, port, hana.PortTypeEnum.HANA)) return endpoints
def _parseInstanceInfo(self, item): r'@types: Properties -> InstanceInfo' hostname = item.get('Host') if not hostname: raise ValueError("Address is not specified") ports = keep(item.get, self.ENDPOINT_NAMES) endpoints = [netutils.createTcpEndpoint(hostname, p) for p in ports] state = self._parseInstanceState(item.get('State')) instName = item.get('Caption') fullName = item.get('Name') _inst = sap_discoverer.parseInstanceFromName(instName) instName = _inst.name if fullName: details = sap_discoverer.parseSystemAndInstanceDetails(fullName) _, hostname, nr = details else: nr = _inst.number instanceWithHostname = sap.Instance(instName, nr, hostname=hostname) return self.InstanceInfo(instanceWithHostname, endpoints, state=state)
def parse(self, content): r'''@types: str -> RuntimeConfig - smd.agent.connection.transport=ssl - smdserver.port to match the P4 SSL port. (5xxx6 by default) ''' result = self.__iniParser.parseValueByNameMapping( content, string.lower, string.strip) # find out whether SLD information is present sldEndpoint = None sldHostname = result.get('sld.hostname') if sldHostname: sldEndpoint = netutils.createTcpEndpoint( sldHostname, result.get('sld.hostport'), netutils.PortTypeEnum.findByName( result.get('sld.hostprotocol'))) return RuntimeConfig(result.get('smd.agent.connection.url'), result.get('sap.solution.manager.server.name'), sldEndpoint)
def parseServedSystems(self, content): r''' @types: str -> list[sap_webdisp.ServedSystem] @resource-file: info.icr ''' # SID of served sap system, it can be None if such information is not # present and vice versa systemSid = None appServerEndpointsBySystemName = {} for line in content.splitlines(): line = line.strip() # do not proceed empty lines if not line: continue # file may contain something similar to sections # of such format <hostname>_<SID>_<SYS_NUMBER> sysInfoMatchObj = re.match(r'''(.*?)_([a-z0-9]+?)_(\d\d)$''', line, re.I) if sysInfoMatchObj: _, systemSid, _ = sysInfoMatchObj.groups() else: matchObj = re.match(r'''(.+?)\s+ # protocol type (.+?)\s+ # address (\d+)# port ''', line, re.IGNORECASE | re.VERBOSE) if matchObj: (appServerEndpointsBySystemName.setdefault(systemSid, []). append(netutils.createTcpEndpoint( matchObj.group(2), matchObj.group(3), netutils.PortTypeEnum.findByName(matchObj.group(1))))) servedSystems = [] for sid, endpoints in appServerEndpointsBySystemName.items(): system = (sid and sap.System(sid) or sap_webdisp.UnknownSystem()) servedSystems.append( sap_webdisp.ServedSystem( system, appServersEndpoints=endpoints)) return set(servedSystems)