Coverage for manila/scheduler/drivers/simple.py: 98%

33 statements  

« 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. 

17 

18""" 

19Simple Scheduler 

20""" 

21 

22from oslo_config import cfg 

23 

24from manila import db 

25from manila import exception 

26from manila.i18n import _ 

27from manila.scheduler.drivers import base 

28from manila.scheduler.drivers import chance 

29from manila import utils 

30 

31simple_scheduler_opts = [ 

32 cfg.IntOpt("max_gigabytes", 

33 default=10000, 

34 help="Maximum number of volume gigabytes to allow per host."), ] 

35 

36CONF = cfg.CONF 

37CONF.register_opts(simple_scheduler_opts) 

38 

39 

40class SimpleScheduler(chance.ChanceScheduler): 

41 """Implements Naive Scheduler that tries to find least loaded host.""" 

42 

43 def schedule_create_share(self, context, request_spec, filter_properties): 

44 """Picks a host that is up and has the fewest shares.""" 

45 # TODO(rushiagr) - pick only hosts that run shares 

46 elevated = context.elevated() 

47 

48 share_id = request_spec.get('share_id') 

49 snapshot_id = request_spec.get('snapshot_id') 

50 share_properties = request_spec.get('share_properties') 

51 share_size = share_properties.get('size') 

52 

53 instance_properties = request_spec.get('share_instance_properties', {}) 

54 availability_zone_id = instance_properties.get('availability_zone_id') 

55 

56 results = db.service_get_all_share_sorted(elevated) 

57 if availability_zone_id: 

58 results = [(service_g, gigs) for (service_g, gigs) in results 

59 if (service_g['availability_zone_id'] 

60 == availability_zone_id)] 

61 for result in results: 

62 (service, share_gigabytes) = result 

63 if share_gigabytes + share_size > CONF.max_gigabytes: 

64 msg = _("Not enough allocatable share gigabytes remaining") 

65 raise exception.NoValidHost(reason=msg) 

66 if utils.service_is_up(service) and not service['disabled']: 66 ↛ 61line 66 didn't jump to line 61 because the condition on line 66 was always true

67 updated_share = base.share_update_db(context, 

68 share_id, 

69 service['host']) 

70 self.share_rpcapi.create_share_instance( 

71 context, 

72 updated_share.instance, 

73 service['host'], 

74 request_spec, 

75 None, 

76 snapshot_id=snapshot_id) 

77 return None 

78 msg = _("Is the appropriate service running?") 

79 raise exception.NoValidHost(reason=msg)