def conf_files(self, **kwargs): """Get conf files for this server :param: number, if supplied will only lookup the nth server :returns: list of conf files """ if self.server in STANDALONE_SERVERS: found_conf_files = search_tree(SWIFT_DIR, self.server + '*', '.conf') else: found_conf_files = search_tree(SWIFT_DIR, '%s-server*' % self.type, '.conf') number = kwargs.get('number') if number: try: conf_files = [found_conf_files[number - 1]] except IndexError: conf_files = [] else: conf_files = found_conf_files if not conf_files: # maybe there's a config file(s) out there, but I couldn't find it! if not kwargs.get('quiet'): print _('Unable to locate config %sfor %s') % ( ('number %s ' % number if number else ''), self.server) if kwargs.get('verbose') and not kwargs.get('quiet'): if found_conf_files: print _('Found configs:') for i, conf_file in enumerate(found_conf_files): print ' %d) %s' % (i + 1, conf_file) return conf_files
def _find_conf_files(self, server_search): if self.conf is not None: return search_tree(SWIFT_DIR, server_search, self.conf + '.conf', dir_ext=self.conf + '.conf.d') else: return search_tree(SWIFT_DIR, server_search + '*', '.conf', dir_ext='.conf.d')
def test_search_tree(self): # file match & ext miss with temptree(["asdf.conf", "blarg.conf", "asdf.cfg"]) as t: asdf = utils.search_tree(t, "a*", ".conf") self.assertEquals(len(asdf), 1) self.assertEquals(asdf[0], os.path.join(t, "asdf.conf")) # multi-file match & glob miss & sort with temptree(["application.bin", "apple.bin", "apropos.bin"]) as t: app_bins = utils.search_tree(t, "app*", "bin") self.assertEquals(len(app_bins), 2) self.assertEquals(app_bins[0], os.path.join(t, "apple.bin")) self.assertEquals(app_bins[1], os.path.join(t, "application.bin")) # test file in folder & ext miss & glob miss files = ("sub/file1.ini", "sub/file2.conf", "sub.bin", "bus.ini", "bus/file3.ini") with temptree(files) as t: sub_ini = utils.search_tree(t, "sub*", ".ini") self.assertEquals(len(sub_ini), 1) self.assertEquals(sub_ini[0], os.path.join(t, "sub/file1.ini")) # test multi-file in folder & sub-folder & ext miss & glob miss files = ("folder_file.txt", "folder/1.txt", "folder/sub/2.txt", "folder2/3.txt", "Folder3/4.txt" "folder.rc") with temptree(files) as t: folder_texts = utils.search_tree(t, "folder*", ".txt") self.assertEquals(len(folder_texts), 4) f1 = os.path.join(t, "folder_file.txt") f2 = os.path.join(t, "folder/1.txt") f3 = os.path.join(t, "folder/sub/2.txt") f4 = os.path.join(t, "folder2/3.txt") for f in [f1, f2, f3, f4]: self.assert_(f in folder_texts)
def conf_files(self, **kwargs): """Get conf files for this server :param: number, if supplied will only lookup the nth server :returns: list of conf files """ if self.server in STANDALONE_SERVERS: found_conf_files = search_tree(SWIFT_DIR, self.server + "*", ".conf") else: found_conf_files = search_tree(SWIFT_DIR, "%s-server*" % self.type, ".conf") number = kwargs.get("number") if number: try: conf_files = [found_conf_files[number - 1]] except IndexError: conf_files = [] else: conf_files = found_conf_files if not conf_files: # maybe there's a config file(s) out there, but I couldn't find it! if not kwargs.get("quiet"): print _("Unable to locate config %sfor %s") % (("number %s " % number if number else ""), self.server) if kwargs.get("verbose") and not kwargs.get("quiet"): if found_conf_files: print _("Found configs:") for i, conf_file in enumerate(found_conf_files): print " %d) %s" % (i + 1, conf_file) return conf_files
def test_search_tree(self): # file match & ext miss with temptree(['asdf.conf', 'blarg.conf', 'asdf.cfg']) as t: asdf = utils.search_tree(t, 'a*', '.conf') self.assertEquals(len(asdf), 1) self.assertEquals(asdf[0], os.path.join(t, 'asdf.conf')) # multi-file match & glob miss & sort with temptree(['application.bin', 'apple.bin', 'apropos.bin']) as t: app_bins = utils.search_tree(t, 'app*', 'bin') self.assertEquals(len(app_bins), 2) self.assertEquals(app_bins[0], os.path.join(t, 'apple.bin')) self.assertEquals(app_bins[1], os.path.join(t, 'application.bin')) # test file in folder & ext miss & glob miss files = ( 'sub/file1.ini', 'sub/file2.conf', 'sub.bin', 'bus.ini', 'bus/file3.ini', ) with temptree(files) as t: sub_ini = utils.search_tree(t, 'sub*', '.ini') self.assertEquals(len(sub_ini), 1) self.assertEquals(sub_ini[0], os.path.join(t, 'sub/file1.ini')) # test multi-file in folder & sub-folder & ext miss & glob miss files = ( 'folder_file.txt', 'folder/1.txt', 'folder/sub/2.txt', 'folder2/3.txt', 'Folder3/4.txt' 'folder.rc', ) with temptree(files) as t: folder_texts = utils.search_tree(t, 'folder*', '.txt') self.assertEquals(len(folder_texts), 4) f1 = os.path.join(t, 'folder_file.txt') f2 = os.path.join(t, 'folder/1.txt') f3 = os.path.join(t, 'folder/sub/2.txt') f4 = os.path.join(t, 'folder2/3.txt') for f in [f1, f2, f3, f4]: self.assert_(f in folder_texts)
def conf_files(self, **kwargs): """Get conf files for this server :param: number, if supplied will only lookup the nth server :returns: list of conf files """ if self.server in STANDALONE_SERVERS: server_search = self.server else: server_search = "%s-server" % self.type if self.conf is not None: found_conf_files = search_tree(SWIFT_DIR, server_search, self.conf + '.conf', dir_ext=self.conf + '.conf.d') else: found_conf_files = search_tree(SWIFT_DIR, server_search + '*', '.conf', dir_ext='.conf.d') number = kwargs.get('number') if number: try: conf_files = [found_conf_files[number - 1]] except IndexError: conf_files = [] else: conf_files = found_conf_files if not conf_files: # maybe there's a config file(s) out there, but I couldn't find it! if not kwargs.get('quiet'): if number: print( _('Unable to locate config number %(number)s for' ' %(server)s') % { 'number': number, 'server': self.server }) else: print(_('Unable to locate config for %s') % self.server) if kwargs.get('verbose') and not kwargs.get('quiet'): if found_conf_files: print(_('Found configs:')) for i, conf_file in enumerate(found_conf_files): print(' %d) %s' % (i + 1, conf_file)) return conf_files
def pid_files(self, **kwargs): """Get pid files for this server :param: number, if supplied will only lookup the nth server :returns: list of pid files """ if self.conf is not None: pid_files = search_tree(self.run_dir, "%s*" % self.server, exts=[self.conf + ".pid", self.conf + ".pid.d"]) else: pid_files = search_tree(self.run_dir, "%s*" % self.server) if kwargs.get("number", 0): conf_files = self.conf_files(**kwargs) # filter pid_files to match the index of numbered conf_file pid_files = [pid_file for pid_file in pid_files if self.get_conf_file_name(pid_file) in conf_files] return pid_files
def pid_files(self, **kwargs): """Get pid files for this server :param: number, if supplied will only lookup the nth server :returns: list of pid files """ if self.conf is not None: pid_files = search_tree(self.run_dir, '%s*' % self.server, exts=[self.conf + '.pid', self.conf + '.pid.d']) else: pid_files = search_tree(self.run_dir, '%s*' % self.server) if kwargs.get('number', 0): conf_files = self.conf_files(**kwargs) # filter pid_files to match the index of numbered conf_file pid_files = [pid_file for pid_file in pid_files if self.get_conf_file_name(pid_file) in conf_files] return pid_files
def conf_files(self, **kwargs): """Get conf files for this server :param: number, if supplied will only lookup the nth server :returns: list of conf files """ if self.server in STANDALONE_SERVERS: server_search = self.server else: server_search = "%s-server" % self.type if self.conf is not None: found_conf_files = search_tree(SWIFT_DIR, server_search, self.conf + '.conf', dir_ext=self.conf + '.conf.d') else: found_conf_files = search_tree(SWIFT_DIR, server_search + '*', '.conf', dir_ext='.conf.d') number = kwargs.get('number') if number: try: conf_files = [found_conf_files[number - 1]] except IndexError: conf_files = [] else: conf_files = found_conf_files if not conf_files: # maybe there's a config file(s) out there, but I couldn't find it! if not kwargs.get('quiet'): if number: print(_('Unable to locate config number %(number)s for' ' %(server)s') % {'number': number, 'server': self.server}) else: print(_('Unable to locate config for %s') % self.server) if kwargs.get('verbose') and not kwargs.get('quiet'): if found_conf_files: print(_('Found configs:')) for i, conf_file in enumerate(found_conf_files): print(' %d) %s' % (i + 1, conf_file)) return conf_files
def pid_files(self, **kwargs): """Get pid files for this server :param: number, if supplied will only lookup the nth server :returns: list of pid files """ pid_files = search_tree(RUN_DIR, "%s*" % self.server, ".pid") if kwargs.get("number", 0): conf_files = self.conf_files(**kwargs) # filter pid_files to match the index of numbered conf_file pid_files = [pid_file for pid_file in pid_files if self.get_conf_file_name(pid_file) in conf_files] return pid_files
def pid_files(self, **kwargs): """Get pid files for this server :param: number, if supplied will only lookup the nth server :returns: list of pid files """ pid_files = search_tree(RUN_DIR, '%s*' % self.server, '.pid') if kwargs.get('number', 0): conf_files = self.conf_files(**kwargs) # filter pid_files to match the index of numbered conf_file pid_files = [pid_file for pid_file in pid_files if self.get_conf_file_name(pid_file) in conf_files] return pid_files
def pid_files(self, **kwargs): """ 获得当前服务器的进程文件Get pid files for this server :param: number, if supplied will only lookup the nth server :returns: list of pid files """ pid_files = search_tree(self.run_dir, '%s*' % self.server) if kwargs.get('number', 0): conf_files = self.conf_files(**kwargs) # filter pid_files to match the index of numbered conf_file pid_files = [pid_file for pid_file in pid_files if self.get_conf_file_name(pid_file) in conf_files] return pid_files
def get_mnt_point(vol_name, conf_dir=SWIFT_DIR, conf_file="object-server*"): """Read the object-server's configuration file and return the device value""" mnt_dir = '' conf_files = search_tree(conf_dir, conf_file, '.conf') if not conf_files: raise Exception("Config file not found") _conf = ConfigParser() if _conf.read(conf_files[0]): try: mnt_dir = _conf.get('DEFAULT', 'devices', '') except (NoSectionError, NoOptionError): raise return os.path.join(mnt_dir, vol_name)
def get_mnt_point(vol_name, conf_dir=SWIFT_DIR, conf_file="object-server*"): """ Read the object-server's configuration file and return the device value. :param vol_name: target GlusterFS volume name :param conf_dir: Swift configuration directory root :param conf_file: configuration file name for which to search :returns full path to given target volume name :raises GlusterfsException if unable to fetch mount point root from configuration files """ mnt_dir = '' conf_files = search_tree(conf_dir, conf_file, '.conf') if not conf_files: raise GlusterfsException("Config file, %s, in directory, %s, " "not found" % (conf_file, conf_dir)) _conf = ConfigParser() if _conf.read(conf_files[0]): mnt_dir = _conf.get('DEFAULT', 'devices', '') return os.path.join(mnt_dir, vol_name) else: raise GlusterfsException("Config file, %s, is empty" % conf_files[0])
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. import os import errno from ConfigParser import ConfigParser from swift.common.ring import ring from swift.common.utils import search_tree from gluster.swift.common.Glusterfs import SWIFT_DIR reseller_prefix = "AUTH_" conf_files = search_tree(SWIFT_DIR, "proxy-server*", 'conf') if conf_files: conf_file = conf_files[0] _conf = ConfigParser() if conf_files and _conf.read(conf_file): if _conf.defaults().get("reseller_prefix", None): reseller_prefix = _conf.defaults().get("reseller_prefix") else: for key, value in _conf._sections.items(): if value.get("reseller_prefix", None): reseller_prefix = value["reseller_prefix"] break if not reseller_prefix.endswith('_'): reseller_prefix = reseller_prefix + '_'
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. from ConfigParser import ConfigParser from swift.common.ring import ring from swift.common.utils import search_tree from gluster.swift.common.Glusterfs import SWIFT_DIR reseller_prefix = "AUTH_" conf_files = search_tree(SWIFT_DIR, "proxy-server*", "conf") if conf_files: conf_file = conf_files[0] _conf = ConfigParser() if conf_files and _conf.read(conf_file): if _conf.defaults().get("reseller_prefix", None): reseller_prefix = _conf.defaults().get("reseller_prefix") else: for key, value in _conf._sections.items(): if value.get("reseller_prefix", None): reseller_prefix = value["reseller_prefix"] break if not reseller_prefix.endswith("_"): reseller_prefix = reseller_prefix + "_"