Coverage for nova/servicegroup/api.py: 100%
24 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
1# Copyright 2012 IBM Corp.
2# Copyright (c) AT&T Labs Inc. 2012 Yun Mao <yunmao@gmail.com>
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
17"""Define APIs for the servicegroup access."""
19from oslo_log import log as logging
20from oslo_utils import importutils
22import nova.conf
24LOG = logging.getLogger(__name__)
26_driver_name_class_mapping = {
27 'db': 'nova.servicegroup.drivers.db.DbDriver',
28 'mc': 'nova.servicegroup.drivers.mc.MemcachedDriver'
29}
31CONF = nova.conf.CONF
33# NOTE(geekinutah): By default drivers wait 5 seconds before reporting
34INITIAL_REPORTING_DELAY = 5
37class API(object):
39 def __init__(self, *args, **kwargs):
40 '''Create an instance of the servicegroup API.
42 args and kwargs are passed down to the servicegroup driver when it gets
43 created.
44 '''
45 # Make sure report interval is less than service down time
46 report_interval = CONF.report_interval
47 if CONF.service_down_time <= report_interval:
48 new_service_down_time = int(report_interval * 2.5)
49 LOG.warning("Report interval must be less than service down "
50 "time. Current config: <service_down_time: "
51 "%(service_down_time)s, report_interval: "
52 "%(report_interval)s>. Setting service_down_time "
53 "to: %(new_service_down_time)s",
54 {'service_down_time': CONF.service_down_time,
55 'report_interval': report_interval,
56 'new_service_down_time': new_service_down_time})
57 CONF.set_override('service_down_time', new_service_down_time)
59 driver_class = _driver_name_class_mapping[CONF.servicegroup_driver]
60 self._driver = importutils.import_object(driver_class,
61 *args, **kwargs)
63 def join(self, member, group, service=None):
64 """Add a new member to a service group.
66 :param member: the joined member ID/name
67 :param group: the group ID/name, of the joined member
68 :param service: a `nova.service.Service` object
69 """
70 return self._driver.join(member, group, service)
72 def service_is_up(self, member):
73 """Check if the given member is up."""
74 # NOTE(johngarbutt) no logging in this method,
75 # so this doesn't slow down the scheduler
76 if member.get('forced_down'):
77 return False
79 return self._driver.is_up(member)
81 def get_updated_time(self, member):
82 """Get the updated time from drivers except db"""
83 return self._driver.updated_time(member)