Esempio n. 1
0
 def import_pool(self, pool):
     self.pools.pop(pool.guid)
     self.updated.emit()
     try:
         logging.info('Importing pool ' + str(pool.name) + ' (' +
                      str(pool.guid) + ')')
         ZFS().import_pool(pool, pool.name, {})
     except ZFSException as e:
         logging.error('Import failed: ' + str(e))
         self.import_error.emit(pool, str(e).capitalize())
         return
     self.import_success.emit(pool)
Esempio n. 2
0
 def _do_scan(self):
     return sorted(list(ZFS().pools), key=lambda pool: str(pool.name))
Esempio n. 3
0
 def _do_scan(self):
     imports = list(ZFS().find_import(search_paths=disk_paths))
     return sorted(imports, key=lambda pool: str(pool.name))
Esempio n. 4
0
from libzfs import (ZFS, ZFSDataset, ZFSSnapshot, ZFSException, Error as
                    ZFSErrorCode)
from tempfile import _RandomNameSequence

_zfs = ZFS()

for name in ('get_object', 'get_dataset', 'get_dataset_by_path'):
    locals()[name] = getattr(_zfs, name)


def create_snapshot(dataset, name):
    fullname = '{}@{}'.format(dataset.name, name)
    dataset.snapshot(fullname)
    return get_object(fullname)


def create_clone(snapshot, name, **opts):
    if isinstance(snapshot, TemporarySnapshot):
        snapshot = snapshot.snap
    snapshot.clone(name, opts)
    return get_object(name)


class TemporarySnapshot:
    def __init__(self, dataset, name):
        self.snap = create_snapshot(dataset, name)

    def __del__(self):
        if hasattr(self, 'snap'):
            self.snap.delete(recursive_children=True)