コード例 #1
0
 def _path_info(self, path):
     import zfs as module_zfs
     import zone as module_zone
     ret_dict = {
         'path': path,
         'fs_inst': None,
         'fs_dir': None,
         'relpath': None
     }
     df_entry = DiskFree.of(path)
     ret_dict['fs_name'] = df_entry['fs_name']
     #
     # fs_dir
     fs_inst = module_zfs.get_zfs_by_name(ret_dict['fs_name'])
     if fs_inst:
         ret_dict['fs_inst'] = fs_inst
     else:
         pass
         #TODO
     ret_dict['fs_dir'] = df_entry['fs_mountpoint']
     #
     # relpath : relative path from fs_dir
     ret_dict['relpath'] = relpath(path, ret_dict['fs_dir'])
     #
     # lmap_zone_reldir
     ret_dict['lmap_zone_reldir'] = []
     if isinstance(fs_inst, module_zfs.Zfs):
         if not fs_inst.get_mountpoint_from_lmount():
             return ret_dict
         print '-------------------------------------------'
         print '-------------------------------------------'
         print path.upper(), ret_dict['fs_inst']
         for zone in module_zone.lzone:
             print ""
             lfs = zone.lfs
             print '---zone:', zone.zonename
             print '---lfs:', lfs
             pretender_zone_fs_len = (None, None, 0)
             fs_list = [
                 x for x in os.path.abspath(
                     fs_inst.get_mountpoint_from_lmount()).split(os.sep)
                 if x
             ]
             zonepath_list = [
                 x for x in os.path.abspath(
                     os.path.join(zone.zonepath, 'root')).split(os.sep) if x
             ]
             common_path = os.path.commonprefix([zonepath_list, fs_list])
             print '  +-----'
             print '  |', fs_inst.get_mountpoint_from_lmount(
             ), ' || ', zone.zonepath, ' || ', os.sep.join(common_path)
             print '  +-----'
             if len(common_path) > pretender_zone_fs_len[2]:
                 rel_dir = ''
                 print '+-+-----'
                 print '|0|', fs_inst.name, ' || ', os.sep.join(common_path)
                 print '+-+-----'
                 pretender_zone_fs_len = (zone, fs_inst.dir,
                                          len(common_path), 1)
             print '  +-----'
             for fs in lfs:
                 print '  |', fs
                 print '  +-----'
                 print '  |-', '\n  |- '.join([fs.special for fs in lfs])
                 print '+-+-----'
                 print '|1|', fs_inst.name, ' || ', fs.special
                 print '+-+-----'
                 if 'zfs' == fs.type:
                     if fs.special == fs_inst.name:
                         print '+-+-----'
                         print '|2|', fs
                         print '+-+-----'
                         ret_dict['lmap_zone_reldir'].append(
                             (zone, fs_inst.dir, 2))
                         continue
                 elif 'lofs' == fs.type:
                     lofs_list = [
                         x
                         for x in os.path.abspath(fs.special).split(os.sep)
                         if x
                     ]
                     common_path = os.path.commonprefix(
                         [lofs_list, fs_list])
                     if len(common_path) > pretender_zone_fs_len[2]:
                         print '+-+-----'
                         print '|3|', fs
                         print '+-+-----'
                         pretender_zone_fs_len = (zone, fs.dir,
                                                  len(common_path), 3)
                 else:
                     raise Exception('this fs is not supported')
             if 0 < pretender_zone_fs_len[1]:
                 ret_dict['lmap_zone_reldir'].append(
                     tuple(pretender_zone_fs_len[0:3]))
         print ""
         print ret_dict['lmap_zone_reldir']
     else:
         raise Exception('path info for a non zfs FS is not supported')
     return ret_dict
