def cmd_status(args): ''' Calls crm_mon -1, passing optional extra arguments. Displays the output, paging if necessary. Raises IOError if crm_mon fails. ''' opts = { "bynode": "-n", "inactive": "-r", "ops": "-o", "timing": "-t", "failcounts": "-f", "verbose": "-V", "quiet": "-Q", "html": "--as-html", "xml": "--as-xml", "simple": "-s", "tickets": "-c", "noheaders": "-D", "detail": "-R", "brief": "-b", } extra = ' '.join(opts.get(arg, arg) for arg in args) rc, s = crm_mon(extra) if rc != 0: raise IOError("crm_mon (rc=%d): %s" % (rc, s)) utils.page_string(s) return True
def cmd_status(args): ''' Calls crm_mon -1, passing optional extra arguments. Displays the output, paging if necessary. Raises ValueError if an illegal argument is passed. Raises IOError if crm_mon fails. ''' crm_mon_opts = { "bynode": "-n", "inactive": "-r", "ops": "-o", "timing": "-t", "failcounts": "-f", } has_crm_mon() def check(arg, val): if not val: raise ValueError("Unknown argument to status: " + str(arg)) return val extra_options = ' '.join(check(arg, crm_mon_opts.get(arg)) for arg in args) rc, s = crm_mon(extra_options) if rc != 0: raise IOError("crm_mon (rc=%d): %s" % (rc, s)) utils.page_string(s) return True
def cmd_status(args): ''' Calls crm_mon -1, passing optional extra arguments. Displays the output, paging if necessary. Raises ValueError if an illegal argument is passed. Raises IOError if crm_mon fails. ''' crm_mon_opts = { "bynode": "-n", "inactive": "-r", "ops": "-o", "timing": "-t", "failcounts": "-f", } has_crm_mon() def check(arg, val): if not val: raise ValueError("Unknown argument to status: " + str(arg)) return val extra_options = ' '.join(check(arg, crm_mon_opts.get(arg)) for arg in args) rc, s = crm_mon(extra_options) if rc != 0: raise IOError("crm_mon exited with code %d. Output: '%s'" % (rc, s)) utils.page_string(s)
def do_info(self, context, *args): "usage: info [<class>:[<provider>:]]<type>" if len(args) == 0: context.fatal_error("Expected [<class>:[<provider>:]]<type>") elif len(args) > 1: # obsolete syntax ra_type = args[0] ra_class = args[1] if len(args) < 3: ra_provider = "heartbeat" else: ra_provider = args[2] else: if args[0] in vars.meta_progs: ra_class = args[0] ra_provider = ra_type = None else: ra_class, ra_provider, ra_type = ra.disambiguate_ra_type( args[0]) agent = ra.RAInfo(ra_class, ra_type, ra_provider) if agent.mk_ra_node() is None: return False try: utils.page_string(agent.meta_pretty()) except Exception, msg: context.fatal_error(msg)
def show(self): ''' Page the "pretty" XML of the status section. ''' if self.get_status() is None: return False page_string(etree.tostring(self.status_node, pretty_print=True)) return True
def do_show(self, context): ''' Display the corosync configuration. ''' cfg = corosync.conf() if not os.path.isfile(cfg): context.fatal_error("No corosync configuration found on this node.") utils.page_string(open(cfg).read())
def show_options(fn): s = '' for opt in opts: if fn(opt): parts = opt.split('.') val = (opt, config.get_option(parts[0], parts[1], raw=True)) s += "%s = %s\n" % val utils.page_string(s)
def _diff_this(pssh, local_path, nodes, this_node): by_host = _diff_slurp(pssh, nodes, local_path) for host, result in by_host: if isinstance(result, pssh.Error): raise ValueError("Failed on %s: %s" % (host, str(result))) _, _, _, path = result _, s = utils.get_stdout("diff -U 0 -d -b --label %s --label %s %s %s" % (host, this_node, path, local_path)) utils.page_string(s)
def _diff(pssh, local_path, nodes): by_host = _diff_slurp(pssh, nodes, local_path) for host, result in by_host: if isinstance(result, pssh.Error): raise ValueError("Failed on %s: %s" % (host, str(result))) h1, r1 = by_host[0] h2, r2 = by_host[1] _, s = utils.get_stdout("diff -U 0 -d -b --label %s --label %s %s %s" % (h1, h2, r1[3], r2[3])) utils.page_string(s)
def do_show(self, context, t, *args): "usage: show <pe> [status]" opt_l = [] if not self._common_pe_render_check(context, opt_l, *args): return False showfun = self._pe_config if "status" in opt_l: showfun = self._pe_status s = self._render_pe(showfun, t) if context.previous_level_is("cibconfig"): cib_factory.refresh() if not s: return False utils.page_string(s)
def do_wdiff(self, context, t1, t2, *args): "usage: wdiff <pe> <pe> [status]" opt_l = [] if not self._common_pe_render_check(context, opt_l, *args): return False showfun = self._pe_config_plain if "status" in opt_l: showfun = self._pe_status_nohdr s = self._diff(showfun, t1, t2, wdiff=True) if context.previous_level_is("cibconfig"): cib_factory.refresh() if s is None: return False utils.page_string(s)
def topic_help(help_tab, topic): if topic not in help_tab: print "There is no help for topic %s" % topic return if type(help_tab[topic][0]) == type(()): shorthelp = help_tab[topic][0][0] longhelp = help_tab[topic][0][1] else: shorthelp = help_tab[topic][0] longhelp = help_tab[topic][1] if longhelp: page_string(longhelp) else: print shorthelp
def topic_help(help_tab,topic): if topic not in help_tab: print "There is no help for topic %s" % topic return if type(help_tab[topic][0]) == type(()): shorthelp = help_tab[topic][0][0] longhelp = help_tab[topic][0][1] else: shorthelp = help_tab[topic][0] longhelp = help_tab[topic][1] if longhelp: page_string(longhelp) else: print shorthelp
def do_peinputs(self, context, *args): """usage: peinputs [{<range>|<number>} ...] [v]""" argl = list(args) opt_l = utils.fetch_opts(argl, ["v"]) if argl: l = [] for s in argl: a = utils.convert2ints(s.split(':')) if a and len(a) == 2 and not utils.check_range(a): common_err("%s: invalid peinputs range" % a) return False l += crm_report.pelist(a, long=("v" in opt_l)) else: l = crm_report.pelist(long=("v" in opt_l)) if not l: return False s = '\n'.join(l) utils.page_string(s)
def do_diff(self, context, t1, t2, *args): "usage: diff <pe> <pe> [status] [html]" opt_l = [] if not self._common_pe_render_check(context, opt_l, *args): return False showfun = self._pe_config_plain mkhtml = "html" in opt_l if "status" in opt_l: showfun = self._pe_status_nohdr elif mkhtml: showfun = self._pe_config_noclr s = self._diff(showfun, t1, t2, html=mkhtml) if context.previous_level_is("cibconfig"): cib_factory.refresh() if s is None: return False if not mkhtml: utils.page_string(s) else: sys.stdout.writelines(s)
def do_info(self, context, *args): "usage: info [<class>:[<provider>:]]<type>" if len(args) == 0: context.fatal_error("Expected [<class>:[<provider>:]]<type>") elif len(args) > 1: # obsolete syntax if len(args) < 3: ra_type, ra_class, ra_provider = args[0], args[1], "heartbeat" else: ra_type, ra_class, ra_provider = args[0], args[1], args[2] elif args[0] in constants.meta_progs: ra_class, ra_provider, ra_type = args[0], None, None else: ra_class, ra_provider, ra_type = ra.disambiguate_ra_type(args[0]) agent = ra.RAInfo(ra_class, ra_type, ra_provider) if agent.mk_ra_node() is None: return False try: utils.page_string(agent.meta_pretty()) except Exception, msg: context.fatal_error(msg)
def paginate(self): ''' Display help, paginated. Replace asciidoc syntax with colorized output where possible. ''' helpfilter = HelpFilter() short_help = clidisplay.help_header(self.short) long_help = self.long if long_help: long_help = helpfilter(long_help) if not long_help.startswith('\n'): long_help = '\n' + long_help prefix = '' if self.is_alias(): prefix = helpfilter("(Redirected from `%s` to `%s`)\n" % self.alias_for) page_string(short_help + '\n' + prefix + long_help)
def do_diff(self, context): "usage: diff" rc, s = utils.get_stdout(utils.add_sudo("%s -d" % self.extcmd_stdout)) utils.page_string(s)