from designatev2.lists import status_list
from salt.exceptions import CommandExecutionError
import datetime
import time


def wait_for_services(cloud_name, host, service=None, retries=18, timeout=10, time_delta=5):
    """Ensure the service is up and running on specified host.
    :example:              salt-call designatev2.wait_for_services admin_identity host=cfg01 service=mdns
    :param host:           name of a host where service is running
    :param service:        name of the service (by default designate)
    :param timeout:        number of seconds to wait before retries
    :param retries:        number of retries
    :time_delta:           time interval that can be between the request and service response
    """

    for _i in range(retries):
        time_actual = datetime.datetime.now()
        services = status_list(cloud_name=cloud_name)['service_statuses']
        service_list = []
        service_active = []

        for s in services:
            if s['hostname'] == host:
                service_list.append(s['service_name'])

        for s in services:
            updated_at = datetime.datetime.strptime(s['updated_at'], '%Y-%m-%dT%H:%M:%S.%f')
            time_diff = abs((time_actual - updated_at).total_seconds()) <= time_delta
            service_name = s['service_name']

            if s['hostname'] == host and time_diff:
                if service is None:
                    service_active.append(s['service_name'])
                else:
                    if service_name == service:
                        return 'Designate-%s service are UP' % (service)
            elif service_name == service and not time_diff:
                continue

        if len(service_list) == len(service_active):
            return 'All Designate services are UP'
        time.sleep(timeout)
    raise CommandExecutionError("Designate-{} services are still down".format(set(service_list) - set(service_active)))