コード例 #2
0
ファイル: mix.py プロジェクト: briner/libcbr
 def _path_info(self, path):
     import zfs as module_zfs
     import zone as module_zone
     ret_dict={'path':path
              ,'fs_inst':None
              ,'fs_dir':None
              ,'relpath':None}
     df_entry=DiskFree.of(path)
     ret_dict['fs_name']=df_entry['fs_name']
     #
     # fs_dir
     fs_inst=module_zfs.get_zfs_by_name(ret_dict['fs_name'])
     if fs_inst:
         ret_dict['fs_inst']=fs_inst
     else:
         pass
         #TODO
     ret_dict['fs_dir']=df_entry['fs_mountpoint']
     #
     # relpath : relative path from fs_dir
     ret_dict['relpath']=relpath(path, ret_dict['fs_dir'])
     #
     # lmap_zone_reldir
     ret_dict['lmap_zone_reldir']=[]
     if isinstance(fs_inst, module_zfs.Zfs):
         if not fs_inst.get_mountpoint_from_lmount():
             return ret_dict
         print '-------------------------------------------'
         print '-------------------------------------------'
         print path.upper(), ret_dict['fs_inst']
         for zone in module_zone.lzone:
             print ""
             lfs=zone.lfs
             print '---zone:',  zone.zonename
             print '---lfs:', lfs
             pretender_zone_fs_len=(None,None,0)
             fs_list = [x for x in os.path.abspath(fs_inst.get_mountpoint_from_lmount()).split(os.sep) if x]
             zonepath_list = [x for x in os.path.abspath(os.path.join(zone.zonepath,'root')).split(os.sep) if x]
             common_path= os.path.commonprefix([zonepath_list, fs_list])
             print '  +-----'
             print '  |',fs_inst.get_mountpoint_from_lmount(),' || ',zone.zonepath,' || ',os.sep.join(common_path)
             print '  +-----'
             if len(common_path) > pretender_zone_fs_len[2]:
                 rel_dir=''
                 print '+-+-----'
                 print '|0|', fs_inst.name,' || ',os.sep.join(common_path)
                 print '+-+-----'
                 pretender_zone_fs_len=(zone, fs_inst.dir , len(common_path), 1)
             print '  +-----'
             for fs in lfs:
                 print '  |', fs
                 print '  +-----'
                 print '  |-', '\n  |- '.join( [fs.special for fs in lfs] )
                 print '+-+-----'
                 print '|1|', fs_inst.name,' || ',fs.special
                 print '+-+-----'
                 if 'zfs'==fs.type:
                     if fs.special == fs_inst.name:
                         print '+-+-----'
                         print '|2|', fs
                         print '+-+-----'
                         ret_dict['lmap_zone_reldir'].append( (zone, fs_inst.dir, 2) )
                         continue     
                 elif 'lofs'==fs.type:
                     lofs_list = [x for x in os.path.abspath(fs.special).split(os.sep) if x]
                     common_path= os.path.commonprefix([lofs_list, fs_list])
                     if len(common_path) > pretender_zone_fs_len[2]:
                         print '+-+-----'
                         print '|3|', fs
                         print '+-+-----'
                         pretender_zone_fs_len=(zone, fs.dir, len(common_path), 3)
                 else:
                     raise Exception('this fs is not supported')
             if 0 < pretender_zone_fs_len[1]:
                 ret_dict['lmap_zone_reldir'].append( tuple(pretender_zone_fs_len[0:3]) )
         print ""
         print ret_dict['lmap_zone_reldir']
     else:
         raise Exception('path info for a non zfs FS is not supported')
     return ret_dict
コード例 #3
0
 def get_info_from_path_of_globalzone(self, path):
     ''' scan zonecfg -z <zone> export and for each FS it gives
     reldir_zonepath : relative directory of the FS from the zonepath (eg. ./root/usr/local)
     is_visible : root mountpoint visible within the zone
     fs_inst : zfs instance or 'FSname' for other
     reldir_fs: path where the FS is mounted inside the zone (eg. /usr/local)
     zone: the zone instance
     '''
     lret = []
     if os.path.isfile(path):
         filename = os.path.basename(path)
     else:
         filename = ''
     zfs_holding_path = module_zfs.get_zfs_4_path(path)
     # check that this zfs is used by the zone
     zfs_holding_zonepath = module_zfs.get_zfs_4_path(self.zonepath)
     if zfs_holding_zonepath == zfs_holding_path:
         reldir_fs = mod_path.lstrip_slash(
             os.path.normpath(
                 path.replace(
                     zfs_holding_zonepath.get_mountpoint_from_lmount(),
                     '')))
         reldir_zonepath = mod_path.lstrip_slash(
             os.path.normpath(path.replace(self.zonepath, '')))
         ret = {
             'reldir_zonepath': reldir_zonepath,
             'is_visible': bool(-1 != path.find(self.rootpath)),
             'fs_inst': zfs_holding_zonepath,
             'reldir_fs': reldir_fs,
             'zone': self
         }
         lret.append(ret)
     for fs in self.lfs:
         if fs.type == 'zfs':
             zfs = module_zfs.get_zfs_by_name(fs.special)
             if zfs == zfs_holding_path:
                 reldir_fs = os.path.join(
                     mod_path.lstrip_slash(
                         os.path.normpath(
                             path.replace(zfs.get_mountpoint_from_lmount(),
                                          ''))), filename)
                 reldir_zonepath = os.path.join(
                     'root', mod_path.lstrip_slash(fs.dir), reldir_fs)
                 reldir_fs = reldir_fs.replace('/./', '/')
                 reldir_zonepath = reldir_zonepath.replace('/./', '/')
                 if reldir_fs == '.':
                     reldir_fs = ''
                 if reldir_zonepath == '.':
                     reldir_zonepath = ''
                 ret = {
                     'reldir_zonepath': reldir_zonepath,
                     'is_visible': True,
                     'fs_inst': zfs,
                     'reldir_fs': reldir_fs,
                     'zone': self
                 }
                 lret.append(ret)
         else:  # this is a lofs mount
             if fs.type == 'lofs':
                 globalpath = os.path.join(self.rootpath,
                                           mod_path.lstrip_slash(fs.dir))
                 if 0 == path.find(globalpath):
                     reldir_fs = os.path.join(
                         mod_path.lstrip_slash(
                             os.path.normpath(path.replace(globalpath,
                                                           ''))), filename)
                     reldir_zonepath = os.path.normpath(
                         os.path.join('root',
                                      mod_path.lstrip_slash(fs.special),
                                      reldir_fs))
                     #
                     reldir_fs = reldir_fs.replace('/./', '/')
                     reldir_zonepath = reldir_zonepath.replace('/./', '/')
                     if (reldir_fs == '.') or (reldir_fs == './'):
                         reldir_fs = ''
                     if (reldir_zonepath == '.') or (reldir_zonepath
                                                     == './'):
                         reldir_zonepath = ''
                     ret = {
                         'reldir_zonepath': reldir_zonepath,
                         'is_visible': True,
                         'fs_inst': fs.special,
                         'reldir_fs': reldir_fs,
                         'zone': self
                     }
                     lret.append(ret)
             else:
                 raise Exception(
                     "not zfs neither lofs! then what is it ? Exception raised in zone.get_info_from_path_of_globalzone"
                 )
     return lret
