Coverage for manila/scheduler/drivers/base.py: 72%
47 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2010 OpenStack, LLC.
2# Copyright 2010 United States Government as represented by the
3# Administrator of the National Aeronautics and Space Administration.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
18"""
19Scheduler base class that all Schedulers should inherit from
20"""
22from oslo_config import cfg
23from oslo_utils import importutils
24from oslo_utils import timeutils
26from manila import db
27from manila.i18n import _
28from manila.share import rpcapi as share_rpcapi
29from manila import utils
31scheduler_driver_opts = [
32 cfg.StrOpt('scheduler_host_manager',
33 default='manila.scheduler.host_manager.HostManager',
34 help='The scheduler host manager class to use.'),
35 cfg.IntOpt('scheduler_max_attempts',
36 default=3,
37 help='Maximum number of attempts to schedule a share.'),
38]
40CONF = cfg.CONF
41CONF.register_opts(scheduler_driver_opts)
44def share_update_db(context, share_id, host):
45 '''Set the host and set the scheduled_at field of a share.
47 :returns: A Share with the updated fields set properly.
48 '''
49 now = timeutils.utcnow()
50 values = {'host': host, 'scheduled_at': now}
51 return db.share_update(context, share_id, values)
54def share_replica_update_db(context, share_replica_id, host):
55 """Set the host and the scheduled_at field of a share replica.
57 :returns: A Share Replica with the updated fields set.
58 """
59 now = timeutils.utcnow()
60 values = {'host': host, 'scheduled_at': now}
61 return db.share_replica_update(context, share_replica_id, values)
64def share_group_update_db(context, share_group_id, host):
65 '''Set the host and set the updated_at field of a share group.
67 :returns: A share group with the updated fields set properly.
68 '''
69 now = timeutils.utcnow()
70 values = {'host': host, 'updated_at': now}
71 return db.share_group_update(context, share_group_id, values)
74class Scheduler(object):
75 """The base class that all Scheduler classes should inherit from."""
77 def __init__(self):
78 self.host_manager = importutils.import_object(
79 CONF.scheduler_host_manager)
80 self.share_rpcapi = share_rpcapi.ShareAPI()
82 def get_host_list(self):
83 """Get a list of hosts from the HostManager."""
84 return self.host_manager.get_host_list()
86 def get_service_capabilities(self):
87 """Get the normalized set of capabilities for the services."""
88 return self.host_manager.get_service_capabilities()
90 def update_service_capabilities(self, service_name, host,
91 capabilities, timestamp):
92 """Process a capability update from a service node."""
93 self.host_manager.update_service_capabilities(service_name,
94 host,
95 capabilities,
96 timestamp)
98 def hosts_up(self, context, topic):
99 """Return the list of hosts that have a running service for topic."""
101 services = db.service_get_all_by_topic(context, topic)
102 return [service['host']
103 for service in services
104 if utils.service_is_up(service)]
106 def schedule(self, context, topic, method, *_args, **_kwargs):
107 """Must override schedule method for scheduler to work."""
108 raise NotImplementedError(_("Must implement a fallback schedule"))
110 def schedule_create_share(self, context, request_spec, filter_properties):
111 """Must override schedule method for scheduler to work."""
112 raise NotImplementedError(_("Must implement schedule_create_share"))
114 def schedule_create_share_group(self, context, share_group_id,
115 request_spec,
116 filter_properties):
117 """Must override schedule method for scheduler to work."""
118 raise NotImplementedError(_(
119 "Must implement schedule_create_share_group"))
121 def get_pools(self, context, filters):
122 """Must override schedule method for scheduler to work."""
123 raise NotImplementedError(_("Must implement get_pools"))
125 def host_passes_filters(self, context, host, request_spec,
126 filter_properties):
127 """Must override schedule method for migration to work."""
128 raise NotImplementedError(_("Must implement host_passes_filters"))
130 def schedule_create_replica(self, context, request_spec,
131 filter_properties):
132 """Must override schedule method for create replica to work."""
133 raise NotImplementedError(_("Must implement schedule_create_replica"))