Ejemplo n.º 1
0
    def v2_runner_on_failed(self, result, ignore_errors=False):
        from deveops.asgi import channel_layer
        message = "{host} => FAILED!\r\n".format(host=result._host.get_name())

        channel_layer.send(self.replay_name, {'text': message})
        channel_layer.send(
            self.replay_name,
            {'text': self._dump_results(result._result, indent=INDENT)})
Ejemplo n.º 2
0
 def import_task(self, play_source):
     from deveops.asgi import channel_layer
     channel_layer.send(self.replay_name, {'text': 'Load Task => '})
     print('renwu', play_source)
     for source in play_source:
         self.play.append(Play().load(
             source,
             variable_manager=self.variable_manager,
             loader=self.loader))
Ejemplo n.º 3
0
 def v2_runner_on_ok(self, result, **kwargs):
     from deveops.asgi import channel_layer
     message = "{host} => SUCCESS\r\n".format(host=result._host.get_name())
     channel_layer.send(self.replay_name, {'text': message})
     channel_layer.send(
         self.replay_name, {
             'text':
             self._dump_results(result._result, indent=INDENT).replace(
                 '\n', '\r\n') + '\r\n'
         })
Ejemplo n.º 4
0
 def v2_runner_on_unreachable(self, result):
     from deveops.asgi import channel_layer
     message = "{host} => UNREACHABLE!\r\n".format(
         host=result._host.get_name())
     channel_layer.send(self.replay_name, {'text': message})
     channel_layer.send(
         self.replay_name, {
             'text':
             self._dump_results(result._result, indent=INDENT).replace(
                 '\n', '\r\n') + '\r\n'
         })
Ejemplo n.º 5
0
    def connect(self, message, **kwargs):
        try:
            play_source, inventory, key = self.before_connect(**kwargs)
        except ObjectDoesNotExist:
            from deveops.asgi import channel_layer
            channel_layer.send(self.replay_name,
                               {'text': u'您执行的任务缺少必要的密钥或者跳板机请联系管理员解决'})
            channel_layer.send(self.replay_name, {'close': True})
            return

        threadSend = AnsibleRecvThread(play_source, inventory, key,
                                       self.message.reply_channel.name)
        threadSend.setDaemon = True
        threadSend.start()
Ejemplo n.º 6
0
 def run(self):
     self.chan.settimeout(0.0)
     while True:
         try:
             stdout = list()
             msg = u(self.chan.recv(self.CACHE))
             from deveops.asgi import channel_layer
             if len(msg) == 0:
                 continue
             if msg == "exit\r\n" or msg == "logout\r\n" or msg == 'logout': #如果exit则返回
                 self.chan.close()
             else:
                 stdout.append([codecs.getincrementaldecoder('UTF-8')('replace').decode(msg)])
             channel_layer.send(self.channel, {'text': msg })
         except socket.timeout:
             pass
         except Exception,e:
             pass
Ejemplo n.º 7
0
    def run(self):
        tqm = None
        try:
            tqm = TaskQueueManager(
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords={},
                stdout_callback=self.stdout_callback
            )

            from deveops.asgi import channel_layer
            channel_layer.send(self.replay_name, {'text': 'Start => \r\n'})

            for p in self.play:
                result = tqm.run(p)
            # self.delete_key()

            channel_layer.send(self.replay_name,
                               {'text': u'执行完毕\r\n'})
            channel_layer.send(self.replay_name,
                               {'close': True})
        finally:
            if tqm is not None:
                tqm.cleanup()
Ejemplo n.º 8
0
    def connect(self, message, **kwargs):
        from deveops.asgi import channel_layer
        work, play_source, inventory, key = self.before_connect(**kwargs)
        if key == None or len(play_source) == 0:
            channel_layer.send(self.message.reply_channel.name,
                               {'text': u'\r\n您执行的任务缺少必要的密钥或者跳板机请联系管理员解决'})
            channel_layer.send(self.message.reply_channel.name,
                               {'close': True})
            return
        elif work.status == 3:
            channel_layer.send(self.message.reply_channel.name,
                               {'text': u'\r\n当前工单已经执行完毕 如有需要请重新创建'})
            channel_layer.send(self.message.reply_channel.name,
                               {'close': True})
            return

        threadSend = AnsibleRecvThread(work, play_source, inventory, key,
                                       self.message.reply_channel.name)
        threadSend.setDaemon = True
        threadSend.start()