def fail_hosts(self, hosts_to_fail, activated_count=None):
        '''
        Flag a ``set`` of hosts as failed, error for ``config.FAIL_PERCENT``.
        '''

        if not hosts_to_fail:
            return

        activated_count = activated_count or len(self.activated_hosts)

        logger.debug('Failing hosts: {0}'.format(', '.join(
            (host.name for host in hosts_to_fail),
        )))

        # Remove the failed hosts from the inventory
        self.active_hosts -= hosts_to_fail

        # Check we're not above the fail percent
        active_hosts = self.active_hosts

        # No hosts left!
        if not active_hosts:
            raise PyinfraError('No hosts remaining!')

        if self.config.FAIL_PERCENT is not None:
            percent_failed = (
                1 - len(active_hosts) / activated_count
            ) * 100

            if percent_failed > self.config.FAIL_PERCENT:
                raise PyinfraError('Over {0}% of hosts failed ({1}%)'.format(
                    self.config.FAIL_PERCENT,
                    int(round(percent_failed)),
                ))
def fail_hosts ( self , hosts_to_fail , activated_count = None ) : if not hosts_to_fail : return activated_count = activated_count or len ( self . activated_hosts ) logger . debug ( 'Failing hosts: {0}' . format ( ', ' . join ( ( host . name for host in hosts_to_fail ) , ) ) ) self . active_hosts -= hosts_to_fail active_hosts = self . active_hosts if not active_hosts : raise PyinfraError ( 'No hosts remaining!' ) if self . config . FAIL_PERCENT is not None : percent_failed = ( 1 - len ( active_hosts ) / activated_count ) * 100 if percent_failed > self . config . FAIL_PERCENT : raise PyinfraError ( 'Over {0}% of hosts failed ({1}%)' . format ( self . config . FAIL_PERCENT , int ( round ( percent_failed ) ) , ) )
Flag a ``set`` of hosts as failed, error for ``config.FAIL_PERCENT``.