Cinder - glusterfs 읽기shares_config 코드

3151 단어 cinderGlusterFS
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/glusterfsshares 프로필에 이렇게 쓰면 돼요.
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

좋은 웹페이지 즐겨찾기