예제 #1
0
def constraint_order_cmd(lib, argv, modifiers):
    if not argv:
        sub_cmd = "show"
    else:
        sub_cmd = argv.pop(0)

    try:
        if sub_cmd == "set":
            order_command.create_with_set(lib, argv, modifiers)
        elif sub_cmd in ["remove", "delete"]:
            order_rm(lib, argv, modifiers)
        elif sub_cmd == "show":
            order_command.show(lib, argv, modifiers)
        else:
            order_start(lib, [sub_cmd] + argv, modifiers)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "constraint", ["order", sub_cmd])
예제 #2
0
def constraint_cmd(lib, argv, modifiers):
    if not argv:
        argv = ["list"]
    sub_cmd = argv.pop(0)

    try:
        if sub_cmd == "help":
            usage.constraint(argv)
        elif sub_cmd == "location":
            try:
                if not argv:
                    sub_cmd2 = "show"
                else:
                    sub_cmd2 = argv.pop(0)

                if sub_cmd2 == "add":
                    location_add(lib, argv, modifiers)
                elif sub_cmd2 in ["remove", "delete"]:
                    location_remove(lib, argv, modifiers)
                elif sub_cmd2 == "show":
                    location_show(lib, argv, modifiers)
                elif len(argv) >= 2:
                    if argv[0] == "rule":
                        location_rule(lib, [sub_cmd2] + argv, modifiers)
                    else:
                        location_prefer(lib, [sub_cmd2] + argv, modifiers)
                else:
                    raise CmdLineInputError()
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint",
                                                   f"location {sub_cmd2}")
        elif sub_cmd == "order":
            if not argv:
                sub_cmd2 = "show"
            else:
                sub_cmd2 = argv.pop(0)

            try:
                if sub_cmd2 == "set":
                    order_command.create_with_set(lib, argv, modifiers)
                elif sub_cmd2 in ["remove", "delete"]:
                    order_rm(lib, argv, modifiers)
                elif sub_cmd2 == "show":
                    order_command.show(lib, argv, modifiers)
                else:
                    order_start(lib, [sub_cmd2] + argv, modifiers)
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint",
                                                   f"order {sub_cmd2}")
        elif sub_cmd == "ticket":
            usage_name = "ticket"
            try:
                command_map = {
                    "set": ticket_command.create_with_set,
                    "add": ticket_command.add,
                    "delete": ticket_command.remove,
                    "remove": ticket_command.remove,
                    "show": ticket_command.show,
                }
                sub_command = argv[0] if argv else "show"
                if sub_command not in command_map:
                    raise CmdLineInputError()
                usage_name = "ticket " + sub_command

                command_map[sub_command](lib, argv[1:], modifiers)
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint", usage_name)

        elif sub_cmd == "colocation":
            if not argv:
                sub_cmd2 = "show"
            else:
                sub_cmd2 = argv.pop(0)

            try:
                if sub_cmd2 == "add":
                    colocation_add(lib, argv, modifiers)
                elif sub_cmd2 in ["remove", "delete"]:
                    colocation_rm(lib, argv, modifiers)
                elif sub_cmd2 == "set":
                    colocation_command.create_with_set(lib, argv, modifiers)
                elif sub_cmd2 == "show":
                    colocation_command.show(lib, argv, modifiers)
                else:
                    raise CmdLineInputError()
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint",
                                                   f"colocation {sub_cmd2}")
        elif sub_cmd in ["remove", "delete"]:
            constraint_rm(lib, argv, modifiers)
        elif sub_cmd in ("show", "list"):
            # all these commands accept -f and --full therefore there is no
            # need to change something here
            location_show(lib, argv, modifiers)
            order_command.show(lib, argv, modifiers)
            colocation_command.show(lib, argv, modifiers)
            ticket_command.show(lib, argv, modifiers)
        elif sub_cmd == "ref":
            constraint_ref(lib, argv, modifiers)
        elif sub_cmd == "rule":
            constraint_rule(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, "constraint", sub_cmd)
