コード例 #1
0
ファイル: Package.py プロジェクト: psbanka/bombardier
    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        if len(command_line) < 2:
            raise CommandError("Incomplete command.")
        package_name = self.check_package_name(command_line)
        if len(command_line) == 2:
            system_state.push_prompt(["package", package_name])
            return OK, []

        command = command_line[2].lower()

        if command == "show":
            return Show.Package().cmd(["show", "package", package_name], 0)

        if command == "edit":
            return Edit.Package().cmd(["edit", "package", package_name], 0)

        if command == "build":
            svn_password = ''
            svn_user = libUi.get_default("svn user", '')
            if svn_user:
                svn_password = libUi.pwd_input("svn password: ")
            try:
                cnm = system_state.cnm_connector
                return cnm.package_build_job(package_name, svn_user,
                                             svn_password, command_line.bg_flag)
            except MachineTraceback, m_err:
                libUi.process_traceback(m_err)
                return FAIL, []
コード例 #2
0
ファイル: User.py プロジェクト: psbanka/bombardier
    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        status = OK
        output = []

        if len(command_line) < 2:
            raise CommandError("Incomplete command.")
        user_name = self.check_user_name(command_line)
        if len(command_line) == 2:
            system_state.push_prompt(["user", user_name])
        else:
            command = command_line[2].lower()

            if command == "edit":
                status, output = Edit.User().cmd(["edit", "user", user_name], 0)

            elif command == "set-password":
                password = libUi.pwd_input("password for %s: " % user_name)
                try:
                    status, output = system_state.cnm_connector.set_password(user_name, password)
                except MachineTraceback, m_err:
                    libUi.process_traceback(m_err)
                    status = FAIL

            elif command == "delete":
                if system_state.username == user_name:
                    status = FAIL
                    output = ["Cannot delete your own user object."]
                else:
                    prompt = 'Delete user "%s" -- are you sure' % user_name
                    if libUi.ask_yes_no(prompt, libUi.NO) == libUi.NO:
                        status = FAIL
                        output = ["Aborted"]
                    try:
                        return system_state.cnm_connector.delete_user(user_name)
                    except MachineTraceback, m_err:
                        libUi.process_traceback(m_err)
                        status = FAIL
コード例 #3
0
ファイル: Machine.py プロジェクト: psbanka/bombardier
    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        if len(command_line) < 2:
            raise CommandError("Incomplete command.")
        machine_name = check_machine_name(command_line)
        if len(command_line) == 2:
            system_state.push_prompt(["machine", machine_name])
            return OK, []

        command = command_line[2].lower()
        bg_flag = command_line.bg_flag
        if command == "ssh":
            command_string = "ssh %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Ssh().cmd(command_line)

        cnm = system_state.cnm_connector
        try:
            if command == "push":
                return cnm.push_machine_config(machine_name, bg_flag)
            elif command == "unpush":
                return cnm.unpush_machine_config(machine_name, bg_flag)
            elif command in ["install", "uninstall", "verify",
                             "configure", "execute", "purge", "fix",
                             "backup", "restore"]:
                argument = ''
                if command == "restore":
                    if len(command_line) != 5:
                        msg = "Incomplete command; require a restore target"
                        raise CommandError(msg)
                    argument = command_line[4]
                if command == "execute":
                    if len(command_line) != 5:
                        msg = "Incomplete command; require a package name "\
                              "and a command."
                        raise CommandError(msg)
                    command = command_line[4]
                if len(command_line) <= 3:
                    msg = "Incomplete command; require a package name."
                    raise CommandError(msg)
                package_name = command_line[3]
                return cnm.package_command(command, machine_name, package_name,
                                           argument, bg_flag)
            elif command in [ "enable", "setup" ]:
                prompt = "%s administrative ssh password: "******"enable":
                    return cnm.enable_command(machine_name, password, bg_flag)
                else:
                    return cnm.setup_command(machine_name, password, bg_flag)
            elif command == [ "disable" ]:
                post_data = {"yaml": yaml.dump( {"machine_type": BDR_CLIENT_TYPE })}
                return cnm.machine_job(machine_name, "disable", bg_flag, post_data)
            elif command == "dist":
                if len(command_line) <= 3:
                    msg = "Incomplete command; requires a dist file name."
                    raise CommandError(msg)
                dist_name = command_line[-1]
                return cnm.dist_command(machine_name, dist_name, bg_flag)
            elif command in ['test', 'init', 'reconcile', 'check-status']:
                return cnm.machine_job(machine_name, command, bg_flag)
            else:
                raise CommandError("%s is not a valid command" % command)
        except MachineTraceback, m_err:
            libUi.process_traceback(m_err)
            return FAIL, []