Esempio n. 1
0
 def do_load(self, context, *args):
     "usage: load [xml] {replace|update} {<url>|<path>}"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     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)
Esempio n. 2
0
 def _pe_config_obj(self, pe_f):
     '''Return set_obj of the configuration. It can later be
     rendered using the repr() method.'''
     self._setup_cib_env(pe_f)
     if not cib_factory.refresh():
         set_obj = mkset_obj("NOOBJ")
     else:
         set_obj = mkset_obj()
     return set_obj
Esempio n. 3
0
 def _pe_config_obj(self, pe_f):
     '''Return set_obj of the configuration. It can later be
     rendered using the repr() method.'''
     self._setup_cib_env(pe_f)
     if not cib_factory.refresh():
         set_obj = mkset_obj("NOOBJ")
     else:
         set_obj = mkset_obj()
     return set_obj
Esempio n. 4
0
 def do_save(self, context, *args):
     "usage: save [xml] <filename>"
     if not args:
         context.fatal_error("Expected 1 argument (0 given)")
     if args[0] == "xml":
         if len(args) != 2:
             context.fatal_error("Expected 2 arguments (%d given)" % (len(args)))
         filename = args[1]
         set_obj = mkset_obj("xml")
     else:
         filename = args[0]
         set_obj = mkset_obj()
     return set_obj.save_to_file(filename)
Esempio n. 5
0
 def do_save(self, context, *args):
     "usage: save [xml] <filename>"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     if not args:
         context.fatal_error("Expected 1 argument (0 given)")
     if args[0] == "xml":
         if len(args) != 2:
             context.fatal_error("Expected 2 arguments (%d given)" % (len(args)))
         filename = args[1]
         set_obj = mkset_obj("xml")
     else:
         filename = args[0]
         set_obj = mkset_obj()
     return set_obj.save_to_file(filename)
Esempio n. 6
0
 def do_save(self, context, *args):
     "usage: save [xml] [<id>...] <filename>"
     if not args:
         context.fatal_error("Expected 1 argument (0 given)")
     filename = args[-1]
     setargs = args[:-1]
     set_obj = mkset_obj(*setargs)
     return set_obj.save_to_file(filename)
Esempio n. 7
0
 def do_edit(self, context, *args):
     "usage: edit [xml] [<id>...]"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     err_buf.buffer()  # keep error messages
     set_obj = mkset_obj(*args)
     err_buf.release()  # show them, but get an ack from the user
     return set_obj.edit()
Esempio n. 8
0
 def do_save(self, context, *args):
     "usage: save [xml] [<id>...] <filename>"
     if not args:
         context.fatal_error("Expected 1 argument (0 given)")
     filename = args[-1]
     setargs = args[:-1]
     set_obj = mkset_obj(*setargs)
     return set_obj.save_to_file(filename)
Esempio n. 9
0
 def do_ptest(self, context, *args):
     "usage: ptest [nograph] [v...] [scores] [utilization] [actions]"
     # use ptest/crm_simulate depending on which command was
     # used
     config.core.ptest = constants.simulate_programs[context.get_command_name()]
     if not config.core.ptest:
         return False
     set_obj = mkset_obj("xml")
     return ui_utils.ptestlike(set_obj.ptest, 'vv', context.get_command_name(), args)
Esempio n. 10
0
 def _pe_config_obj(self, pe_f):
     '''Return set_obj of the configuration. It can later be
     rendered using the repr() method.'''
     self._setup_cib_env(pe_f)
     cib_factory.refresh()
     if not cib_factory.is_cib_sane():
         return False
     set_obj = mkset_obj()
     return set_obj
Esempio n. 11
0
 def _pe_config_obj(self, pe_f):
     '''Return set_obj of the configuration. It can later be
     rendered using the repr() method.'''
     self._setup_cib_env(pe_f)
     cib_factory.refresh()
     if not cib_factory.is_cib_sane():
         return False
     set_obj = mkset_obj()
     return set_obj
Esempio n. 12
0
 def do_ptest(self, context, *args):
     "usage: ptest [nograph] [v...] [scores] [utilization] [actions]"
     if not cib_factory.is_cib_sane():
         return False
     # use ptest/crm_simulate depending on which command was
     # used
     config.core.ptest = vars.simulate_programs[context.get_command_name()]
     if not config.core.ptest:
         return False
     set_obj = mkset_obj("xml")
     return ui_utils.ptestlike(set_obj.ptest, 'vv', context.get_command_name(), args)
Esempio n. 13
0
 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
Esempio n. 14
0
 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