예제 #3
0
def constraint_cmd(argv):
    lib = utils.get_library_wrapper()
    modificators = utils.get_modificators()
    if len(argv) == 0:
        argv = ["list"]

    sub_cmd = argv.pop(0)
    if (sub_cmd == "help"):
        usage.constraint(argv)
    elif (sub_cmd == "location"):
        if len (argv) == 0:
            sub_cmd2 = "show"
        else:
            sub_cmd2 = argv.pop(0)

        if (sub_cmd2 == "add"):
            location_add(argv)
        elif (sub_cmd2 in ["remove","delete"]):
            location_add(argv,True)
        elif (sub_cmd2 == "show"):
            location_show(argv)
        elif len(argv) >= 2:
            if argv[0] == "rule":
                location_rule([sub_cmd2] + argv)
            else:
                location_prefer([sub_cmd2] + argv)
        else:
            usage.constraint()
            sys.exit(1)
    elif (sub_cmd == "order"):
        if (len(argv) == 0):
            sub_cmd2 = "show"
        else:
            sub_cmd2 = argv.pop(0)

        if (sub_cmd2 == "set"):
            try:
                order_command.create_with_set(lib, argv, modificators)
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint", 'order set')
            except LibraryError as e:
                utils.process_library_reports(e.args)
        elif (sub_cmd2 in ["remove","delete"]):
            order_rm(argv)
        elif (sub_cmd2 == "show"):
            order_command.show(lib, argv, modificators)
        else:
            order_start([sub_cmd2] + argv)
    elif sub_cmd == "ticket":
        usage_name = "ticket"
        try:
            command_map = {
                "set": ticket_command.create_with_set,
                "add": ticket_command.add,
                "show": ticket_command.show,
            }
            sub_command = argv[0] if argv else "show"
            if sub_command not in command_map:
                raise CmdLineInputError()
            usage_name = "ticket "+sub_command

            command_map[sub_command](lib, argv[1:], modificators)
        except LibraryError as e:
            utils.process_library_reports(e.args)
        except CmdLineInputError as e:
            utils.exit_on_cmdline_input_errror(e, "constraint", usage_name)

    elif (sub_cmd == "colocation"):
        if (len(argv) == 0):
            sub_cmd2 = "show"
        else:
            sub_cmd2 = argv.pop(0)

        if (sub_cmd2 == "add"):
            colocation_add(argv)
        elif (sub_cmd2 in ["remove","delete"]):
            colocation_rm(argv)
        elif (sub_cmd2 == "set"):
            try:

                colocation_command.create_with_set(lib, argv, modificators)
            except LibraryError as e:
                utils.process_library_reports(e.args)
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint", "colocation set")
        elif (sub_cmd2 == "show"):
            colocation_command.show(lib, argv, modificators)
        else:
            usage.constraint()
            sys.exit(1)
    elif (sub_cmd in ["remove","delete"]):
        constraint_rm(argv)
    elif (sub_cmd == "show" or sub_cmd == "list"):
        location_show(argv)
        order_command.show(lib, argv, modificators)
        colocation_command.show(lib, argv, modificators)
        ticket_command.show(lib, argv, modificators)
    elif (sub_cmd == "ref"):
        constraint_ref(argv)
    elif (sub_cmd == "rule"):
        constraint_rule(argv)
    else:
        usage.constraint()
        sys.exit(1)
예제 #4
0
파일: constraint.py 프로젝트: miz-take/pcs
def constraint_cmd(argv):
    lib = utils.get_library_wrapper()
    modificators = utils.get_modificators()

    if len(argv) == 0:
        argv = ["list"]
    sub_cmd = argv.pop(0)

    try:
        if (sub_cmd == "help"):
            usage.constraint(argv)
        elif (sub_cmd == "location"):
            if len(argv) == 0:
                sub_cmd2 = "show"
            else:
                sub_cmd2 = argv.pop(0)

            if (sub_cmd2 == "add"):
                location_add(argv)
            elif (sub_cmd2 in ["remove", "delete"]):
                location_add(argv, True)
            elif (sub_cmd2 == "show"):
                location_show(argv)
            elif len(argv) >= 2:
                if argv[0] == "rule":
                    location_rule([sub_cmd2] + argv)
                else:
                    location_prefer([sub_cmd2] + argv)
            else:
                usage.constraint()
                sys.exit(1)
        elif (sub_cmd == "order"):
            if (len(argv) == 0):
                sub_cmd2 = "show"
            else:
                sub_cmd2 = argv.pop(0)

            if (sub_cmd2 == "set"):
                try:
                    order_command.create_with_set(lib, argv, modificators)
                except CmdLineInputError as e:
                    utils.exit_on_cmdline_input_errror(e, "constraint",
                                                       'order set')
                except LibraryError as e:
                    utils.process_library_reports(e.args)
            elif (sub_cmd2 in ["remove", "delete"]):
                order_rm(argv)
            elif (sub_cmd2 == "show"):
                order_command.show(lib, argv, modificators)
            else:
                order_start([sub_cmd2] + argv)
        elif sub_cmd == "ticket":
            usage_name = "ticket"
            try:
                command_map = {
                    "set": ticket_command.create_with_set,
                    "add": ticket_command.add,
                    "remove": ticket_command.remove,
                    "show": ticket_command.show,
                }
                sub_command = argv[0] if argv else "show"
                if sub_command not in command_map:
                    raise CmdLineInputError()
                usage_name = "ticket " + sub_command

                command_map[sub_command](lib, argv[1:], modificators)
            except LibraryError as e:
                utils.process_library_reports(e.args)
            except CmdLineInputError as e:
                utils.exit_on_cmdline_input_errror(e, "constraint", usage_name)

        elif (sub_cmd == "colocation"):
            if (len(argv) == 0):
                sub_cmd2 = "show"
            else:
                sub_cmd2 = argv.pop(0)

            if (sub_cmd2 == "add"):
                colocation_add(argv)
            elif (sub_cmd2 in ["remove", "delete"]):
                colocation_rm(argv)
            elif (sub_cmd2 == "set"):
                try:

                    colocation_command.create_with_set(lib, argv, modificators)
                except LibraryError as e:
                    utils.process_library_reports(e.args)
                except CmdLineInputError as e:
                    utils.exit_on_cmdline_input_errror(e, "constraint",
                                                       "colocation set")
            elif (sub_cmd2 == "show"):
                colocation_command.show(lib, argv, modificators)
            else:
                usage.constraint()
                sys.exit(1)
        elif (sub_cmd in ["remove", "delete"]):
            constraint_rm(argv)
        elif (sub_cmd == "show" or sub_cmd == "list"):
            location_show(argv)
            order_command.show(lib, argv, modificators)
            colocation_command.show(lib, argv, modificators)
            ticket_command.show(lib, argv, modificators)
        elif (sub_cmd == "ref"):
            constraint_ref(argv)
        elif (sub_cmd == "rule"):
            constraint_rule(argv)
        else:
            usage.constraint()
            sys.exit(1)
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "resource", sub_cmd)