def start(self): if "node.x.exportfs" not in capabilities: raise ex.Error("exportfs is not installed") try: up = self.is_up() except ex.Error 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.Error
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))
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 = [Env.syspaths.losetup, '-d', loop] ret, out, err = self.vcall(cmd) clear_cache("losetup.json") if ret != 0: raise ex.Error if os.path.exists(self.loopfile): self.auto_unprovision()
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.Error clear_cache("virsh.dom_state.%s@%s" % (self.name, Env.nodename))
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))
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.Error self.virsh_define() cmd = ['virsh', 'start', self.name] (ret, buff, err) = self.vcall(cmd) if ret != 0: raise ex.Error clear_cache("virsh.dom_state.%s@%s" % (self.name, Env.nodename))
def stop(self): if "node.x.exportfs" not in capabilities: raise ex.Error("exportfs is not installed") try: up = self.is_up() except ex.Error 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.Error
def start(self): if self.is_up(): self.log.info("%s is already up" % self.label) return if not os.path.exists(self.loopfile): self.auto_provision() lockfile = os.path.join(Env.paths.pathlock, "disk.loop") try: with cmlock(timeout=30, delay=1, lockfile=lockfile): cmd = [Env.syspaths.losetup, '-f', self.loopfile] ret, out, err = self.vcall(cmd) clear_cache("losetup.json") except Exception as exc: raise ex.Error(str(exc)) if ret != 0: raise ex.Error self.loop = utilities.devices.linux.file_to_loop(self.loopfile) if len(self.loop) == 0: raise ex.Error("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 clear_cache(self, sig): """ Wraps the rcUtilities clear_cache function, setting the resource as object keyword argument. """ clear_cache(sig, o=self)
def is_up_clear_cache(self): clear_cache("virsh.dom_state.%s@%s" % (self.name, Env.nodename))