Beispiel #1
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)
Beispiel #2
0
     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)
 except MachineStatusException, err:
     output = ["ERROR: Machine status is incomplete"]
     output.append(str(err))
     libUi.user_output(output, FAIL)
 except exceptions.SystemExit:
     # if system_state.comment_commands:
     # makeComment()
     sys.exit(0)
 except CommandError, err:
     system_state.fp_out.write("\n %% %s\n\n" % err)
 except ServerTracebackException, err:
     msg = " %% There was a problem on the server:"
     system_state.fp_err.write(msg)
     for line in err.traceback:
         system_state.fp_err.write("  %%%% %s" % line)
         system_state.fp_err.write("\n")
 except Exception, err:
     msg = " %%%% Error detected in %s (%s)." % (command_string, err)
     system_state.fp_err.write(msg)
Beispiel #3
0
    def watch_jobs(self, job_names):
        "Given a list of jobs, watch their progress."
        summary_output = []
        summary_status = OK
        jobs = set(job_names)
        try:
            while job_names:
                jobs = jobs.union(job_names)
                time.sleep(0.25)
                url = "json/job/poll/"
                post_data = {"yaml": yaml.dump({"job_names": job_names})}
                output = self.service_yaml_request(url, post_data=post_data)
                if type(output) != type({}):
                    msg = "Request to %s returned and invalid type (%s)"
                    libUi.error(msg % (url, output))
                    return FAIL, output
                for job_name in output:
                    job_output = output[job_name]
                    if "traceback" in job_output:
                        raise MachineTraceback(url, job_output["traceback"])
                    new_output = job_output.get("new_output", '')
                    if new_output:
                        libUi.process_cnm(new_output)
                    alive = job_output.get("alive")
                    if alive == None:
                        if job_output.get("command_status") == "QUEUED":
                            pending_job = job_output.get("pending_job")
                            msg = "%s is pending %s." % (job_name, pending_job)
                            libUi.warning(msg)
                            libUi.info("Watching %s..." % pending_job)
                            job_names = [pending_job]
                            break
                    if alive == False:
                        out = system_state.cnm_connector.join_job(job_name)
                        summary_output.append(out.get("command_output"))
                        status = out.get("command_status", OK)
                        if status != OK:
                            summary_status = FAIL
                        job_names +=  out.get("children", [])
                        job_names.remove(job_name)
                        comments = out.get("jobs_requiring_comment", 0)
                        if comments:
                            system_state.comment_counter = len(comments)
        except exceptions.KeyboardInterrupt:
            term = libUi.ask_yes_no("Terminate job", libUi.YES)
            if term == libUi.NO:
                msg = ["Disconnected from %s" % job_names,
                       "To re-connect, use 'job view'"]
                return OK, msg
            else:
                matcher = re.compile("(\S+)@(\S+)\-(\d+)")
                machine_names = set()
                for job_name in job_names:
                    _user, machine_name, _counter = matcher.findall(job_name)[0]
                    machine_names.update([machine_name])
                output = {}
                for machine_name in machine_names:
                    _status, output = self.stop_jobs(machine_name)
                    print ">>> Halting all jobs on %s..." % machine_name
                    libUi.user_output(output, FAIL)
                raise exceptions.KeyboardInterrupt

        libUi.info("Finishing processing of %d jobs..." % len(jobs))
        return summary_status, summary_output