您的位置:首页 > 编程语言

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: