Пример #1
0
    def do_new(self, context, *args):
        "usage: new [<shadow_cib>] [withstatus] [force] [empty]"
        argl = list(args)
        opt_l = utils.fetch_opts(argl, ["force", "--force", "withstatus", "empty"])
        if len(argl) > 1:
            context.fatal_error("Unexpected argument(s): " + ' '.join(argl))

        name = None
        if argl:
            name = argl[0]
            if not utils.is_filename_sane(name):
                context.fatal_error("Bad filename: " + name)
            if name in (constants.tmp_cib_prompt, constants.live_cib_prompt):
                context.fatal_error("Shadow name '%s' is not allowed" % (name))
            del argl[0]
            constants.tmp_cib = False
        else:
            fd, fname = tmpfiles.create(dir=xmlutil.cib_shadow_dir(), prefix="shadow.crmsh_")
            name = os.path.basename(fname).replace("shadow.", "")
            constants.tmp_cib = True

        if "empty" in opt_l:
            new_cmd = "%s -e '%s'" % (self.extcmd, name)
        else:
            new_cmd = "%s -c '%s'" % (self.extcmd, name)
        if constants.tmp_cib or config.core.force or "force" in opt_l or "--force" in opt_l:
            new_cmd = "%s --force" % new_cmd
        if utils.ext_cmd(new_cmd) == 0:
            context.info("%s shadow CIB created" % name)
            self.do_use(context, name)
            if "withstatus" in opt_l:
                cib_status.load("shadow:%s" % name)
Пример #2
0
    def do_new(self, context, *args):
        "usage: new [<shadow_cib>] [withstatus] [force] [empty]"
        argl = list(args)
        opt_l = utils.fetch_opts(argl, ["force", "--force", "withstatus", "empty"])
        if len(argl) > 1:
            context.fatal_error("Unexpected argument(s): " + ' '.join(argl))

        name = None
        if argl:
            name = argl[0]
            if not utils.is_filename_sane(name):
                context.fatal_error("Bad filename: " + name)
            if name in (constants.tmp_cib_prompt, constants.live_cib_prompt):
                context.fatal_error("Shadow name '%s' is not allowed" % (name))
            del argl[0]
            constants.tmp_cib = False
        else:
            fd, fname = tmpfiles.create(dir=xmlutil.cib_shadow_dir(), prefix="shadow.crmsh_")
            name = os.path.basename(fname).replace("shadow.", "")
            constants.tmp_cib = True

        if "empty" in opt_l:
            new_cmd = "%s -e '%s'" % (self.extcmd, name)
        else:
            new_cmd = "%s -c '%s'" % (self.extcmd, name)
        if constants.tmp_cib or config.core.force or "force" in opt_l or "--force" in opt_l:
            new_cmd = "%s --force" % new_cmd
        if utils.ext_cmd(new_cmd) == 0:
            context.info("%s shadow CIB created" % name)
            self.do_use(context, name)
            if "withstatus" in opt_l:
                cib_status.load("shadow:%s" % name)
Пример #3
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
Пример #4
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
Пример #5
0
 def do_load(self, context, org):
     "usage: load {<file>|shadow:<cib>|live}"
     return cib_status.load(org)
Пример #6
0
 def do_load(self, context, org):
     "usage: load {<file>|shadow:<cib>|live}"
     return cib_status.load(org)