def run(): try: if len(sys.argv) >= 2 and sys.argv[1] == '--compgen': compgen() return 0 envsetup() userdir.mv_user_files() ui = ui_root.Root() context = ui_context.Context(ui) load_rc(context, userdir.RC_FILE) atexit.register(exit_handler) options.interactive = utils.can_ask() if not options.interactive: err_buf.reset_lineno() options.batch = True user_args = parse_options() term._init() if options.profile: return profile_run(context, user_args) else: return do_work(context, user_args) except KeyboardInterrupt: print "Ctrl-C, leaving" sys.exit(1) except ValueError, e: common_err(str(e))
def do_weak_bond(self, context, *nodes): ''' Create a 'weak' colocation: Colocating a non-sequential resource set with a dummy resource which is not monitored creates, in effect, a colocation which does not imply any internal relationship between resources. ''' if len(nodes) < 2: context.fatal_error("Need at least two arguments") for node in nodes: obj = cib_factory.find_object(node) if not obj: context.fatal_error("Object not found: %s" % (node)) if not xmlutil.is_primitive(obj.node): context.fatal_error("Object not primitive: %s" % (node)) constraint_name = self.make_unique_name('place-constraint-') dummy_name = self.make_unique_name('place-dummy-') print "Create weak bond / independent colocation" print "The following elements will be created:" print " * Colocation constraint, ID: %s" % (constraint_name) print " * Dummy resource, ID: %s" % (dummy_name) if not utils.can_ask() or utils.ask("Create resources?"): cib_factory.create_object('primitive', dummy_name, 'ocf:heartbeat:Dummy') colo = ['colocation', constraint_name, 'inf:', '('] colo.extend(nodes) colo.append(')') colo.append(dummy_name) cib_factory.create_object(*colo)
def _set_interactive(self): '''Set the interactive option only if we're on a tty.''' if utils.can_ask(): options.interactive = True