Esempio n. 15
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" %
                                 args[0])
         if len(args) != 2:
             context.fatal_error(
                 "Expected 'after|before <id>' (%d arguments given)" %
                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" %
                             (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id, )
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Esempio n. 16
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" % args[0])
         if len(args) != 2:
             context.fatal_error("Expected 'after|before <id>' (%d arguments given)" %
                                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" % (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id,)
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Esempio n. 17
0
 def do_graph(self, context, *args):
     "usage: graph [<gtype> [<file> [<img_format>]]]"
     if args and args[0] == "exportsettings":
         return utils.save_graphviz_file(userdir.GRAPHVIZ_USER_FILE, constants.graph)
     rc, gtype, outf, ftype = ui_utils.graph_args(args)
     if not rc:
         context.fatal_error("Failed to create graph")
     rc, d = utils.load_graphviz_file(userdir.GRAPHVIZ_USER_FILE)
     if rc and d:
         constants.graph = d
     set_obj = mkset_obj()
     if not outf:
         rc = set_obj.show_graph(gtype)
     elif gtype == ftype:
         rc = set_obj.save_graph(gtype, outf)
     else:
         rc = set_obj.graph_img(gtype, outf, ftype)
     return rc
Esempio n. 18
0
 def do_graph(self, context, *args):
     "usage: graph [<gtype> [<file> [<img_format>]]]"
     if args and args[0] == "exportsettings":
         return utils.save_graphviz_file(userdir.GRAPHVIZ_USER_FILE,
                                         constants.graph)
     rc, gtype, outf, ftype = ui_utils.graph_args(args)
     if not rc:
         context.fatal_error("Failed to create graph")
     rc, d = utils.load_graphviz_file(userdir.GRAPHVIZ_USER_FILE)
     if rc and d:
         constants.graph = d
     set_obj = mkset_obj()
     if not outf:
         rc = set_obj.show_graph(gtype)
     elif gtype == ftype:
         rc = set_obj.save_graph(gtype, outf)
     else:
         rc = set_obj.graph_img(gtype, outf, ftype)
     return rc
Esempio n. 19
0
 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
Esempio n. 20
0
 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
Esempio n. 21
0
 def do_edit(self, context, *args):
     "usage: edit [xml] [<id>...]"
     err_buf.buffer()  # keep error messages
     set_obj = mkset_obj(*args)
     err_buf.release()  # show them, but get an ack from the user
     return set_obj.edit()
Esempio n. 22
0
 def do_filter(self, context, filterprog, *args):
     "usage: filter <prog> [xml] [<id>...]"
     set_obj = mkset_obj(*args)
     return set_obj.filter(filterprog)
Esempio n. 23
0
 def do_verify(self, context):
     "usage: verify"
     set_obj_all = mkset_obj("xml")
     return self._verify(set_obj_all, set_obj_all)
Esempio n. 24
0
 def do_verify(self, context):
     "usage: verify"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     set_obj_all = mkset_obj("xml")
     return self._verify(set_obj_all, set_obj_all)
Esempio n. 25
0
 def do_filter(self, context, filterprog, *args):
     "usage: filter <prog> [xml] [<id>...]"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     set_obj = mkset_obj(*args)
     return set_obj.filter(filterprog)
Esempio n. 26
0
def test_show():
    setobj = cibconfig.mkset_obj()
    s = setobj.repr_nopretty()
    sp = s.splitlines()
    assert_in("node 1: ha-one", sp[0:3])
Esempio n. 27
0
 def do_show(self, context, *args):
     "usage: show [xml] [<id>...]"
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     set_obj = mkset_obj(*args)
     return set_obj.show()
Esempio n. 28
0
def test_show():
    setobj = cibconfig.mkset_obj()
    s = setobj.repr_nopretty()
    sp = s.splitlines()
    assert_in("node 1: ha-one", sp[0:3])
Esempio n. 29
0
 def do_show(self, context, *args):
     "usage: show [xml] [<id>...]"
     set_obj = mkset_obj(*args)
     return set_obj.show()
Esempio n. 30
0
 def do_filter(self, context, filterprog, *args):
     "usage: filter <prog> [xml] [<id>...]"
     set_obj = mkset_obj(*args)
     return set_obj.filter(filterprog)
Esempio n. 31
0
 def do_verify(self, context):
     "usage: verify"
     set_obj_all = mkset_obj("xml")
     return self._verify(set_obj_all, set_obj_all)
Esempio n. 32
0
 def do_edit(self, context, *args):
     "usage: edit [xml] [<id>...]"
     err_buf.buffer()  # keep error messages
     set_obj = mkset_obj(*args)
     err_buf.release()  # show them, but get an ack from the user
     return set_obj.edit()
Esempio n. 33
0
 def do_show(self, context, *args):
     "usage: show [xml] [<id>...]"
     set_obj = mkset_obj(*args)
     return set_obj.show()