Cinder - 读取glusterfs_shares_config代码
2015-01-09 13:15
106 查看
cinder创建glusterfs volume的函数 vim /usr/lib/python2.7/site-packages/cinder/volume/drivers/glusterfs.py @utils.synchronized('glusterfs', external=False) def create_volume(self, volume): """Creates a volume.""" self._ensure_shares_mounted() volume['provider_location'] = self._find_share(volume['size']) LOG.info(_('casted to %s') % volume['provider_location']) self._do_create_volume(volume) return {'provider_location': volume['provider_location']} # 确保glusterfs_shares_config里面的volume都被mount了 def _ensure_shares_mounted(self): """Mount all configured GlusterFS shares.""" self._mounted_shares = [] self._load_shares_config(self.configuration.glusterfs_shares_config) # _load_shares_config是读取_load_shares_config的函数 for share in self.shares.keys(): try: self._ensure_share_mounted(share) self._mounted_shares.append(share) except Exception as exc: LOG.error(_('Exception during mounting %s') % (exc,)) LOG.debug('Available shares: %s' % self._mounted_shares) vim /usr/lib/python2.7/site-packages/cinder/volume/drivers/remotefs.py # _load_shares_config函数在remotefs.py这里 def _read_config_file(self, config_file): # Returns list of lines in file with open(config_file) as f: return f.readlines() def _load_shares_config(self, share_file): self.shares = {} for share in self._read_config_file(share_file): # A configuration line may be either: # host:/vol_name # or # host:/vol_name -o options=123,rw --other if not share.strip(): # Skip blank or whitespace-only lines continue if share.startswith('#'): continue share_info = share.split(' ', 1) # 这里share.split里面的1是用空格分离符最多分离一个 # results in share_info = # [ 'address:/vol', '-o options=123,rw --other' ] share_address = share_info[0].strip().decode('unicode_escape') share_opts = share_info[1].strip() if len(share_info) > 1 else None if not re.match(self.SHARE_FORMAT_REGEX, share_address): LOG.warn(_("Share %s ignored due to invalid format. Must be " "of form address:/export.") % share_address) continue self.shares[share_address] = share_opts LOG.debug("shares loaded: %s", self.shares)# 所以如果我们要让cinder挂载两个glusterfs volume,就在/etc/cinder/glusterfs_shares配置文件中写成这样格式就可以
cat /etc/cinder/glusterfs_shares gluster2:/openstack gluster2:/ssd # 下面看另外一种更安全的写法 # backup-volfile相当于是gluster001的backup cat /etc/cinder/glusterfs_shares gluster001:/ssd -o backup-volfile-servers=gluster003:gluster004:gluster005:gluster006
本文出自 “the-way-to-cloud” 博客,请务必保留此出处http://iceyao.blog.51cto.com/9426658/1601023
相关文章推荐
- asp.net 读取并修改config文件实现代码
- cinder glusterfs driver代码结构
- asp.net 读取并修改config文件实现代码
- 来段代码提提神-Java读取config.properties文件中的key=value
- C#中读取App.config配置文件代码实例
- 读取.ini文件里面的连接数据库的代码、读取App.config文件的代码
- [Config]如何利用ConfigurationSettings.AppSettings.GetValues读取配置文件中多个同Key的value
- 最简单的读取CLOB字段的代码
- OLEDB接口读取各数据类型的转换方式(代码节录)
- 生成/读取(反向更新数据库) Excel文件(示例代码下载)
- 对web.config进行新增修改删除读取操作
- Web.config中appSettings的两种读取方法
- 读取CONFIG
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- 利用代码读取XML文档
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)
- ASP.NET读取POP3邮件的操作(纯代码)
- winform项目中app.config读取修改小结!
- MapXtreme2004代码 读取TAB表中的元素