def set_property(argv): if not argv: usage.property(['set']) sys.exit(1) prop_def_dict = utils.get_cluster_properties_definition() nodes_attr = "--node" in utils.pcs_options failed = False forced = "--force" in utils.pcs_options properties = {} for arg in argv: args = arg.split('=') if len(args) != 2: utils.err("invalid property format: '{0}'".format(arg), False) failed = True elif not args[0]: utils.err("empty property name: '{0}'".format(arg), False) failed = True elif nodes_attr or forced or args[1].strip() == "": properties[args[0]] = args[1] else: try: if utils.is_valid_cluster_property( prop_def_dict, args[0], args[1] ): properties[args[0]] = args[1] else: utils.err( "invalid value of property: '{0}', (use --force to " "override)".format(arg), False ) failed = True except utils.UnknownPropertyException: utils.err( "unknown cluster property: '{0}', (use --force to " "override)".format(args[0]), False ) failed = True if failed: sys.exit(1) if nodes_attr: for prop, value in properties.items(): utils.set_node_attribute(prop, value, utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for prop, value in properties.items(): utils.set_cib_property(prop, value, cib_dom) utils.replace_cib_configuration(cib_dom)
def unset_property(argv): if len(argv) < 1: usage.property() sys.exit(1) if "--node" in utils.pcs_options: for arg in argv: utils.set_node_attribute(arg, "",utils.pcs_options["--node"]) else: cib_dom = utils.get_cib_dom() for arg in argv: utils.set_cib_property(arg, "", cib_dom) utils.replace_cib_configuration(cib_dom)
def property_cmd(argv): if len(argv) == 0: argv = ["list"] sub_cmd = argv.pop(0) if sub_cmd == "help": usage.property(argv) elif sub_cmd == "set": set_property(argv) elif sub_cmd == "unset": unset_property(argv) elif sub_cmd == "list" or sub_cmd == "show": list_property(argv) elif sub_cmd == "get_cluster_properties_definition": print(json.dumps(utils.get_cluster_properties_definition())) else: usage.property() sys.exit(1)
def property_cmd(lib, argv, modifiers): if not argv: argv = ["list"] try: sub_cmd = argv.pop(0) if sub_cmd == "help": usage.property(argv) elif sub_cmd == "set": set_property(lib, argv, modifiers) elif sub_cmd == "unset": unset_property(lib, argv, modifiers) elif sub_cmd in ("list", "show"): list_property(lib, argv, modifiers) elif sub_cmd == "get_cluster_properties_definition": print_cluster_properties_definition(lib, argv, modifiers) else: raise CmdLineInputError() except LibraryError as e: utils.process_library_reports(e.args) except CmdLineInputError as e: utils.exit_on_cmdline_input_errror(e, "property", sub_cmd)
from pcs import ( prop, usage, ) from pcs.cli.common.routing import create_router property_cmd = create_router( { "help": lambda _lib, _argv, _modifiers: usage.property(_argv), "set": prop.set_property, "unset": prop.unset_property, "list": prop.list_property, "show": prop.list_property, "get_cluster_properties_definition": prop.print_cluster_properties_definition, }, ["property"], default_cmd="list")
from pcs import ( prop, usage, ) from pcs.cli.common.routing import create_router property_cmd = create_router( { "help": lambda _lib, _argv, _modifiers: usage.property(_argv), "set": prop.set_property, "unset": prop.unset_property, "list": prop.list_property, "show": prop.list_property, "get_cluster_properties_definition": prop.print_cluster_properties_definition, }, ["property"], default_cmd="list" )
from pcs import ( prop, usage, ) from pcs.cli.common.routing import create_router property_cmd = create_router( { "help": lambda _lib, _argv, _modifiers: print(usage.property(_argv)), "set": prop.set_property, "unset": prop.unset_property, # TODO remove, deprecated command # replaced with 'config' "list": prop.list_property_deprecated, # TODO remove, deprecated command # replaced with 'config' "show": prop.list_property_deprecated, "config": prop.list_property, "get_cluster_properties_definition": (prop.print_cluster_properties_definition), }, ["property"], default_cmd="config", )