def run(fqdns, ip_addresses, dns, check, timer, logger):
    """
    This is the "main loop". It will repeatedly check that the machines
    pointed by the DNS records are fine.
    """
    if isinstance(fqdns, basestring):
        fqdns = [fqdns]

    if isinstance(ip_addresses, basestring):
        ip_addresses = [ip_addresses]

    logger.info('[INFO] Python-dns-failover starting')

    while True:
        now = time.time()
        nextCheck = timer.getNextCheckTime()

        # Log if checking is late
        if now > nextCheck:
            logger.warning('[WARNING] We are late by {0} seconds'
                           .format(now-nextCheck))

        # Wait until newt check time
        while time.time() < nextCheck:
            wait = nextCheck - time.time()
            logger.info('[INFO] Waiting {0} seconds before next round of '
                        'checks'
                        .format(wait))
            time.sleep(wait)

        # For each FQDN of the provided list
        for fqdn in fqdns:
            logger.debug('[DEBUG] Getting DNS records for {0}'
                         .format(fqdn))

            # Get current ip adresses records associated with the FQDN
            try:
                records = dns.get_a_records(fqdn)
            except Exception as e:
                logger.error('[ERROR] Error while retrieving DNS records for '
                             '{0}: {1}'
                             .format(fqdn, e))
                continue
            else:
                logger.debug('[DEBUG] DNS current records: {0}'
                             .format(records))

            logger.debug('[DEBUG] Checking servers')

            # For each ip address of the provided list
            for ip_addr in ip_addresses:

                # Server seems dead
                if not retryBoundedCheck(ip_addr, check, timer, logger):

                    # Server is still in the DNS
                    if ip_addr in records:

                        # Server is the last in the DNS
                        if len(records) < 2:
                            logger.error('[ERROR] Server {0} seems dead and '
                                         'it is on a DNS record for {1}, but '
                                         'it will not be removed since it is '
                                         'the last server.'
                                         .format(ip_addr, fqdn))

                        # Server is not the last. Delete it.
                        else:
                            logger.error('[ERROR] Server {0} seems dead and '
                                         'it is on a DNS record for {1}. '
                                         'Removing it.'
                                         .format(ip_addr, fqdn))
                            try:
                                n_deleted = dns.delete_a_record(fqdn, ip_addr)
                            except Exception as e:
                                logger.error('[ERROR] Error while deleting '
                                             'record {0} for {1}: {2}'
                                             .format(ip_addr, fqdn, e))
                            else:
                                logger.info('[INFO] Records targeting {0} '
                                            'were removed from the DNS ({1}).'
                                            .format(ip_addr, n_deleted))
                                # Only remove one server at a time
                                break

                    # Server not in the DNS
                    else:
                        logger.info('[INFO] Server {0} continues dead.'
                                    .format(ip_addr))

                # Server seems alive
                else:

                    # Server is already in the DNS
                    if ip_addr in records:
                        logger.info('[INFO] Server {0} seems alive and it is '
                                    'on the DNS'
                                    .format(ip_addr))

                    # Server is not in the DNS. Add it.
                    else:
                        logger.warning('[WARNING] Server {0} seems alive and '
                                       'it is not on a DNS record for {1}. '
                                       'Adding it.'
                                       .format(ip_addr, fqdn))
                        try:
                            dns.add_a_record(fqdn, ip_addr)
                        except Exception as e:
                            logger.error('[ERROR] Error while adding record '
                                         '{0} for {1}: {2}'
                                         .format(ip_addr, fqdn, e))
                        else:
                            logger.info('[INFO] Record targeting {0} was '
                                        'added to the DNS.'
                                        .format(ip_addr))
dataset/ETHPy150Open marccerrato/python-dns-failover/dns_failover/core.py/run/original