def run(self, dataset): mountpoint = self.dispatcher.call_sync('volume.get_dataset_path', dataset) # Estimate number of files statfs = bsd.statfs(mountpoint) total_files = statfs.files - statfs.free_files done_files = 0 for root, dirs, files in os.walk(mountpoint, topdown=True): dirs[:] = [dir for dir in dirs if not os.path.ismount(os.path.join(root, dir))] for d in dirs: path = os.path.join(root, d) collect(self.datastore, path) done_files += 1 self.set_progress(done_files / total_files * 100, 'Processing directory {0}'.format(path)) for f in files: path = os.path.join(root, f) collect(self.datastore, path) done_files += 1 self.join_subtasks(self.run_subtask('volume.snapshot.create', { 'dataset': dataset, 'name': 'org.freenas.indexer:ref', 'hidden': True }))
def run(self, dataset): mountpoint = self.dispatcher.call_sync('volume.get_dataset_path', dataset) # Estimate number of files statfs = bsd.statfs(mountpoint) total_files = statfs.files - statfs.free_files done_files = 0 for root, dirs, files in os.walk(mountpoint, topdown=True): dirs[:] = [ dir for dir in dirs if not os.path.ismount(os.path.join(root, dir)) ] for d in dirs: path = os.path.join(root, d) collect(self.datastore, path) done_files += 1 self.set_progress(done_files / total_files * 100, 'Processing directory {0}'.format(path)) for f in files: path = os.path.join(root, f) collect(self.datastore, path) done_files += 1 self.run_subtask_sync('volume.snapshot.create', { 'dataset': dataset, 'name': 'org.freenas.indexer:ref', 'hidden': True })
def mount(name, properties): path = os.path.join('/nfs', name) if not os.path.isdir(path): os.makedirs(path) try: stat = bsd.statfs(path) if stat.fstype == 'nfs': umount(name) except: pass # XXX: Couldn't figure out how to do that with py-bsd's nmount system('/sbin/mount_nfs', '-osoft,intr,retrans=1,timeout=100', '{address}:{path}'.format(**properties), path)
def statfs(self, path): """ Return stats from the filesystem of a given path. Raises: CallError(ENOENT) - Path not found """ try: statfs = bsd.statfs(path) except FileNotFoundError: raise CallError('Path not found.', errno.ENOENT) return { **statfs.__getstate__(), 'total_bytes': statfs.total_blocks * statfs.blocksize, 'free_bytes': statfs.free_blocks * statfs.blocksize, 'avail_bytes': statfs.avail_blocks * statfs.blocksize, }
def convert_bootenv(ds): boot_pool = dispatcher.call_sync('zfs.pool.get_boot_pool') root_mount = bsd.statfs('/') path = ds['id'].split('/') if len(path) != 3: return if path[:2] != [boot_pool['id'], 'ROOT']: return return { 'active': root_mount.source == ds['id'], 'on_reboot': boot_pool['properties.bootfs.value'] == ds['id'], 'id': ds.get('properties.beadm:nickname.value', path[-1]), 'space': int(ds['properties.used.rawvalue']), 'realname': path[-1], 'mountpoint': ds.get('mountpoint'), 'created': datetime.fromtimestamp(int(ds['properties.creation.rawvalue'])) }
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # import os import libzfs import bsd zfs = libzfs.ZFS() root_mount = bsd.statfs('/') boot_pool, be_prefix = root_mount.source.split('/')[:2] root_ds = zfs.get_dataset('/'.join([boot_pool, be_prefix])) class BootEnvironment(object): def __init__(self, name): self.ds = zfs.get_dataset(root_ds.name + '/' + name) def __str__(self): return "<be.BootEnvironment name '{0}'>".format(self.name) def __repr__(self): return str(self) def __getstate__(self):
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # import os import libzfs import bsd zfs = libzfs.ZFS() root_mount = bsd.statfs('/') boot_pool, be_prefix = root_mount.source.split('/')[:2] root_ds = zfs.get_dataset('/'.join([boot_pool, be_prefix])) class BootEnvironment(object): def __init__(self, name): self.ds = zfs.get_dataset(root_ds.name + '/' + name) def __str__(self): return "<be.BootEnvironment name '{0}'>".format(self.name) def __repr__(self): return str(self) def __getstate__(self):