def do_load(self, context, *args): "usage: load [xml] {replace|update} {<url>|<path>}" if len(args) < 2: context.fatal_error("Expected 2 arguments (0 given)") if args[0] == "xml": if len(args) != 3: context.fatal_error("Expected 3 arguments (%d given)" % len(args)) url = args[2] method = args[1] xml = True else: if len(args) != 2: context.fatal_error("Expected 2 arguments (%d given)" % len(args)) url = args[1] method = args[0] xml = False if method not in ("replace", "update"): context.fatal_error("Unknown method %s" % method) if method == "replace": if options.interactive and cib_factory.has_cib_changed(): if not utils.ask("This operation will erase all changes. Do you want to proceed?"): return False cib_factory.erase() if xml: set_obj = mkset_obj("xml") else: set_obj = mkset_obj() return set_obj.import_file(method, url)
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_load(self, context, *args): "usage: load [xml] {replace|update} {<url>|<path>}" if len(args) < 2: context.fatal_error("Expected 2 arguments (0 given)") if args[0] == "xml": if len(args) != 3: context.fatal_error("Expected 3 arguments (%d given)" % len(args)) url = args[2] method = args[1] xml = True else: if len(args) != 2: context.fatal_error("Expected 2 arguments (%d given)" % len(args)) url = args[1] method = args[0] xml = False if method not in ("replace", "update"): context.fatal_error("Unknown method %s" % method) if method == "replace": if options.interactive and cib_factory.has_cib_changed(): if not utils.ask( "This operation will erase all changes. Do you want to proceed?" ): return False cib_factory.erase() if xml: set_obj = mkset_obj("xml") else: set_obj = mkset_obj() return set_obj.import_file(method, url)
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 end_game(self, no_questions_asked=False): ok = True if cib_factory.has_cib_changed(): if no_questions_asked or not options.interactive: ok = self._commit() elif utils.ask("There are changes pending. Do you want to commit them?"): ok = self._commit() cib_factory.reset() return ok
def _commit_meta_attr(self, context, rsc, name, value): """ Perform change to resource """ if not utils.is_name_sane(rsc): return False commit = not cib_factory.has_cib_changed() if not commit: context.info("Currently editing the CIB, changes will not be committed") return set_deep_meta_attr(rsc, name, value, commit=commit)
def end_game(self, no_questions_asked=False): ok = True if cib_factory.has_cib_changed(): if no_questions_asked or not options.interactive: ok = self._commit() elif utils.ask( "There are changes pending. Do you want to commit them?"): ok = self._commit() cib_factory.reset() return ok
def _common_pe_render_check(self, context, opt_l, *args): if context.previous_level_is("cibconfig") and cib_factory.has_cib_changed(): common_err("please try again after committing CIB changes") return False argl = list(args) supported_l = ["status"] if context.get_command_name() == "diff": supported_l.append("html") opt_l += utils.fetch_opts(argl, supported_l) if argl: syntax_err(' '.join(argl), context=context.get_command_name()) return False return True
def _common_pe_render_check(self, context, opt_l, *args): if context.previous_level_is( "cibconfig") and cib_factory.has_cib_changed(): common_err("please try again after committing CIB changes") return False argl = list(args) supported_l = ["status"] if context.get_command_name() == "diff": supported_l.append("html") opt_l += utils.fetch_opts(argl, supported_l) if argl: syntax_err(' '.join(argl), context=context.get_command_name()) return False return True
def _commit(self, force=None): if force and force != "force": syntax_err(('configure.commit', force)) return False if not cib_factory.has_cib_changed(): common_info("apparently there is nothing to commit") common_info("try changing something first") return True rc1 = True if not (force or utils.cibadmin_can_patch()): rc1 = cib_factory.is_current_cib_equal() rc2 = cib_factory.has_no_primitives() or \ self._verify(mkset_obj("xml", "changed"), mkset_obj("xml")) if rc1 and rc2: return cib_factory.commit() if force or config.core.force: common_info("commit forced") return cib_factory.commit(force=True) if utils.ask("Do you still want to commit?"): return cib_factory.commit(force=True) return False
def do_apply(self, context, *args): "usage: apply [<method>] [<config>]" method = "replace" name = '' if len(args) > 0: i = 0 if args[0] in ("replace", "update"): method = args[0] i += 1 if len(args) > i: name = args[i] if not name and not self.curr_conf: common_err("please load a config first") return False if name: if not self.config_exists(name): return False s = self.process(name) else: s = self.process() if not s: return False tmp = utils.str2tmp(s) if not tmp: return False if method == "replace": if options.interactive and cib_factory.has_cib_changed(): if not utils.ask( "This operation will erase all changes. Do you want to proceed?" ): return False cib_factory.erase() set_obj = mkset_obj() rc = set_obj.import_file(method, tmp) try: os.unlink(tmp) except: pass return rc
def _commit(self, force=False, replace=False): if force: syntax_err(('configure.commit', force)) return False if not cib_factory.has_cib_changed(): common_info("apparently there is nothing to commit") common_info("try changing something first") return True replace = replace or not utils.cibadmin_can_patch() rc1 = True if replace and not force: rc1 = cib_factory.is_current_cib_equal() rc2 = cib_factory.has_no_primitives() or \ self._verify(mkset_obj("xml", "changed"), mkset_obj("xml")) if rc1 and rc2: return cib_factory.commit(replace=replace) if force or config.core.force: common_info("commit forced") return cib_factory.commit(force=True, replace=replace) if utils.ask("Do you still want to commit?"): return cib_factory.commit(force=True, replace=replace) return False
def do_apply(self, context, *args): "usage: apply [<method>] [<config>]" method = "replace" name = '' if len(args) > 0: i = 0 if args[0] in ("replace", "update"): method = args[0] i += 1 if len(args) > i: name = args[i] if not name and not self.curr_conf: common_err("please load a config first") return False if name: if not self.config_exists(name): return False s = self.process(name) else: s = self.process() if not s: return False tmp = utils.str2tmp(s) if not tmp: return False if method == "replace": if options.interactive and cib_factory.has_cib_changed(): if not utils.ask("This operation will erase all changes. Do you want to proceed?"): return False cib_factory.erase() set_obj = mkset_obj() rc = set_obj.import_file(method, tmp) try: os.unlink(tmp) except: pass return rc
def should_wait(self): return cib_factory.has_cib_changed()
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()