blob: ded8e9561b24ff3c35aab913b7c98c01a47cc100 [file] [log] [blame]
# 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))