def discoverTopology(sapUtils, domain, hostname, connInfo): r'''@types: SapUtils, str, str, ConnectionInfo -> oshv, list[str]''' warnings = [] vector = ObjectStateHolderVector() system_name = getSapSystemName(sapUtils) if system_name: system = sap.System(system_name) isSolMan, tmsDomain, instances = consume(warnings, _discoverIsSolutionManager(sapUtils), _discoverTmsDomain(sapUtils), (_discoverInstances(sapUtils, system.getName()) or ())) # find an instance with ip we are connected to connected_instance = find_instance_with_ip(instances, ip_addr.IPAddress(connInfo.ip)) if connected_instance: logger.info("We have connected to instance %s, adding credentials" % str(connected_instance)) # report currently connected instance system_osh = _reportSystem(sapUtils, system, domain, isSolMan, tmsDomain) connected_osh, additional_vector = sap_abap_discoverer.reportInstanceWithSystem(connected_instance, [ip_addr.IPAddress(connInfo.ip)], system, system_osh, application_ip=ip_addr.IPAddress(connInfo.ip), cred_id=connInfo.credsId) # report all instances vector = second(reportInstances(instances, system, system_osh)) vector.addAll(additional_vector) vector.add(connected_osh) vector.add(system_osh) else: warnings.append('Failed to find destination ip among configured server ips. ' 'No Topology will be reported.') else: warnings.append('Failed to find configured servers. ' 'No Topology will be reported.') return vector, warnings
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
def report_vm_node(vm_config, hypervisor_osh): ''' Create VM node identified by virtual interfaces @types: list[ovm_cli.ShowVmCmd.Config], osh -> osh[node]?, seq[osh] ''' name = vm_config.vm.name host_osh = ovm_node.build_vm_node(name) oshs = (modeling.createInterfaceOSH(second(vnic), host_osh) for vnic in vm_config.vnics) oshs = filter(None, oshs) if not oshs: return None, () report_run_link = ovm_linkage.Reporter().execution_environment oshs.append(report_run_link(hypervisor_osh, host_osh)) oshs.append(host_osh) return host_osh, oshs
def discoverTopology(sapUtils, domain, hostname, connInfo): r'''@types: SapUtils, str, str, ConnectionInfo -> oshv, list[str]''' warnings = [] vector = ObjectStateHolderVector() system_name = getSapSystemName(sapUtils) if system_name: system = sap.System(system_name) isSolMan, tmsDomain, instances = consume( warnings, _discoverIsSolutionManager(sapUtils), _discoverTmsDomain(sapUtils), (_discoverInstances(sapUtils, system.getName()) or ())) # find an instance with ip we are connected to connected_instance = find_instance_with_ip( instances, ip_addr.IPAddress(connInfo.ip)) if connected_instance: logger.info( "We have connected to instance %s, adding credentials" % str(connected_instance)) # report currently connected instance system_osh = _reportSystem(sapUtils, system, domain, isSolMan, tmsDomain) connected_osh, additional_vector = sap_abap_discoverer.reportInstanceWithSystem( connected_instance, [ip_addr.IPAddress(connInfo.ip)], system, system_osh, application_ip=ip_addr.IPAddress(connInfo.ip), cred_id=connInfo.credsId) # report all instances vector = second(reportInstances(instances, system, system_osh)) vector.addAll(additional_vector) vector.add(connected_osh) vector.add(system_osh) else: warnings.append( 'Failed to find destination ip among configured server ips. ' 'No Topology will be reported.') else: warnings.append('Failed to find configured servers. ' 'No Topology will be reported.') return vector, warnings
def _reportRfcDestination(dst, ip, connByName, systemOsh): r'@types: RfcDestination, str, dict[str, str], osh -> oshv' vector = ObjectStateHolderVector() type_ = RFC_CONNECTION_TYPES.get(dst.type) hostOsh = modeling.createHostOSH(ip) vector.add(hostOsh) targetOsh = hostOsh if dst.type == sap.RfcConnectionTypeEnum.INTERNAL.name: serverOsh = createAppServerOSH(hostOsh, dst.name, dst.instNr) vector.add(serverOsh) targetOsh = serverOsh description = second(connByName.get(dst.name)) linkBuilder = sap.LinkBuilder() rfc = linkBuilder.RfcConnection(type_, dst.instNr, dst.program, dst.name, description, dst.connClientNr) rfcOsh = linkBuilder.buildRfcConnection(rfc, systemOsh, targetOsh) vector.add(rfcOsh) return vector
def parse_xml_result(buffer): ''' @types: str -> bool, str, xml.etree.ElementTree.Element @raise ValueError: if output is not valid, doesn't contain Result tag @raise ValueError: if command failed, message of exception taken from ErrorMsg tag ''' if buffer.find('<Result>') == -1: raise ValueError(buffer) # strip command itself and <xml> tag in the beginning result = second(buffer.split('<Result>', 1)) result = "<Result>" + result root = ET.fromstring(result) status = root.find('./Status').text status = status.lower() == 'success' if not status: error_msg = root.find(r'./ErrorMsg').text raise ValueError(error_msg) data = root.find(r'./CommandData') time_ = root.find(r'./Time').text return status, time_, data
def _discoverBasedOnProfilesUnsafe(sapUtils, oshPerInstance, system, systemOsh, discoverSapProfiles): '@types: SapUtils, dict[Instance, osh], System, osh, bool -> oshv' r = discoverTopologyBasedOnProfiles(sapUtils, system.getName(), systemOsh) pfNameToOsh, defaultPf, otherPfs = r pfSetByInstName = _groupPfsIniByInstanceName(otherPfs) instOshs = oshPerInstance.itervalues() vector = ObjectStateHolderVector() if discoverSapProfiles: vector.addAll(pfNameToOsh.values()) vector.addAll(_reportInstPfLinks(instOshs, pfNameToOsh, system)) defaultPfDoc = None if defaultPf: defaultPfDoc = IniParser.parseIniDoc(second(defaultPf)) try: logger.info("Trying to discover ASCS") vector.addAll(_discoverAscsInPf(defaultPfDoc, system, systemOsh, oshPerInstance)) except SapSystemInconsistentDataException, e: logger.debugException('') raise e except: