def do_use(self, context, name='', withstatus=''): "usage: use [<shadow_cib>] [withstatus]" # check the name argument if name and not utils.is_filename_sane(name): context.fatal_error("Bad filename: " + name) if name and name != "live": if not os.access(xmlutil.shadowfile(name), os.F_OK): context.fatal_error("%s: no such shadow CIB" % name) if withstatus and withstatus != "withstatus": context.fatal_error("Expected 'withstatus', got '%s'" % (withstatus)) # If invoked from configure # take special precautions if not context.previous_level_is("cibconfig"): return self._use(name, withstatus) if not cib_factory.has_cib_changed(): ret = self._use(name, withstatus) # new CIB: refresh the CIB factory cib_factory.refresh() return ret saved_cib = utils.get_cib_in_use() self._use(name, '') # don't load the status yet if not cib_factory.is_current_cib_equal(silent=True): # user made changes and now wants to switch to a # different and unequal CIB; we refuse to cooperate context.error_message("the requested CIB is different from the current one") if config.core.force: context.info("CIB overwrite forced") elif not utils.ask("All changes will be dropped. Do you want to proceed?"): self._use(saved_cib, '') # revert to the previous CIB return False return self._use(name, withstatus) # now load the status too
def do_refresh(self, context): "usage: refresh" if options.interactive and cib_factory.has_cib_changed(): if not utils.ask( "All changes will be dropped. Do you want to proceed?"): return cib_factory.refresh()
def do_show(self, context, t, *args): "usage: show <pe> [status]" self._init_source() 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]" self._init_source() 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 _pe_config_obj(self, pe_f): '''Return set_obj of the configuration. It can later be rendered using the repr() method.''' self._setup_cib_env(pe_f) if not cib_factory.refresh(): return False set_obj = mkset_obj() return set_obj
def _pe_config_obj(self, pe_f): '''Return set_obj of the configuration. It can later be rendered using the repr() method.''' self._setup_cib_env(pe_f) if not cib_factory.refresh(): set_obj = mkset_obj("NOOBJ") else: set_obj = mkset_obj() return set_obj
def do_dump(self, context, t, *args): '''dump configuration or status to a file and print file name. NB: The configuration is color rendered, but note that that depends on the current value of the TERM variable. ''' self._init_source() opt_l = [] if not self._common_pe_render_check(context, opt_l, *args): return False if "status" in opt_l: s = self._render_pe(self._pe_status_nohdr, t) else: s = utils.term_render(self._render_pe(self._pe_config_plain, t)) if context.previous_level_is("cibconfig"): cib_factory.refresh() if not s: return False print utils.str2tmp(s)
def _get_trace_rsc(self, rsc_id): if not cib_factory.refresh(): return None rsc = cib_factory.find_object(rsc_id) if not rsc: common_err("resource %s does not exist" % rsc_id) return None if rsc.obj_type != "primitive": common_err("element %s is not a primitive resource" % rsc_id) return None return rsc
def do_diff(self, context, t1, t2, *args): "usage: diff <pe> <pe> [status] [html]" self._init_source() 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_graph(self, context, t, *args): "usage: graph <pe> [<gtype> [<file> [<img_format>]]]" self._init_source() pe_f = self._get_diff_pe_input(t) if not pe_f: return False rc, gtype, outf, ftype = ui_utils.graph_args(args) if not rc: return False rc, d = utils.load_graphviz_file(userdir.GRAPHVIZ_USER_FILE) if rc and d: constants.graph = d set_obj = self._pe_config_obj(pe_f) if not outf: rc = set_obj.show_graph(gtype) elif gtype == ftype: rc = set_obj.save_graph(gtype, outf) else: rc = set_obj.graph_img(gtype, outf, ftype) if context.previous_level_is("cibconfig"): cib_factory.refresh() return rc
def do_refresh(self, context): "usage: refresh" if options.interactive and cib_factory.has_cib_changed(): if not utils.ask("All changes will be dropped. Do you want to proceed?"): return cib_factory.refresh()