Exemplo n.º 1
0
 def remove_snap(self, dataset):
     cursnaps = self.list_snaps()
     snaps = {}
     for sv in cursnaps:
         s = sv.replace(dataset + "@", "")
         l = s.split('.')
         if len(l) < 2:
             continue
         if l[0] != self.name or l[1] != "snap":
             continue
         try:
             ds = sv.split(".snap.")[-1]
             d = datetime.datetime.strptime(ds, "%Y-%m-%d.%H:%M:%S")
             snaps[ds] = sv
         except Exception as e:
             pass
     if len(snaps) <= self.keep:
         return
     sorted_snaps = []
     for ds in sorted(snaps.keys(), reverse=True):
         sorted_snaps.append(snaps[ds])
     for path in sorted_snaps[self.keep:]:
         try:
             ds = Dataset(path, log=self.log)
             if self.recursive:
                 options = ["-r"]
             else:
                 options = []
             ds.destroy(options=options)
             clear_cache("zfs.list.snapshots.name")
         except Exception as e:
             raise ex.Error(str(e))
Exemplo n.º 2
0
 def create_zonepath(self):
     """create zonepath dataset from clone of snapshot of self.snapof
     snapshot for self.snapof will be created
     then cloned to self.clone
     """
     zonename = self.name
     source_ds = Dataset(self.snapof)
     if source_ds.exists(type="filesystem") is False:
         raise (ex.Error("source dataset doesn't exist " + self.snapof))
     snapshot = source_ds.snapshot(zonename)
     snapshot.clone(self.clone, ['-o', 'mountpoint=' + self.kw_zonepath])
Exemplo n.º 3
0
 def create_snap(self, snap):
     snapds = Dataset(snap)
     if snapds.exists():
         self.log.error('%s should not exist' % snap)
         raise ex.Error
     if self.recursive:
         cmd = [Env.syspaths.zfs, 'snapshot', '-r', snap]
     else:
         cmd = [Env.syspaths.zfs, 'snapshot', snap]
     (ret, out, err) = self.vcall(cmd)
     if ret != 0:
         raise ex.Error
Exemplo n.º 4
0
 def create_snap(self, dataset):
     ds = Dataset(dataset, log=self.log)
     snap = ""
     if self.name:
         suffix = self.name
     else:
         suffix = ""
     suffix += ".snap.%Y-%m-%d.%H:%M:%S"
     snap += datetime.datetime.now().strftime(suffix)
     try:
         ds.snapshot(snapname=snap, recursive=self.recursive)
         clear_cache("zfs.list.snapshots.name")
     except Exception as e:
         raise ex.Error(str(e))
Exemplo n.º 5
0
 def unprovisioner(self):
     if "node.x.zfs" not in capabilities:
         self.log.error("zfs command not found")
         raise ex.Error
     dataset = Dataset(self.device, log=self.log)
     if dataset.exists():
         dataset.destroy(["-r"])
     if os.path.exists(self.mount_point) and os.path.isdir(
             self.mount_point):
         try:
             os.rmdir(self.mount_point)
             self.log.info("rmdir %s", self.mount_point)
         except OSError as exc:
             self.log.warning("failed to rmdir %s: %s", self.mount_point,
                              exc)
Exemplo n.º 6
0
 def _status_one(self, dataset):
     if not self.has_pool(dataset):
         return
     try:
         ds = Dataset(dataset, log=self.log)
     except Exception as e:
         self.status_log("%s %s" % (dataset, str(e)))
         return
     snaps = self.get_snaps(dataset)
     if len(snaps) == 0:
         self.status_log("%s has no snap" % dataset)
         return
     if len(snaps) > self.keep + 1:
         self.status_log("%s has %d too many snaps" %
                         (dataset, len(snaps) - self.keep))
     last = self.last_snap_date(snaps)
     limit = datetime.datetime.now() - datetime.timedelta(
         seconds=self.sync_max_delay)
     if last < limit:
         self.status_log("%s last snap is too old (%s)" %
                         (dataset, last.strftime("%Y-%m-%d %H:%M:%S")))
Exemplo n.º 7
0
    def provisioner(self):
        if "node.x.zfs" not in capabilities:
            self.log.error("zfs command not found")
            raise ex.Error
        dataset = Dataset(self.device, log=self.log)
        mkfs_opt = ["-p"]
        mkfs_opt += self.oget("mkfs_opt")

        if not any([True for e in mkfs_opt if e.startswith("mountpoint=")]):
            mkfs_opt += ['-o', 'mountpoint=' + self.mount_point]
        if not any([True for e in mkfs_opt if e.startswith("canmount=")]):
            mkfs_opt += ['-o', 'canmount=noauto']

        if dataset.exists() is False:
            dataset.create(mkfs_opt)

        nv_list = dict()
        size = self.oget("size")
        if not size:
            return
        if size:
            nv_list['refquota'] = "%dM" % convert_size(size, _to="m")
        dataset.verify_prop(nv_list)
Exemplo n.º 8
0
 def provisioned(self):
     dataset = Dataset(self.device, log=self.log)
     return dataset.exists()
Exemplo n.º 9
0
 def can_sync(self, target=None):
     if not Dataset(self.src).exists():
         return False
     return True