def get_cmd(self, action, script_arg=None, validate=True): key = action + "_seq" val = getattr(self, key) if val in (None, False): raise ex.AbortAction() try: int(val) cmd = [self.script, script_arg if script_arg else action] except (TypeError, ValueError): try: val = convert_boolean(val) if val is False: raise ex.AbortAction() cmd = [self.script, script_arg if script_arg else action] except ex.AbortAction: raise except: if six.PY2: cmd = map(lambda s: s.decode('utf8'), shlex.split(val.encode('utf8'))) else: cmd = shlex.split(val) if "|" in cmd or "||" in cmd or "&&" in cmd or any([True for w in cmd if w.endswith(";")]): val, vol = self.replace_volname(val, strict=False, errors="ignore") return val cmd[0], vol = self.replace_volname(cmd[0], strict=False, errors="ignore") if validate: cmd = self.validate_on_action(cmd) return cmd
def validate_cluster_global_expect(self, global_expect): if global_expect is None: return if global_expect == "thawed": if shared.DAEMON_STATUS.get("monitor", {}).get("frozen") == "thawed": raise ex.AbortAction("cluster is already thawed") elif global_expect == "frozen": if shared.DAEMON_STATUS.get("monitor", {}).get("frozen") == "frozen": raise ex.AbortAction("cluster is already frozen") else: raise ex.Error("invalid global_expect value: %s" % global_expect)
def _configure(self): if self.name not in shared.NODE.cd: # this thread will be stopped. don't reconfigure to avoid logging errors return self.get_hb_nodes() self.peer_config = {} self.timeout = shared.NODE.oget(self.name, "timeout") self.interval = shared.NODE.oget(self.name, "interval") try: self.relay = shared.NODE.oget(self.name, "relay") except Exception: raise ex.AbortAction("no %s.relay is not set in node.conf" % self.name) try: self.secret = shared.NODE.oget(self.name, "secret") except Exception: raise ex.AbortAction("no %s.secret is not set in node.conf" % self.name)
def _configure(self): if self.name not in shared.NODE.cd: # this thread will be stopped. don't reconfigure to avoid logging errors return self.get_hb_nodes() self.peer_config = {} if not hasattr(self, "meta_slot_buff"): self.meta_slot_buff = mmap.mmap(-1, 2 * mmap.PAGESIZE) if not hasattr(self, "slot_buff"): self.slot_buff = mmap.mmap(-1, self.SLOTSIZE) self.timeout = shared.NODE.oget(self.name, "timeout") self.interval = shared.NODE.oget(self.name, "interval") try: new_dev = shared.NODE.oget(self.name, "dev") except ex.RequiredOptNotFound: raise ex.AbortAction("no %s.dev is not set in node.conf" % self.name) if not os.path.exists(new_dev): raise ex.AbortAction("%s does not exist" % new_dev) new_dev = os.path.realpath(new_dev) new_flags = os.O_RDWR statinfo = os.stat(new_dev) if Env.sysname == "Linux": if stat.S_ISBLK(statinfo.st_mode): self.log.info("using directio") new_flags |= os.O_DIRECT | os.O_SYNC | os.O_DSYNC # (Darwin, SunOS) pylint: disable=no-member else: raise ex.AbortAction("%s must be a block device" % new_dev) else: if not stat.S_ISCHR(statinfo.st_mode): raise ex.AbortAction("%s must be a char device" % new_dev) if new_dev != self.dev: self.dev = new_dev self.flags = new_flags self.peer_config = {} self.log.info("set dev=%s", self.dev) with self.hb_fo() as fo: self.load_peer_config(fo=fo)
def write_slot(self, slot, data, fo=None): if len(data) > self.SLOTSIZE: self.log.error("attempt to write too long data in slot %d", slot) raise ex.AbortAction() self.slot_buff.seek(0) self.slot_buff.write(data) offset = self.slot_offset(slot) fo.seek(offset, os.SEEK_SET) fo.write(self.slot_buff) fo.flush()
def create_container_origin(self): lockfile = os.path.join(self.var_d, 'create_zone2clone-' + self.container_origin) try: with utilities.lock.cmlock(timeout=1200, delay=4, lockfile=lockfile): container = self.origin_factory() container.install_origin() except utilities.lock.LOCK_EXCEPTIONS as exc: raise ex.AbortAction(str(exc))
def hb_fo(self): try: fd = os.open(self.dev, self.flags) fo = os.fdopen(fd, 'rb+') except OSError as exc: if exc.errno == errno.EINVAL: raise ex.AbortAction("%s directio is not supported" % self.dev) else: raise ex.AbortAction("error opening %s: %s" % (self.dev, str(exc))) except Exception as exc: raise ex.AbortAction("error opening %s: %s" % (self.dev, str(exc))) try: yield fo except Exception as exc: self.log.error("%s: %s", self.dev, exc) finally: # closing fo also closes fd try: os.fsync(fd) except OSError as exc: self.duplog("error", "%(exc)s", exc=str(exc), nodename="") fo.close()