def get_instance_home_by_instance_name(shell, instance_name):
    user_home = get_userhome_by_username(shell, instance_name)
    if not user_home:
        pathtool = file_system.getPathToolByShell(shell)
        user_home = file_system.Path(r'/home/%s' % instance_name, pathtool)

    return compose_instance_home_by_userhome(user_home)
Exemplo n.º 2
0
 def _get_db2_home_path(self, context):
     fileSystem = file_system.createFileSystem(context.client)
     path_tool = file_system.getPathTool(fileSystem)
     if self._main_process.executablePath:
         exe_path = file_system.Path(self._main_process.executablePath,
                                     path_tool)
         return exe_path.get_parent().get_parent()
Exemplo n.º 3
0
def findHdbsqlPathBySid(fs, installationPath, dbSid, is_cmd_exist, shell_executor):
    binName = _HDBSQL_BINARY_NAME
    if fs._shell.isWinOs():
        binName = '%s.exe' % binName

    pathTool = file_system.getPath(fs)

    alternatives = (
                    file_system.Path(installationPath, pathTool) + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + 'exe' + 'linuxx86_64' + 'hdb' + binName,
                    file_system.Path('/usr/sap', pathTool) + dbSid + r'SYS' + r'global' + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/sapmnt', pathTool) + dbSid + _HDBCLIENT_FOLDER_NAME + binName,
                    file_system.Path('/sapmnt', pathTool) + dbSid + r'global' + _HDBCLIENT_FOLDER_NAME + binName,
                    )

    alternatives = imap(shell_interpreter.normalizePath, alternatives)
    binpath = findFirst(Sfn(fs.exists), alternatives)
    if not binpath:
        bin_in_path = is_cmd_exist(binName) | shell_executor
        if not bin_in_path:
            raise NoHdbsqlException('Hdbsql binary not found')
        binpath = binName
    return binpath
Exemplo n.º 4
0
def findBinPathBySid(binName, mainProcessPath, dbSid, fs):
    if fs._shell.isWinOs():
        binName = '%s.exe' % binName

    alternatives = ()
    if mainProcessPath:
        pathTool = file_system.getPath(fs)
        maxDbHomePath = getMaxDbHomeDir(mainProcessPath, dbSid)
        if maxDbHomePath:
            alternatives = (file_system.Path(maxDbHomePath, pathTool) +
                            'programs' + 'bin' + binName,
                            file_system.Path(maxDbHomePath, pathTool) +
                            'globalprograms' + 'bin' + binName)
        else:
            mainProcessFolder = pathTool.dirName(mainProcessPath).strip('" ')
            alternatives = (file_system.Path(mainProcessFolder, pathTool) +
                            binName, )

    alternatives = (shell_interpreter.normalizePath(path_)
                    for path_ in alternatives)
    return findFirst(Sfn(fs.exists), alternatives) or binName
Exemplo n.º 5
0
    def discover(self, name, driverName, scope, shell):
        DSNRegistryEntryDiscoverer.discover(self, name, driverName, scope, shell)
        fs = file_system.createFileSystem(shell)
        path_tool = file_system.getPathTool(fs)
        oracle_home_bin = file_system.Path(self._raw_object.Driver, path_tool).get_parent()
        logger.debug("Oracle home bin folder:%s" % oracle_home_bin)
        if oracle_home_bin:
            self.__oracle_home = oracle_home_bin.get_parent()
            logger.debug("Oracle home:%s" % oracle_home_bin)
            self.__address, self.__port, self.__database = self.__discoverAliasInfo(scope, self.__oracle_home, shell)

        if not self.__address:
            raise flow.DiscoveryException("Address is empty")
Exemplo n.º 6
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
Exemplo n.º 7
0
    def discover(self, name, driverName, scope, shell):
        DSNRegistryEntryDiscoverer.discover(self, name, driverName, scope,
                                            shell)
        fs = file_system.createFileSystem(shell)
        path_tool = file_system.getPathTool(fs)
        db2_home_bin = file_system.Path(self._raw_object.Driver,
                                        path_tool).get_parent()
        if db2_home_bin:
            self.__db2_home = db2_home_bin.get_parent()

            instance_name = self.__parseInstanceName(driverName)
            self.__address, self.__port, self.__database = self.__discoverAliasInfo(
                scope, self.__db2_home, shell, instance_name)

        if not self.__address:
            raise flow.DiscoveryException("Address is empty")
Exemplo n.º 8
0
import command
import file_system
import file_topology
from db2_pyarg_validator import not_none, validate
from db2_base_shell_discoverer import Cmd, parse_network_services


class cat(Cmd):
    def __init__(self, path, handler=command.ReturnOutputResultHandler()):
        Cmd.__init__(self, 'cat %s' % path, handler)


class grep(command.Cmd):
    def __init__(self, pattern, options=None):
        cmdParts = ['grep']
        options and cmdParts.append(options)
        pattern = re.sub(r'"', r'\"', pattern)
        pattern = re.sub(r'\.', r'\\.', pattern)
        cmdParts.append('"%s"' % pattern)
        command.Cmd.__init__(self, ' '.join(cmdParts))


SERVICES_PATH = file_system.Path(r'/etc/services', file_topology.PosixPath())


@validate(not_none, file_system.Path)
def get_network_services(executor, path=SERVICES_PATH):
    '@types: command.CmdExecutor, file_system.Path? -> generator[NetworkService]'
    return parse_network_services(cat(path) | executor)
Exemplo n.º 9
0
        db2cmd = Db2Cmd(cmdline).c.w.i
        executor = command.ChainedCmdlet(db2cmd, executor)
        return original_fn(executor, *args, **kwargs)

    return wrapper


class win_type(Cmd):
    @validate(file_system.Path, optional)
    def __init__(self, path, handler=command.ReturnOutputResultHandler()):
        command.Cmd.__init__(self, 'type %s' % path, handler)


class find(command.Cmd):
    def __init__(self, pattern, options=None):
        cmdParts = ['find']
        options and cmdParts.append(options)
        # Need to escape doublequotes
        pattern = re.sub(r'"', r'""', pattern)
        cmdParts.append('"%s"' % pattern)
        command.Cmd.__init__(self, ' '.join(cmdParts))


SERVICES_PATH = file_system.Path(r'%SystemRoot%\system32\drivers\etc\services',
                                 file_topology.NtPath())


@validate(not_none, file_system.Path)
def get_network_services(executor, path=SERVICES_PATH):
    return parse_network_services(win_type(path) | executor)
Exemplo n.º 10
0
 def handler(self, output):
     return file_system.Path(output, self.pathtool)