Beispiel #1
0
    def __init__(self, pool, interfacesToLookup, currentHostNameAnswersForInterfaces):
        self.__hostCache={}         # interface -> hostname

        # Read the .gphostcache file if it exists
        if os.path.isfile(CACHEFILE):
            try:
                for line in readAllLinesFromFile(CACHEFILE, stripLines=True, skipEmptyLines=True):
                    if line[0] == '#': # okay check because empty lines are skipped
                        continue

                    arr = line.split(':')
                    if len(arr) == 2 and len(arr[0]) > 0 and len(arr[1]) > 0:
                        (interface, hostname) = arr
                        self.__hostCache[interface.strip()]=hostname.strip()
            except Exception, e:
                logger.warn("Error reading file '%s': %s" % (CACHEFILE, str(e)))
Beispiel #2
0
    def __init__(self, pool, interfacesToLookup, currentHostNameAnswersForInterfaces):
        self.__hostCache={}         # interface -> hostname

        # Read the .gphostcache file if it exists
        if os.path.isfile(CACHEFILE):
            try:
                for line in readAllLinesFromFile(CACHEFILE, stripLines=True, skipEmptyLines=True):
                    if line[0] == '#': # okay check because empty lines are skipped
                        continue

                    arr = line.split(':')
                    if len(arr) == 2 and len(arr[0]) > 0 and len(arr[1]) > 0:
                        (interface, hostname) = arr
                        self.__hostCache[interface.strip()]=hostname.strip()
            except Exception, e:
                logger.warn("Error reading file '%s': %s" % (CACHEFILE, str(e)))
