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_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_erase(self, context, nodes=None): "usage: erase [nodes]" if nodes is None: return cib_factory.erase() if nodes != 'nodes': context.fatal_error("Expected 'nodes' (found '%s')" % (nodes)) return cib_factory.erase_nodes()
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 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