示例#1
0
    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        machine_name = check_machine_name(command_line)

        if len(command_line) == 3 or command_line[3] == "config":
            command_string = "edit machine %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Edit.Machine().cmd(command_line)

        command = command_line[3]
        if len(command_line) != 5:
            msg = "Incomplete command; need to include %s name." % command
            raise CommandError(msg)

        object_name = command_line[4]

        if command == "bom":
            command_string = "edit bom %s" % object_name
            command_line = CommandLine.process_input(command_string)
            return Edit.Bom().cmd(command_line)
        elif command == "include":
            command_string = "edit include %s" % object_name
            command_line = CommandLine.process_input(command_string)
            return Edit.Include().cmd(command_line)

        raise CommandError("Unknown command: %s" % command)
示例#2
0
 def complete(self, _text, status):
     """Command line completer, called with [tab] or [?]
     _text -- text that readline sends as what the user enters
     status -- the index into the completion list"""
     try:
         if status > 0:
             if status >= len(self.names):
                 return None
             return self.names[status]
         else:
             # _no_flag, help_flag, tokens, _comment = \
             command_line = CommandLine.process_input(readline.get_line_buffer())
             command_line.update_system_tokens()
             if command_line.help_flag:  # Process the [?] key first
                 self.find_help(command_line, 0)
                 sys.stdout.write("%s%s" % (system_state.get_prompt(), readline.get_line_buffer()))
                 sys.stdout.flush()
                 return []
             names, token_delimeter = self.get_names_and_token_delimeter(command_line)
             self.names = names
             if not self.names:
                 return []
             if len(self.names) == 1:
                 return self.names[0] + token_delimeter
             if self.names:
                 return self.names[0]
             return []
     except StandardError, err:
         sys.stderr.write(" %%%% Error detected in %s (%s)." % (file, err))
         tb_str = StringIO.StringIO()
         traceback.print_exc(file=tb_str)
         tb_str.seek(0)
         data = tb_str.read()
         ermsg = ""
         for line in data.split("\n"):
             ermsg += "\n||>>>%s" % line
         sys.stderr.write(ermsg)
         sys.stderr.write(" %%%% Error ocurred in %s" % file)
         print
         return []
示例#3
0
 def process_command(self, command_string):
     "When somebody hits return in the shell, this method handles it."
     if command_string == "exit":
         raise EOFError
     try:
         # no_flag, help_flag, tokens, comment = libUi.process_input(command_string)
         # FIXME: nobody cares about the comment
         command_line = CommandLine.process_input(command_string)
         if command_line.is_empty():
             # somebody just pressed return for no reason
             return OK, []
         command_line.update_system_tokens()
         status, output = self.run(command_line)
         libUi.user_output(output, status)
         return status, output
     except ServerException, err:
         if err.http_code == 403:
             msg = ["You are not authorized for this command."]
             libUi.user_output(msg, FAIL)
             return FAIL, msg
         output = ["ERROR: Cannot communicate with CNM Server"]
         output.append(str(err))
         libUi.user_output(output, FAIL)
示例#4
0
    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        machine_name = check_machine_name(command_line)

        if len(command_line) == 3 or command_line[3] == "config":
            command_string = "show machine %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Show.Machine().cmd(command_line)

        command = command_line[3]
        if command == "merged":
            command_string = "show merged %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Show.Merged().cmd(command_line)
        elif command == "status":
            command_string = "show status %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Show.Status().cmd(command_line)
        elif command == "summary":
            command_string = "show summary %s" % machine_name
            command_line = CommandLine.process_input(command_string)
            return Show.Summary().cmd(command_line)

        if len(command_line) != 5:
            msg = "Incomplete command; need to include %s name." % command
            raise CommandError(msg)

        object_name = command_line[4]

        if command == "bom":
            command_string = "show bom %s" % object_name
            command_line = CommandLine.process_input(command_string)
            return Show.Bom().cmd(command_line)
        elif command == "include":
            command_string = "show include %s" % object_name
            command_line = CommandLine.process_input(command_string)
            return Show.Include().cmd(command_line)

        raise CommandError("Unknown command: %s" % command)
示例#5
0
    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, []