def action(self, nodename, thr=None, stream_id=None, **kwargs): thr.selector = "**" options = self.parse_options(kwargs) duration = options.duration if (options.duration is not None and options.duration < MAX_DURATION) else MAX_DURATION timeout = time.time() + duration if not options.condition: return {"status": 0, "data": {"satisfied": True, "duration": duration, "elapsed": 0}} if not thr.event_queue: thr.event_queue = queue.Queue() if not thr in thr.parent.events_clients: thr.parent.events_clients.append(thr) neg, jsonpath_expr, oper, val = self.parse_condition(options.condition) if neg ^ self.match(jsonpath_expr, oper, val, {"kind": "patch"}): return {"status": 0, "data": {"satisfied": True, "duration": duration, "elapsed": 0}} end = False while True: left = timeout - time.time() if left < 0: left = 0 try: msg = thr.event_queue.get(True, left if left < 3 else 3) except queue.Empty: msg = {"kind": "patch"} if left < 3: end = True if neg ^ self.match(jsonpath_expr, oper, val, msg): return {"status": 0, "data": {"satisfied": True, "duration": duration, "elapsed": duration-left}} if end: return {"status": 1, "data": {"satisfied": False, "duration": duration, "elapsed": duration-left}}
def action(self, nodename, thr=None, stream_id=None, **kwargs): options = self.parse_options(kwargs) thr.selector = "" ref_gen = shared.GEN if not thr.event_queue: thr.event_queue = queue.Queue() if not thr in thr.parent.events_clients: thr.parent.events_clients.append(thr) if self.match(ref_gen): return {"status": 0, "data": {"satisfied": True, "gen": ref_gen}} limit = time.time() + options.timeout while True: if self.match(ref_gen): return { "status": 0, "data": { "satisfied": True, "gen": ref_gen } } left = limit - time.time() if left <= 0: break if left > 3: left = 3 try: thr.event_queue.get(True, left) except queue.Empty: pass return {"status": 1, "data": {"satisfied": False, "gen": ref_gen}}
def action(self, nodename, thr=None, stream_id=None, **kwargs): options = self.parse_options(kwargs) thr.selector = options.selector if not thr.event_queue: thr.event_queue = queue.Queue() if options.full: data = thr.daemon_status() namespaces = thr.get_namespaces() fevent = { "nodename": Env.nodename, "ts": time.time(), "kind": "full", "data": thr.filter_daemon_status(data, namespaces=namespaces, selector=options.selector), } if thr.h2conn: _msg = fevent elif thr.encrypted: _msg = thr.encrypt(fevent) else: _msg = thr.msg_encode(fevent) thr.event_queue.put(_msg) if not thr in thr.parent.events_clients: thr.parent.events_clients.append(thr) if not stream_id in thr.events_stream_ids: thr.events_stream_ids.append(stream_id) if thr.h2conn: request_headers = HTTPHeaderMap( thr.streams[stream_id]["request"].headers) try: content_type = bdecode(request_headers.get("accept").pop()) except: content_type = "application/json" thr.streams[stream_id]["content_type"] = content_type thr.streams[stream_id]["pushers"].append({ "fn": "h2_push_action_events", }) else: thr.raw_push_action_events()
def action(self, nodename, thr=None, stream_id=None, **kwargs): thr.selector = "" ref_gen = shared.GEN if not thr.event_queue: thr.event_queue = queue.Queue() if not thr in thr.parent.events_clients: thr.parent.events_clients.append(thr) if self.match(ref_gen): return {"status": 0, "data": {"satisfied": True, "gen": ref_gen}} timeout = time.time() + 60 end = False while True: left = timeout - time.time() if left < 0: left = 0 try: thr.event_queue.get(True, left if left < 3 else 3) except queue.Empty: if left < 3: end = True if self.match(ref_gen): return { "status": 0, "data": { "satisfied": True, "gen": ref_gen } } if end: return { "status": 1, "data": { "satisfied": False, "gen": ref_gen } }
# prog = "om mon" import core.exceptions as ex import foreign.json_delta as json_delta import utilities.render.color from core.node import Node from foreign.six.moves import queue from utilities.render.cluster import format_cluster CLEAREOL = "\x1b[K" CLEAREOLNEW = "\x1b[K\n" CLEAREOS = "\x1b[J" CURSORHOME = "\x1b[H" PATCH_Q = queue.Queue() def setup_parser(node): __ver = prog + " version " + node.agent_version __usage = prog + \ " [ OPTIONS ]\n" \ "\n" \ "Flags:\n" \ " O up\n" \ " S stdby up\n" \ " X down\n" \ " s stdby down\n" \ " ! warn\n" \ " P unprovisioned\n" \ " * frozen\n" \