示例#1
0
文件: pause.py 项目: nengxu/ansible
    def run(self, conn, tmp, module_name, module_args, inject):
        ''' run the pause actionmodule '''
        args = self.runner.module_args
        hosts = ', '.join(map(lambda x: x[1], self.runner.host_set))

        (self.pause_type, sep, pause_params) = args.partition('=')

        if self.pause_type == '':
            self.pause_type = 'prompt'
        elif not self.pause_type in self.PAUSE_TYPES:
            raise ae("invalid parameter for pause, '%s'. must be one of: %s" % \
                         (self.pause_type, ", ".join(self.PAUSE_TYPES)))

        # error checking
        if self.pause_type in ['minutes', 'seconds']:
            try:
                int(pause_params)
            except ValueError:
                raise ae("value given to %s parameter invalid: '%s', must be an integer" % \
                             self.pause_type, pause_params)

        # The time() command operates in seconds so we need to
        # recalculate for minutes=X values.
        if self.pause_type == 'minutes':
            self.seconds = int(pause_params) * 60
        elif self.pause_type == 'seconds':
            self.seconds = int(pause_params)
            self.duration_unit = 'seconds'
        else:
            # if no args are given we pause with a prompt
            if pause_params == '':
                self.prompt = "[%s]\nPress enter to continue: " % hosts
            else:
                self.prompt = "[%s]\n%s: " % (hosts, pause_params)

        vv("created 'pause' ActionModule: pause_type=%s, duration_unit=%s, calculated_seconds=%s, prompt=%s" % \
                (self.pause_type, self.duration_unit, self.seconds, self.prompt))

        try:
            self._start()
            if not self.pause_type == 'prompt':
                print "[%s]\nPausing for %s seconds" % (hosts, self.seconds)
                time.sleep(self.seconds)
            else:
                # Clear out any unflushed buffered input which would
                # otherwise be consumed by raw_input() prematurely.
                tcflush(sys.stdin, TCIFLUSH)
                raw_input(self.prompt)
        except KeyboardInterrupt:
            while True:
                print '\nAction? (a)bort/(c)ontinue: '
                c = getch()
                if c == 'c':
                    # continue playbook evaluation
                    break
                elif c == 'a':
                    # abort further playbook evaluation
                    raise ae('user requested abort!')
        finally:
            self._stop()

        return ReturnData(conn=conn, result=self.result)
示例#2
0
        # Begin the hard work!
        try:
            self._start()
            if not self.pause_type == 'prompt':
                print "[%s]\nPausing for %s seconds" % (hosts, self.seconds)
                time.sleep(self.seconds)
            else:
                # Clear out any unflushed buffered input which would
                # otherwise be consumed by raw_input() prematurely.
                tcflush(sys.stdin, TCIFLUSH)
                self.result['user_input'] = raw_input(
                    self.prompt.encode(sys.stdout.encoding))
        except KeyboardInterrupt:
            while True:
                print '\nAction? (a)bort/(c)ontinue: '
                c = getch()
                if c == 'c':
                    # continue playbook evaluation
                    break
                elif c == 'a':
                    # abort further playbook evaluation
                    raise ae('user requested abort!')
        finally:
            self._stop()

        return ReturnData(conn=conn, result=self.result)

    def _start(self):
        ''' mark the time of execution for duration calculations later '''
        self.start = time.time()
        self.result['start'] = str(datetime.datetime.now())
示例#3
0
        ########################################################################
        # Begin the hard work!
        try:
            self._start()
            if not self.pause_type == 'prompt':
                print "[%s]\nPausing for %s seconds" % (hosts, self.seconds)
                time.sleep(self.seconds)
            else:
                # Clear out any unflushed buffered input which would
                # otherwise be consumed by raw_input() prematurely.
                tcflush(sys.stdin, TCIFLUSH)
                self.result['user_input'] = raw_input(self.prompt.encode(sys.stdout.encoding))
        except KeyboardInterrupt:
            while True:
                print '\nAction? (a)bort/(c)ontinue: '
                c = getch()
                if c == 'c':
                    # continue playbook evaluation
                    break
                elif c == 'a':
                    # abort further playbook evaluation
                    raise ae('user requested abort!')
        finally:
            self._stop()

        return ReturnData(conn=conn, result=self.result)

    def _start(self):
        ''' mark the time of execution for duration calculations later '''
        self.start = time.time()
        self.result['start'] = str(datetime.datetime.now())
示例#4
0
文件: pause.py 项目: broferek/ansible
    def run(self, conn, tmp, module_name, module_args, inject):
        ''' run the pause actionmodule '''
        args = self.runner.module_args
        hosts = ', '.join(map(lambda x: x[1], self.runner.host_set))

        (self.pause_type, sep, pause_params) = args.partition('=')

        if self.pause_type == '':
            self.pause_type = 'prompt'
        elif not self.pause_type in self.PAUSE_TYPES:
            raise ae("invalid parameter for pause, '%s'. must be one of: %s" % \
                         (self.pause_type, ", ".join(self.PAUSE_TYPES)))

        # error checking
        if self.pause_type in ['minutes', 'seconds']:
            try:
                int(pause_params)
            except ValueError:
                raise ae("value given to %s parameter invalid: '%s', must be an integer" % \
                             self.pause_type, pause_params)

        # The time() command operates in seconds so we need to
        # recalculate for minutes=X values.
        if self.pause_type == 'minutes':
            self.seconds = int(pause_params) * 60
        elif self.pause_type == 'seconds':
            self.seconds = int(pause_params)
            self.duration_unit = 'seconds'
        else:
            # if no args are given we pause with a prompt
            if pause_params == '':
                self.prompt = "[%s]\nPress enter to continue: " % hosts
            else:
                self.prompt = "[%s]\n%s: " % (hosts, pause_params)

        vv("created 'pause' ActionModule: pause_type=%s, duration_unit=%s, calculated_seconds=%s, prompt=%s" % \
                (self.pause_type, self.duration_unit, self.seconds, self.prompt))

        try:
            self._start()
            if not self.pause_type == 'prompt':
                print "[%s]\nPausing for %s seconds" % (hosts, self.seconds)
                time.sleep(self.seconds)
            else:
                # Clear out any unflushed buffered input which would
                # otherwise be consumed by raw_input() prematurely.
                tcflush(sys.stdin, TCIFLUSH)
                raw_input(self.prompt)
        except KeyboardInterrupt:
            while True:
                print '\nAction? (a)bort/(c)ontinue: '
                c = getch()
                if c == 'c':
                    # continue playbook evaluation
                    break
                elif c == 'a':
                    # abort further playbook evaluation
                    raise ae('user requested abort!')
        finally:
            self._stop()

        return ReturnData(conn=conn, result=self.result)