コード例 #4
0
ファイル: zone.py プロジェクト: briner/libcbr
 def get_info_from_path_of_globalzone(self,path):
     ''' scan zonecfg -z <zone> export and for each FS it gives
     reldir_zonepath : relative directory of the FS from the zonepath (eg. ./root/usr/local)
     is_visible : root mountpoint visible within the zone
     fs_inst : zfs instance or 'FSname' for other
     reldir_fs: path where the FS is mounted inside the zone (eg. /usr/local)
     zone: the zone instance
     '''
     lret=[]
     if os.path.isfile(path):
         filename=os.path.basename(path)
     else:
         filename=''
     zfs_holding_path=module_zfs.get_zfs_4_path(path)
     # check that this zfs is used by the zone
     zfs_holding_zonepath = module_zfs.get_zfs_4_path(self.zonepath)
     if zfs_holding_zonepath == zfs_holding_path:    
         reldir_fs=mod_path.lstrip_slash( os.path.normpath( path.replace(zfs_holding_zonepath.get_mountpoint_from_lmount(),'') ) )
         reldir_zonepath=mod_path.lstrip_slash( os.path.normpath( path.replace(self.zonepath,'') ) )
         ret={'reldir_zonepath':reldir_zonepath
             ,'is_visible': bool(-1 != path.find(self.rootpath) )
             ,'fs_inst': zfs_holding_zonepath
             ,'reldir_fs': reldir_fs
             ,'zone':self}
         lret.append(ret)
     for fs in self.lfs:
         if fs.type=='zfs':
             zfs=module_zfs.get_zfs_by_name(fs.special)
             if  zfs==zfs_holding_path:
                 reldir_fs=os.path.join(mod_path.lstrip_slash(  os.path.normpath(path.replace(zfs.get_mountpoint_from_lmount(),'') ) ), filename)
                 reldir_zonepath=os.path.join('root',mod_path.lstrip_slash(fs.dir), reldir_fs)
                 reldir_fs=reldir_fs.replace('/./','/')
                 reldir_zonepath=reldir_zonepath.replace('/./','/')
                 if reldir_fs == '.':
                     reldir_fs=''
                 if reldir_zonepath == '.':
                     reldir_zonepath=''
                 ret={'reldir_zonepath':reldir_zonepath
                      ,'is_visible': True
                      ,'fs_inst': zfs
                      ,'reldir_fs': reldir_fs
                      ,'zone':self}
                 lret.append(ret)
         else: # this is a lofs mount
             if fs.type=='lofs':
                 globalpath=os.path.join(self.rootpath, mod_path.lstrip_slash(fs.dir))
                 if 0 == path.find(globalpath):
                     reldir_fs=os.path.join(mod_path.lstrip_slash(  os.path.normpath(path.replace(globalpath,'') ) ), filename)
                     reldir_zonepath=os.path.normpath(os.path.join('root',mod_path.lstrip_slash(fs.special), reldir_fs))
                     #
                     reldir_fs=reldir_fs.replace('/./','/')
                     reldir_zonepath=reldir_zonepath.replace('/./','/')
                     if ( reldir_fs == '.' )or( reldir_fs == './' ):
                         reldir_fs=''
                     if ( reldir_zonepath == '.' )or( reldir_zonepath == './' ):
                         reldir_zonepath=''
                     ret={'reldir_zonepath': reldir_zonepath
                         ,'is_visible': True
                         ,'fs_inst': fs.special
                         ,'reldir_fs': reldir_fs
                         ,'zone':self}
                     lret.append(ret)
             else:
                 raise Exception("not zfs neither lofs! then what is it ? Exception raised in zone.get_info_from_path_of_globalzone")
     return lret