From f268af945f82c212864fe6a11f922b11d56d02a0 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 4 Jan 2016 12:01:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dweb=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=B2=A1=E6=9C=89=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_websocket.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/run_websocket.py b/run_websocket.py index 4a1a185dc..ec6b2f73f 100755 --- a/run_websocket.py +++ b/run_websocket.py @@ -230,15 +230,14 @@ class ExecHandler(tornado.websocket.WebSocketHandler): def on_message(self, message): data = json.loads(message) pattern = data.get('pattern', '') - command = data.get('command', '') - asset_name_str = '' - if pattern and command: + self.command = data.get('command', '') + self.asset_name_str = '' + if pattern and self.command: for inv in self.runner.inventory.get_hosts(pattern=pattern): - asset_name_str += '%s ' % inv.name - self.write_message('匹配主机: ' + asset_name_str) - self.write_message('Ansible> %s\n\n' % command) - self.__class__.tasks.append(MyThread(target=self.run_cmd, args=(command, pattern))) - ExecLog(host=asset_name_str, cmd=command, user=self.user.username, remote_ip=self.remote_ip).save() + self.asset_name_str += '%s ' % inv.name + self.write_message('匹配主机: ' + self.asset_name_str) + self.write_message('Ansible> %s\n\n' % self.command) + self.__class__.tasks.append(MyThread(target=self.run_cmd, args=(self.command, pattern))) for t in self.__class__.tasks: if t.is_alive(): @@ -251,11 +250,12 @@ class ExecHandler(tornado.websocket.WebSocketHandler): def run_cmd(self, command, pattern): self.runner.run('shell', command, pattern=pattern) + ExecLog(host=self.asset_name_str, cmd=self.command, user=self.user.username, + remote_ip=self.remote_ip, result=self.runner.results).save() newline_pattern = re.compile(r'\n') for k, v in self.runner.results.items(): for host, output in v.items(): output = newline_pattern.sub('
', output) - logger.debug(output) if k == 'ok': header = "[ %s => %s]\n" % (host, 'Ok') else: