def lock(self): """ Acquire the startip lock, protecting against allocation of the same ipdev stacked device to multiple resources or multiple services. """ timeout = convert_duration(self.svc.options.waitlock) if timeout is None or timeout < 0: timeout = 120 delay = 1 lockfd = None action = "startip" lockfile = os.path.join(Env.paths.pathlock, action) details = "(timeout %d, delay %d, action %s, lockfile %s)" % \ (timeout, delay, action, lockfile) self.log.debug("acquire startip lock %s", details) try: lockfd = utilities.lock.lock(timeout=timeout, delay=delay, lockfile=lockfile, intent="startip") except utilities.lock.LockTimeout as exc: raise ex.Error("timed out waiting for lock %s: %s" % (details, str(exc))) except utilities.lock.LockNoLockFile: raise ex.Error("lock_nowait: set the 'lockfile' param %s" % details) except utilities.lock.LockCreateError: raise ex.Error("can not create lock file %s" % details) except utilities.lock.LockAcquire as exc: raise ex.Error("another action is currently running %s: %s" % (details, str(exc))) except ex.Signal: raise ex.Error("interrupted by signal %s" % details) except Exception as exc: self.save_exc() raise ex.Error("unexpected locking error %s: %s" % (details, str(exc))) if lockfd is not None: self.lockfd = lockfd
def collector_list_unavailability_ack(self): if self.path is None: return opts = {} opts['svcname'] = self.path if self.options.begin is not None: opts['begin'] = self.options.begin if self.options.end is not None: opts['end'] = self.options.end if self.options.author is not None: opts['author'] = self.options.author if self.options.comment is not None: opts['comment'] = self.options.comment if self.options.duration is not None: opts['duration'] = convert_duration(self.options.duration, _to="m") if self.options.account: opts['account'] = "1" else: opts['account'] = "0" d = self.collector.call('collector_list_unavailability_ack', opts) if d is None: raise ex.Error("xmlrpc unknown failure") if d['ret'] != 0: raise ex.Error(d['msg']) return d['data']
def collector_list_actions(self): opts = {} if self.path is not None: opts['svcname'] = self.path if self.options.begin is not None: opts['begin'] = self.options.begin if self.options.end is not None: opts['end'] = self.options.end if self.options.duration is not None: opts['duration'] = convert_duration(self.options.duration, _to="m") d = self.collector.call('collector_list_actions', opts) if d is None: raise ex.Error("xmlrpc unknown failure") if d['ret'] != 0: raise ex.Error(d['msg']) return d['data']
def _sched_parse_timerange(self, spec, section=None): """ Return the list of timerange data structure parsed from the <spec> definition string. """ min_tr_len = 1 def parse_timerange(spec): if spec == "*" or spec == "": return {"begin": "00:00", "end": "23:59"} if "-" not in spec: spec = "-".join((spec, spec)) try: begin, end = spec.split("-") except: raise SchedSyntaxError("split '%s' error" % spec) if begin.count(":") != 1 or \ end.count(":") != 1: raise SchedSyntaxError( "only one ':' allowed in timerange '%s' end" % spec) begin_m = self._time_to_minutes(begin) end_m = self._time_to_minutes(end) if begin_m == end_m: end_m += min_tr_len end = "%02d:%02d" % (end_m // 60, end_m % 60) return {"begin": begin, "end": end} if section and section.startswith("sync"): probabilistic = False else: probabilistic = True tr_list = [] for _spec in spec.split(","): if len(_spec) == 0 or _spec == "*": tr_data = { "probabilistic": probabilistic, "begin": "00:00", "end": "23:59", "interval": 1441, } tr_list.append(tr_data) continue ecount = _spec.count("@") if ecount == 0: tr_data = parse_timerange(_spec) tr_data["interval"] = self._interval_from_timerange(tr_data) if tr_data["interval"] <= min_tr_len + 1: tr_data["probabilistic"] = False else: tr_data["probabilistic"] = probabilistic tr_list.append(tr_data) continue elements = _spec.split("@") ecount = len(elements) if ecount < 2: raise SchedSyntaxError("missing @<interval> in '%s'" % _spec) if ecount > 2: raise SchedSyntaxError("only one @<interval> allowed in '%s'" % _spec) tr_data = parse_timerange(elements[0]) try: tr_data["interval"] = convert_duration(elements[1], _from="m", _to="m") except ValueError as exc: raise SchedSyntaxError( "interval '%s' is not a valid duration expression: %s" % (elements[1], exc)) tr_len = self._interval_from_timerange(tr_data) if tr_len <= min_tr_len + 1 or tr_data["interval"] < tr_len: probabilistic = False tr_data["probabilistic"] = probabilistic tr_list.append(tr_data) return tr_list