def _get_lfs_info(self): self._lfs_info if self._lfs_info!=None: return self._lfs_info lret=[] lret+=self.get_info_from_path_of_globalzone(self.zonepath) for fs in self.lfs: lret+=self.get_info_from_path_of_globalzone(os.path.join(self.rootpath, mod_path.lstrip_slash(fs.dir))) self._lfs_info=lret return self._lfs_info
def _get_lfs_info(self): self._lfs_info if self._lfs_info != None: return self._lfs_info lret = [] lret += self.get_info_from_path_of_globalzone(self.zonepath) for fs in self.lfs: lret += self.get_info_from_path_of_globalzone( os.path.join(self.rootpath, mod_path.lstrip_slash(fs.dir))) self._lfs_info = lret return self._lfs_info
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
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