def execute_ (self, arguments) : self.enforce_length (arguments, 1) machine = self.enforce_select_machine (arguments[0]) exit_code = self.execute_ssh (ProcessModes.NullWithStdoutToStderrText, machine.host, machine.user, 'test', '!', '-d', machine.store) if not exit_code == 0 : return Outcomes.Failure ('store already exists; aborting.') exit_code = self.execute_ssh (ProcessModes.NullWithStdoutToStderrText, machine.host, machine.user, 'mkdir', '-p', machine.store) if not exit_code == 0 : return Outcomes.Failure ('store can not be created; aborting.') tar_process = self.start_local (ProcessModes.PipedBinary, 'tar', '-c', './sources') tar_process.output_stream.close () untar_process = self.start_ssh (ProcessModes.PipedBinary, machine.host, machine.user, 'tar', '-x', '-C', machine.store) untar_process.input_stream.close () while True : buffer = tar_process.input_stream.read (1024) if buffer == '' : break untar_process.output_stream.write (buffer) untar_process.output_stream.flush () tar_process.join () untar_process.join () frontend = Frontend (machine.host, machine.user, machine.store) return frontend.execute ('deploy-machine', [])
def ping_backend (self, machine) : frontend = Frontend (machine.host, machine.user, machine.store) frontend.start () frontend.output ('ping') outcome = frontend.input () if outcome == 'pong' : frontend.output ('exit') exit_code = frontend.join () elif outcome == Frontend.End : self.error.outputf ('remote closed.') exit_code = frontend.join () else : self.error.outputf ('remote did not pong-ed.') exit_code = frontend.join () if exit_code is None : return Outcomes.Failure ('remote terminated.') elif not exit_code == 0 : return Outcomes.Failure ('remote failed with exit-code %d.', exit_code) return Outcomes.Succeeded