12
12
# License for the specific language governing permissions and limitations
13
13
# under the License.
14
14
15
+ import typing as ty
15
16
16
17
import os_resource_classes as orc
17
18
from oslo_limit import exception as limit_exceptions
39
40
}
40
41
41
42
42
- def _get_placement_usages (context , project_id ):
43
+ def _get_placement_usages (
44
+ context : 'nova.context.RequestContext' , project_id : str
45
+ ) -> ty .Dict [str , int ]:
43
46
global PLACEMENT_CLIENT
44
47
if not PLACEMENT_CLIENT :
45
48
PLACEMENT_CLIENT = report .SchedulerReportClient ()
46
49
return PLACEMENT_CLIENT .get_usages_counts_for_limits (context , project_id )
47
50
48
51
49
- def _get_usage (context , project_id , resource_names ):
52
+ def _get_usage (
53
+ context : 'nova.context.RequestContext' ,
54
+ project_id : str ,
55
+ resource_names : ty .List [str ],
56
+ ) -> ty .Dict [str , int ]:
50
57
"""Called by oslo_limit's enforcer"""
51
58
if not limit_utils .use_unified_limits ():
52
- raise NotImplementedError ("unified limits is disabled" )
59
+ raise NotImplementedError ("Unified limits support is disabled" )
53
60
54
61
count_servers = False
55
62
resource_classes = []
@@ -113,7 +120,9 @@ def _get_usage(context, project_id, resource_names):
113
120
return resource_counts
114
121
115
122
116
- def _get_deltas_by_flavor (flavor , is_bfv , count ):
123
+ def _get_deltas_by_flavor (
124
+ flavor : 'objects.Flavor' , is_bfv : bool , count : int
125
+ ) -> ty .Dict [str , int ]:
117
126
if flavor is None :
118
127
raise ValueError ("flavor" )
119
128
if count < 0 :
@@ -132,16 +141,25 @@ def _get_deltas_by_flavor(flavor, is_bfv, count):
132
141
return deltas
133
142
134
143
135
- def _get_enforcer (context , project_id ):
144
+ def _get_enforcer (
145
+ context : 'nova.context.RequestContext' , project_id : str
146
+ ) -> limit .Enforcer :
136
147
# NOTE(johngarbutt) should we move context arg into oslo.limit?
137
148
def callback (project_id , resource_names ):
138
149
return _get_usage (context , project_id , resource_names )
139
150
140
151
return limit .Enforcer (callback )
141
152
142
153
143
- def enforce_num_instances_and_flavor (context , project_id , flavor , is_bfvm ,
144
- min_count , max_count , enforcer = None ):
154
+ def enforce_num_instances_and_flavor (
155
+ context : 'nova.context.RequestContext' ,
156
+ project_id : str ,
157
+ flavor : 'objects.Flavor' ,
158
+ is_bfvm : bool ,
159
+ min_count : int ,
160
+ max_count : int ,
161
+ enforcer : ty .Optional [limit .Enforcer ] = None
162
+ ) -> int :
145
163
"""Return max instances possible, else raise TooManyInstances exception."""
146
164
if not limit_utils .use_unified_limits ():
147
165
return max_count
0 commit comments