Exemplo n.º 1
0
Arquivo: main.py Projeto: lge/crmsh
def cib_prompt():
    shadow = utils.get_cib_in_use()
    if not shadow:
        return constants.live_cib_prompt
    if constants.tmp_cib:
        return constants.tmp_cib_prompt
    return shadow
Exemplo n.º 2
0
Arquivo: ui_cib.py Projeto: lge/crmsh
 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
Exemplo n.º 3
0
def cib_prompt():
    shadow = utils.get_cib_in_use()
    if not shadow:
        return vars.live_cib_prompt
    if vars.tmp_cib:
        return vars.tmp_cib_prompt
    return shadow
Exemplo n.º 4
0
def cib_prompt():
    shadow = utils.get_cib_in_use()
    if not shadow:
        return constants.live_cib_prompt
    if constants.tmp_cib:
        return constants.tmp_cib_prompt
    return shadow
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 def initialize(self):
     src = utils.get_cib_in_use()
     if not src:
         src = "live"
     else:
         src = "shadow:" + src
     if self._load(src):
         self.origin = src
Exemplo n.º 7
0
 def initialize(self):
     src = utils.get_cib_in_use()
     if not src:
         src = "live"
     else:
         src = "shadow:" + src
     if self._load(src):
         self.origin = src
Exemplo n.º 8
0
Arquivo: ui_cib.py Projeto: lge/crmsh
 def do_delete(self, context, name):
     "usage: delete <shadow_cib>"
     if not utils.is_filename_sane(name):
         context.fatal_error("Bad filename: " + name)
     if utils.get_cib_in_use() == name:
         context.fatal_error("%s shadow CIB is in use" % name)
     if utils.ext_cmd("%s -D '%s' --force" % (self.extcmd, name)) == 0:
         context.info("%s shadow CIB deleted" % name)
     else:
         context.fatal_error("failed to delete %s shadow CIB" % name)
Exemplo n.º 9
0
 def do_delete(self, context, name):
     "usage: delete <shadow_cib>"
     if not utils.is_filename_sane(name):
         context.fatal_error("Bad filename: " + name)
     if utils.get_cib_in_use() == name:
         context.fatal_error("%s shadow CIB is in use" % name)
     if utils.ext_cmd("%s -D '%s' --force" % (self.extcmd, name)) == 0:
         context.info("%s shadow CIB deleted" % name)
     else:
         context.fatal_error("failed to delete %s shadow CIB" % name)
Exemplo n.º 10
0
Arquivo: ui_cib.py Projeto: lge/crmsh
 def do_commit(self, context, name=None):
     "usage: commit [<shadow_cib>]"
     if name and not utils.is_filename_sane(name):
         context.fatal_error("Bad filename: " + name)
     if not name:
         name = utils.get_cib_in_use()
     if not name:
         context.fatal_error("There is nothing to commit")
     if utils.ext_cmd("%s -C '%s' --force" % (self.extcmd, name)) == 0:
         context.info("committed '%s' shadow CIB to the cluster" % name)
     else:
         context.fatal_error("failed to commit the %s shadow CIB" % name)
     if constants.tmp_cib:
         self._use('', '')
Exemplo n.º 11
0
 def do_commit(self, context, name=None):
     "usage: commit [<shadow_cib>]"
     if name and not utils.is_filename_sane(name):
         context.fatal_error("Bad filename: " + name)
     if not name:
         name = utils.get_cib_in_use()
     if not name:
         context.fatal_error("There is nothing to commit")
     if utils.ext_cmd("%s -C '%s' --force" % (self.extcmd, name)) == 0:
         context.info("committed '%s' shadow CIB to the cluster" % name)
     else:
         context.fatal_error("failed to commit the %s shadow CIB" % name)
     if vars.tmp_cib:
         self._use('', '')
Exemplo n.º 12
0
Arquivo: ui_cib.py Projeto: lge/crmsh
 def _use(self, name, withstatus):
     # Choose a shadow cib for further changes. If the name
     # provided is empty, then choose the live (cluster) cib.
     # Don't allow ' in shadow names
     if not name or name == "live":
         if withstatus:
             cib_status.load("live")
         if constants.tmp_cib:
             utils.ext_cmd("%s -D '%s' --force" % (self.extcmd, utils.get_cib_in_use()))
             constants.tmp_cib = False
         utils.clear_cib_in_use()
     else:
         utils.set_cib_in_use(name)
         if withstatus:
             cib_status.load("shadow:%s" % name)
     return True
Exemplo n.º 13
0
 def _use(self, name, withstatus):
     # Choose a shadow cib for further changes. If the name
     # provided is empty, then choose the live (cluster) cib.
     # Don't allow ' in shadow names
     if not name or name == "live":
         if withstatus:
             cib_status.load("live")
         if constants.tmp_cib:
             utils.ext_cmd("%s -D '%s' --force" % (self.extcmd, utils.get_cib_in_use()))
             constants.tmp_cib = False
         utils.clear_cib_in_use()
     else:
         utils.set_cib_in_use(name)
         if withstatus:
             cib_status.load("shadow:%s" % name)
     return True
Exemplo n.º 14
0
def is_live_cib():
    '''We working with the live cluster?'''
    return not get_cib_in_use() and not os.getenv("CIB_file")
Exemplo n.º 15
0
def is_live_cib():
    '''We working with the live cluster?'''
    return not get_cib_in_use() and not os.getenv("CIB_file")
Exemplo n.º 16
0
def test_shadowcib():
    assert utils.get_cib_in_use() == ""
    utils.set_cib_in_use("foo")
    assert utils.get_cib_in_use() == "foo"
    utils.clear_cib_in_use()
    assert utils.get_cib_in_use() == ""