Esempio n. 1
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
Esempio n. 2
0
File: ui_cib.py Progetto: 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
Esempio n. 3
0
 def do_refresh(self, context):
     "usage: refresh"
     if options.interactive and cib_factory.has_cib_changed():
         if not utils.ask(
                 "All changes will be dropped. Do you want to proceed?"):
             return
     cib_factory.refresh()
Esempio n. 4
0
 def do_show(self, context, t, *args):
     "usage: show <pe> [status]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config
     if "status" in opt_l:
         showfun = self._pe_status
     s = self._render_pe(showfun, t)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     utils.page_string(s)
Esempio n. 5
0
 def do_wdiff(self, context, t1, t2, *args):
     "usage: wdiff <pe> <pe> [status]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config_plain
     if "status" in opt_l:
         showfun = self._pe_status_nohdr
     s = self._diff(showfun, t1, t2, wdiff=True)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if s is None:
         return False
     utils.page_string(s)
Esempio n. 6
0
 def do_wdiff(self, context, t1, t2, *args):
     "usage: wdiff <pe> <pe> [status]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config_plain
     if "status" in opt_l:
         showfun = self._pe_status_nohdr
     s = self._diff(showfun, t1, t2, wdiff=True)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if s is None:
         return False
     utils.page_string(s)
Esempio n. 7
0
 def do_show(self, context, t, *args):
     "usage: show <pe> [status]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config
     if "status" in opt_l:
         showfun = self._pe_status
     s = self._render_pe(showfun, t)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     utils.page_string(s)
Esempio n. 8
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():
         return False
     set_obj = mkset_obj()
     return set_obj
Esempio n. 9
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. 10
0
 def do_dump(self, context, t, *args):
     '''dump configuration or status to a file and print file
     name.
     NB: The configuration is color rendered, but note that
     that depends on the current value of the TERM variable.
     '''
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     if "status" in opt_l:
         s = self._render_pe(self._pe_status_nohdr, t)
     else:
         s = utils.term_render(self._render_pe(self._pe_config_plain, t))
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     print utils.str2tmp(s)
Esempio n. 11
0
 def do_dump(self, context, t, *args):
     '''dump configuration or status to a file and print file
     name.
     NB: The configuration is color rendered, but note that
     that depends on the current value of the TERM variable.
     '''
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     if "status" in opt_l:
         s = self._render_pe(self._pe_status_nohdr, t)
     else:
         s = utils.term_render(self._render_pe(self._pe_config_plain, t))
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if not s:
         return False
     print utils.str2tmp(s)
Esempio n. 12
0
 def _get_trace_rsc(self, rsc_id):
     if not cib_factory.refresh():
         return None
     rsc = cib_factory.find_object(rsc_id)
     if not rsc:
         common_err("resource %s does not exist" % rsc_id)
         return None
     if rsc.obj_type != "primitive":
         common_err("element %s is not a primitive resource" % rsc_id)
         return None
     return rsc
Esempio n. 13
0
 def _get_trace_rsc(self, rsc_id):
     if not cib_factory.refresh():
         return None
     rsc = cib_factory.find_object(rsc_id)
     if not rsc:
         common_err("resource %s does not exist" % rsc_id)
         return None
     if rsc.obj_type != "primitive":
         common_err("element %s is not a primitive resource" % rsc_id)
         return None
     return rsc
Esempio n. 14
0
 def do_diff(self, context, t1, t2, *args):
     "usage: diff <pe> <pe> [status] [html]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config_plain
     mkhtml = "html" in opt_l
     if "status" in opt_l:
         showfun = self._pe_status_nohdr
     elif mkhtml:
         showfun = self._pe_config_noclr
     s = self._diff(showfun, t1, t2, html=mkhtml)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if s is None:
         return False
     if not mkhtml:
         utils.page_string(s)
     else:
         sys.stdout.writelines(s)
Esempio n. 15
0
 def do_diff(self, context, t1, t2, *args):
     "usage: diff <pe> <pe> [status] [html]"
     self._init_source()
     opt_l = []
     if not self._common_pe_render_check(context, opt_l, *args):
         return False
     showfun = self._pe_config_plain
     mkhtml = "html" in opt_l
     if "status" in opt_l:
         showfun = self._pe_status_nohdr
     elif mkhtml:
         showfun = self._pe_config_noclr
     s = self._diff(showfun, t1, t2, html=mkhtml)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     if s is None:
         return False
     if not mkhtml:
         utils.page_string(s)
     else:
         sys.stdout.writelines(s)
Esempio n. 16
0
 def do_graph(self, context, t, *args):
     "usage: graph <pe> [<gtype> [<file> [<img_format>]]]"
     self._init_source()
     pe_f = self._get_diff_pe_input(t)
     if not pe_f:
         return False
     rc, gtype, outf, ftype = ui_utils.graph_args(args)
     if not rc:
         return False
     rc, d = utils.load_graphviz_file(userdir.GRAPHVIZ_USER_FILE)
     if rc and d:
         constants.graph = d
     set_obj = self._pe_config_obj(pe_f)
     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)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     return rc
Esempio n. 17
0
 def do_graph(self, context, t, *args):
     "usage: graph <pe> [<gtype> [<file> [<img_format>]]]"
     self._init_source()
     pe_f = self._get_diff_pe_input(t)
     if not pe_f:
         return False
     rc, gtype, outf, ftype = ui_utils.graph_args(args)
     if not rc:
         return False
     rc, d = utils.load_graphviz_file(userdir.GRAPHVIZ_USER_FILE)
     if rc and d:
         constants.graph = d
     set_obj = self._pe_config_obj(pe_f)
     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)
     if context.previous_level_is("cibconfig"):
         cib_factory.refresh()
     return rc
Esempio n. 18
0
 def do_refresh(self, context):
     "usage: refresh"
     if options.interactive and cib_factory.has_cib_changed():
         if not utils.ask("All changes will be dropped. Do you want to proceed?"):
             return
     cib_factory.refresh()