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 _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 _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