Beispiel #3
0
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile,
                                         stripLines=True,
                                         skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            for line in lines:
                if index == maxPrimariesPerHost:
                    raise Exception('Number of %s directories must equal %d but more were read from %s' % \
                                    (labelOfPathsBeingRead, maxPrimariesPerHost, configFile))

                path = normalizeAndValidateInputPath(line, "config file")
                dirs.append(path)
                index += 1
            if index < maxPrimariesPerHost:
                raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                                (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print(
                    'Enter mirror segment data directory location %d of %d >' %
                    (len(dirs) + 1, maxPrimariesPerHost))
                line = input().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException as e:
                        print("\n%s\n" % e)

        return dirs
Beispiel #4
0
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile, stripLines=True, skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            for line in lines:
                if index == maxPrimariesPerHost:
                    raise Exception('Number of %s directories must equal %d but more were read from %s' % \
                                    (labelOfPathsBeingRead, maxPrimariesPerHost, configFile))

                path = normalizeAndValidateInputPath(line, "config file")
                dirs.append(path)
                index += 1
            if index < maxPrimariesPerHost:
                raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                                (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print 'Enter mirror segment data directory location %d of %d >' % (len(dirs) + 1, maxPrimariesPerHost)
                line = raw_input().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException, e:
                        print "\n%s\n" % e
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []
        filespaceOidToPathMaps = []
        while len(filespaceOidToPathMaps) < maxPrimariesPerHost:
            filespaceOidToPathMaps.append({})

        filespaceNameToOid = {}
        for fs in gpArray.getFilespaces(False):
            filespaceNameToOid[fs.getName()] = fs.getOid()

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile, stripLines=True, skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            fsOid = gparray.SYSTEM_FILESPACE
            enteredFilespaces = {}
            for line in lines:
                if line.startswith("filespace "):
                    if index < maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

                    fsName = line[len("filespace "):].strip()
                    labelOfPathsBeingRead = fsName

                    if fsName not in filespaceNameToOid:
                        raise Exception("Unknown filespace %s specified in input file %s" % \
                            (fsName, configFile))
                    fsOid = filespaceNameToOid[fsName]
                    
                    if gpArray.isFileSpaceShared(fsOid):
                        raise Exception("Shared filespace %s does not need to specify in input file %s" % \
                            (fsName, configFile))

                    if fsName in enteredFilespaces:
                        raise Exception( "Filespace %s specified twice in input file %s" % \
                            (fsName, configFile))
                    enteredFilespaces[fsName] = True

                    index = 0
                else:
                    if index == maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but more were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, configFile))

                    path = normalizeAndValidateInputPath(line, "config file")
                    if fsOid == gparray.SYSTEM_FILESPACE:
                        dirs.append(path)
                    else:
                        filespaceOidToPathMaps[index][fsOid] = path
                    index += 1
            if index < maxPrimariesPerHost:
                raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                    (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

            # The shared filespace path will set later.
            for (fsName, fsOid) in filespaceNameToOid.iteritems():
                if fsName in enteredFilespaces:
                    continue
                if not gpArray.isFileSpaceShared(fsOid):
                    break
                for index in range(maxPrimariesPerHost):
                    filespaceOidToPathMaps[index][fsOid] = None
                enteredFilespaces[fsName] = True

            if len(enteredFilespaces) != len(filespaceNameToOid):
                raise Exception("Only read directories for %d of %d filespaces from %s" % \
                    (len(enteredFilespaces), len(filespaceNameToOid), configFile))
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print 'Enter mirror segment data directory location %d of %d >' % (len(dirs)+1, maxPrimariesPerHost)
                line = sys.stdin.readline().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException, e:
                        print "\n%s\n" % e


            for fs in gpArray.getFilespaces(False):
                # Shared storage path can only be set when we know the
                # relationship between the primary and mirror.
                fsys = fs.getFsys()
                delay_set = False
                if fsys != None and fsys.isShared():
                    delay_set = True
                    print 'Skip filespace "%s" stored on the shared filesystem "%s"' % (fs.getName(), fsys.getName())

                index = 0
                while index < maxPrimariesPerHost:
                    if delay_set:
                        filespaceOidToPathMaps[index][fs.getOid()] = None
                        index += 1
                        continue

                    print "Enter mirror filespace '%s' directory location %d of %d >" % \
                                (fs.getName(), index+1, maxPrimariesPerHost)
                    line = sys.stdin.readline().strip()
                    if len(line) > 0:
                        try:
                            filespaceOidToPathMaps[index][fs.getOid()] = normalizeAndValidateInputPath(line)
                            index += 1
                        except PathNormalizationException, e:
                            print "\n%s\n" % e
Beispiel #6
0
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []
        filespaceOidToPathMaps = []
        while len(filespaceOidToPathMaps) < maxPrimariesPerHost:
            filespaceOidToPathMaps.append({})

        filespaceNameToOid = {}
        for fs in gpArray.getFilespaces(False):
            filespaceNameToOid[fs.getName()] = fs.getOid()

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile,
                                         stripLines=True,
                                         skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            fsOid = gparray.SYSTEM_FILESPACE
            enteredFilespaces = {}
            for line in lines:
                if line.startswith("filespace "):
                    if index < maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

                    fsName = line[len("filespace "):].strip()
                    labelOfPathsBeingRead = fsName

                    if fsName not in filespaceNameToOid:
                        raise Exception("Unknown filespace %s specified in input file %s" % \
                            (fsName, configFile))
                    fsOid = filespaceNameToOid[fsName]

                    if fsName in enteredFilespaces:
                        raise Exception( "Filespace %s specified twice in input file %s" % \
                            (fsName, configFile))
                    enteredFilespaces[fsName] = True

                    index = 0
                else:
                    if index == maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but more were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, configFile))

                    path = normalizeAndValidateInputPath(line, "config file")
                    if fsOid == gparray.SYSTEM_FILESPACE:
                        dirs.append(path)
                    else:
                        filespaceOidToPathMaps[index][fsOid] = path
                    index += 1
            if index < maxPrimariesPerHost:
                raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                    (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

            if len(enteredFilespaces) != len(filespaceNameToOid):
                raise Exception("Only read directories for %d of %d filespaces from %s" % \
                    (len(enteredFilespaces), len(filespaceNameToOid), configFile))
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print 'Enter mirror segment data directory location %d of %d >' % (
                    len(dirs) + 1, maxPrimariesPerHost)
                line = sys.stdin.readline().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException, e:
                        print "\n%s\n" % e

            for fs in gpArray.getFilespaces(False):
                index = 0
                while index < maxPrimariesPerHost:
                    print "Enter mirror filespace '%s' directory location %d of %d >" % \
                                (fs.getName(), index+1, maxPrimariesPerHost)
                    line = sys.stdin.readline().strip()
                    if len(line) > 0:
                        try:
                            filespaceOidToPathMaps[index][fs.getOid(
                            )] = normalizeAndValidateInputPath(line)
                            index += 1
                        except PathNormalizationException, e:
                            print "\n%s\n" % e
Beispiel #7
0
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []
        filespaceOidToPathMaps = []
        while len(filespaceOidToPathMaps) < maxPrimariesPerHost:
            filespaceOidToPathMaps.append({})

        filespaceNameToOid = {}
        for fs in gpArray.getFilespaces(False):
            filespaceNameToOid[fs.getName()] = fs.getOid()

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile,
                                         stripLines=True,
                                         skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            fsOid = gparray.SYSTEM_FILESPACE
            enteredFilespaces = {}
            for line in lines:
                if line.startswith("filespace "):
                    if index < maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

                    fsName = line[len("filespace "):].strip()
                    labelOfPathsBeingRead = fsName

                    if fsName not in filespaceNameToOid:
                        raise Exception("Unknown filespace %s specified in input file %s" % \
                            (fsName, configFile))
                    fsOid = filespaceNameToOid[fsName]

                    if gpArray.isFileSpaceShared(fsOid):
                        raise Exception("Shared filespace %s does not need to specify in input file %s" % \
                            (fsName, configFile))

                    if fsName in enteredFilespaces:
                        raise Exception( "Filespace %s specified twice in input file %s" % \
                            (fsName, configFile))
                    enteredFilespaces[fsName] = True

                    index = 0
                else:
                    if index == maxPrimariesPerHost:
                        raise Exception('Number of %s directories must equal %d but more were read from %s' % \
                            (labelOfPathsBeingRead, maxPrimariesPerHost, configFile))

                    path = normalizeAndValidateInputPath(line, "config file")
                    if fsOid == gparray.SYSTEM_FILESPACE:
                        dirs.append(path)
                    else:
                        filespaceOidToPathMaps[index][fsOid] = path
                    index += 1
            if index < maxPrimariesPerHost:
                raise Exception('Number of %s directories must equal %d but %d were read from %s' % \
                    (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile))

            # The shared filespace path will set later.
            for (fsName, fsOid) in filespaceNameToOid.iteritems():
                if fsName in enteredFilespaces:
                    continue
                if not gpArray.isFileSpaceShared(fsOid):
                    break
                for index in range(maxPrimariesPerHost):
                    filespaceOidToPathMaps[index][fsOid] = None
                enteredFilespaces[fsName] = True

            if len(enteredFilespaces) != len(filespaceNameToOid):
                raise Exception("Only read directories for %d of %d filespaces from %s" % \
                    (len(enteredFilespaces), len(filespaceNameToOid), configFile))
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print 'Enter mirror segment data directory location %d of %d >' % (
                    len(dirs) + 1, maxPrimariesPerHost)
                line = sys.stdin.readline().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException, e:
                        print "\n%s\n" % e

            for fs in gpArray.getFilespaces(False):
                # Shared storage path can only be set when we know the
                # relationship between the primary and mirror.
                fsys = fs.getFsys()
                delay_set = False
                if fsys != None and fsys.isShared():
                    delay_set = True
                    print 'Skip filespace "%s" stored on the shared filesystem "%s"' % (
                        fs.getName(), fsys.getName())

                index = 0
                while index < maxPrimariesPerHost:
                    if delay_set:
                        filespaceOidToPathMaps[index][fs.getOid()] = None
                        index += 1
                        continue

                    print "Enter mirror filespace '%s' directory location %d of %d >" % \
                                (fs.getName(), index+1, maxPrimariesPerHost)
                    line = sys.stdin.readline().strip()
                    if len(line) > 0:
                        try:
                            filespaceOidToPathMaps[index][fs.getOid(
                            )] = normalizeAndValidateInputPath(line)
                            index += 1
                        except PathNormalizationException, e:
                            print "\n%s\n" % e
Beispiel #8
0
    def __getDataDirectoriesForMirrors(self, maxPrimariesPerHost, gpArray):
        dirs = []
        filespaceOidToPathMaps = []
        while len(filespaceOidToPathMaps) < maxPrimariesPerHost:
            filespaceOidToPathMaps.append({})

        filespaceNameToOid = {}
        for fs in gpArray.getFilespaces(False):
            filespaceNameToOid[fs.getName()] = fs.getOid()

        configFile = self.__options.mirrorDataDirConfigFile
        if configFile is not None:

            #
            # load from config file
            #
            lines = readAllLinesFromFile(configFile, stripLines=True, skipEmptyLines=True)

            labelOfPathsBeingRead = "data"
            index = 0
            fsOid = gparray.SYSTEM_FILESPACE
            enteredFilespaces = {}
            for line in lines:
                if line.startswith("filespace "):
                    if index < maxPrimariesPerHost:
                        raise Exception(
                            "Number of %s directories must equal %d but %d were read from %s"
                            % (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile)
                        )

                    fsName = line[len("filespace ") :].strip()
                    labelOfPathsBeingRead = fsName

                    if fsName not in filespaceNameToOid:
                        raise Exception("Unknown filespace %s specified in input file %s" % (fsName, configFile))
                    fsOid = filespaceNameToOid[fsName]

                    if fsName in enteredFilespaces:
                        raise Exception("Filespace %s specified twice in input file %s" % (fsName, configFile))
                    enteredFilespaces[fsName] = True

                    index = 0
                else:
                    if index == maxPrimariesPerHost:
                        raise Exception(
                            "Number of %s directories must equal %d but more were read from %s"
                            % (labelOfPathsBeingRead, maxPrimariesPerHost, configFile)
                        )

                    path = normalizeAndValidateInputPath(line, "config file")
                    if fsOid == gparray.SYSTEM_FILESPACE:
                        dirs.append(path)
                    else:
                        filespaceOidToPathMaps[index][fsOid] = path
                    index += 1
            if index < maxPrimariesPerHost:
                raise Exception(
                    "Number of %s directories must equal %d but %d were read from %s"
                    % (labelOfPathsBeingRead, maxPrimariesPerHost, index, configFile)
                )

            if len(enteredFilespaces) != len(filespaceNameToOid):
                raise Exception(
                    "Only read directories for %d of %d filespaces from %s"
                    % (len(enteredFilespaces), len(filespaceNameToOid), configFile)
                )
        else:

            #
            # get from stdin
            #
            while len(dirs) < maxPrimariesPerHost:
                print "Enter mirror segment data directory location %d of %d >" % (len(dirs) + 1, maxPrimariesPerHost)
                line = sys.stdin.readline().strip()
                if len(line) > 0:
                    try:
                        dirs.append(normalizeAndValidateInputPath(line))
                    except PathNormalizationException, e:
                        print "\n%s\n" % e

            for fs in gpArray.getFilespaces(False):
                index = 0
                while index < maxPrimariesPerHost:
                    print "Enter mirror filespace '%s' directory location %d of %d >" % (
                        fs.getName(),
                        index + 1,
                        maxPrimariesPerHost,
                    )
                    line = sys.stdin.readline().strip()
                    if len(line) > 0:
                        try:
                            filespaceOidToPathMaps[index][fs.getOid()] = normalizeAndValidateInputPath(line)
                            index += 1
                        except PathNormalizationException, e:
                            print "\n%s\n" % e