def start(self): try: up = self.is_up() except ex.excError as e: self.log.error("skip start because the share is in unknown state") return if up and len(self.issues) == 0: self.log.info("%s is already up" % self.path) return self.can_rollback = True for client, opts in self.opts.items(): if client in self.issues_none: continue if client in self.issues_wrong_opts: cmd = ['exportfs', '-u', ':'.join((client, self.path))] ret, out, err = self.vcall(cmd) cmd = [ 'exportfs', '-o', ','.join(opts), ':'.join((client, self.path)) ] ret, out, err = self.vcall(cmd) clear_cache("exportfs.v") clear_cache("showmount.e") if ret != 0: raise ex.excError
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 = rcZfs.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.excError(str(e))
def stop(self): if not self.is_up(): self.log.info("%s is already down" % self.label) return 0 for loop in self.loop: cmd = [rcEnv.syspaths.losetup, '-d', loop] ret, out, err = self.vcall(cmd) clear_cache("losetup.json") if ret != 0: raise ex.excError
def do_start(self): if self.is_up(): self.log.info("%s is already up" % self.name) return 0 self.zgenhostid() ret = self.import_pool() if ret != 0: raise ex.excError("failed to import pool") self.can_rollback = True self.set_multihost() clear_cache("zpool.status." + self.name)
def do_stop(self): if not self.is_up(): self.log.info("%s is already down" % self.name) return 0 cmd = ["zpool", "export", self.name] ret, out, err = self.vcall(cmd, err_to_warn=True) if ret != 0: cmd = ["zpool", "export", "-f", self.name] ret, out, err = self.vcall(cmd) clear_cache("zpool.status." + self.name) if ret != 0: raise ex.excError
def container_stop(self): state = self.dom_state() if state == "running": cmd = ['virsh', 'shutdown', self.name] elif state in ("blocked", "paused", "crashed"): self.container_forcestop() else: self.log.info("skip stop, container state=%s", state) return ret, buff, err = self.vcall(cmd) if ret != 0: raise ex.excError clear_cache("virsh.dom_state.%s@%s" % (self.name, rcEnv.nodename))
def create_snap(self, dataset): ds = rcZfs.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.excError(str(e))
def container_start(self): if self.svc.create_pg and which("machinectl") is None and self.capable( "partitions"): self.set_partition() else: self.unset_partition() if not os.path.exists(self.cf): self.log.error("%s not found" % self.cf) raise ex.excError self.virsh_define() cmd = ['virsh', 'start', self.name] (ret, buff, err) = self.vcall(cmd) if ret != 0: raise ex.excError clear_cache("virsh.dom_state.%s@%s" % (self.name, rcEnv.nodename))
def stop(self): try: up = self.is_up() except ex.excError as e: self.log.error( "continue with stop even if the share is in unknown state") if not up: self.log.info("%s is already down" % self.path) return 0 for client in self.opts: cmd = ['exportfs', '-u', ':'.join((client, self.path))] ret, out, err = self.vcall(cmd) clear_cache("exportfs.v") clear_cache("showmount.e") if ret != 0: raise ex.excError
def start(self): lockfile = os.path.join(rcEnv.paths.pathlock, "disk.loop") if self.is_up(): self.log.info("%s is already up" % self.label) return try: with cmlock(timeout=30, delay=1, lockfile=lockfile): cmd = [rcEnv.syspaths.losetup, '-f', self.loopFile] ret, out, err = self.vcall(cmd) clear_cache("losetup.json") except Exception as exc: raise ex.excError(str(exc)) if ret != 0: raise ex.excError self.loop = file_to_loop(self.loopFile) if len(self.loop) == 0: raise ex.excError("loop device did not appear or disappeared") time.sleep(2) self.log.info("%s now loops to %s" % (', '.join(self.loop), self.loopFile)) self.can_rollback = True
def is_up_clear_cache(self): clear_cache("virsh.dom_state.%s@%s" % (self.name, rcEnv.nodename))
def clear_cache(self, sig): """ Wraps the rcUtilities clear_cache function, setting the resource as object keyword argument. """ clear_cache(sig, o=self)
def clear_caches(self): clear_cache("showvv", o=self)
def clear_showrcopy_cache(self): clear_cache("showrcopy_groups", o=self)