#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import six.moves.urllib.parse as urllib_parse
import time

from salt.exceptions import CommandExecutionError
from manilang.common import send, MANILA_HEADER

@send('get', MANILA_HEADER)
def service_list(*args, **kwargs):
    """Return list of Manila services."""

    # TODO For API versions 2.6 and prior, replace services in the URLs with os-services.
    # https://developer.openstack.org/api-ref/shared-file-system/#list-services
    url = '/os-services?{}'.format(urllib_parse.urlencode(kwargs))
    return url, {}


@send('put', MANILA_HEADER)
def service_update(host, binary, action, **kwargs):
    """Enable/Disable Manila service"""

    url = '/services/{}'.format(action)
    req = {"host": host, "binary": binary}

    return url, req

def wait_for_service(cloud_name, host=None, admin_up_only=True, retries=18, timeout=10, **kwargs):
    """Ensure the service is up and running on specified host.

    :param host:           name of a host where service is running
    :param admin_up_only:  do not check status for admin disabled service
    :param timeout:        number of seconds to wait before retries
    :param retries:        number of retries
    """
    if admin_up_only:
        kwargs['status'] = 'enabled'

    kwargs['state'] = 'down'

    for _i in range(retries):

        services = service_list(cloud_name=cloud_name, **kwargs)['services']

        # You are able to wait status either certain manila-share instance by host@driver
        # or all existed instances on a node by host.
        # Also you are able to wait status of all instances from every node if you don't define host.
        if host:
           if '@' in str(host):
               down_services  = [s for s in services if host == s['host']]
           else:
               down_services = [s for s in services if host == s['host'].split('@')[0]]
        else:
            down_services = [s for s in services]

        if len(down_services) == 0:
            return 'Manila services with admin_up_only={} are up or disabled administratively'.format(admin_up_only)
        time.sleep(timeout)

    raise CommandExecutionError("Manila services {} are still down or disabled".format(down_services))
