Coverage for manila/scheduler/rpcapi.py: 100%

42 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2012, Red Hat, Inc. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15""" 

16Client side of the scheduler manager RPC API. 

17""" 

18 

19from oslo_config import cfg 

20import oslo_messaging as messaging 

21from oslo_serialization import jsonutils 

22from oslo_utils import timeutils 

23 

24from manila import rpc 

25 

26CONF = cfg.CONF 

27 

28 

29class SchedulerAPI(object): 

30 """Client side of the scheduler rpc API. 

31 

32 API version history: 

33 

34 1.0 - Initial version. 

35 1.1 - Add get_pools method 

36 1.2 - Introduce Share Instances. Replace ``create_share()`` with 

37 ``create_share_instance()`` 

38 1.3 - Add create_consistency_group method (renamed in 1.7) 

39 1.4 - Add migrate_share_to_host method 

40 1.5 - Add create_share_replica 

41 1.6 - Add manage_share 

42 1.7 - Updated migrate_share_to_host method with new parameters 

43 1.8 - Rename create_consistency_group -> create_share_group method 

44 1.9 - Add cached parameter to get_pools method 

45 1.10 - Add timestamp to update_service_capabilities 

46 1.11 - Add extend_share 

47 """ 

48 

49 RPC_API_VERSION = '1.11' 

50 

51 def __init__(self): 

52 super(SchedulerAPI, self).__init__() 

53 target = messaging.Target(topic=CONF.scheduler_topic, 

54 version=self.RPC_API_VERSION) 

55 self.client = rpc.get_client(target, version_cap=self.RPC_API_VERSION) 

56 

57 def create_share_instance(self, context, request_spec=None, 

58 filter_properties=None): 

59 request_spec_p = jsonutils.to_primitive(request_spec) 

60 call_context = self.client.prepare(version='1.2') 

61 return call_context.cast(context, 

62 'create_share_instance', 

63 request_spec=request_spec_p, 

64 filter_properties=filter_properties) 

65 

66 def update_service_capabilities(self, context, 

67 service_name, host, 

68 capabilities): 

69 call_context = self.client.prepare(fanout=True, version='1.10') 

70 timestamp = jsonutils.to_primitive(timeutils.utcnow()) 

71 call_context.cast(context, 

72 'update_service_capabilities', 

73 service_name=service_name, 

74 host=host, 

75 capabilities=capabilities, 

76 timestamp=timestamp) 

77 

78 def get_pools(self, context, filters=None, cached=False): 

79 call_context = self.client.prepare(version='1.9') 

80 return call_context.call(context, 'get_pools', filters=filters, 

81 cached=cached) 

82 

83 def create_share_group(self, context, share_group_id, request_spec=None, 

84 filter_properties=None): 

85 """Casts an rpc to the scheduler to create a share group. 

86 

87 Example of 'request_spec' argument value:: 

88 

89 { 

90 

91 'share_group_type_id': 'fake_share_group_type_id', 

92 'share_group_id': 'some_fake_uuid', 

93 'availability_zone_id': 'some_fake_az_uuid', 

94 'share_types': [models.ShareType], 

95 'resource_type': models.ShareGroup, 

96 

97 } 

98 

99 """ 

100 request_spec_p = jsonutils.to_primitive(request_spec) 

101 call_context = self.client.prepare(version='1.8') 

102 return call_context.cast(context, 

103 'create_share_group', 

104 share_group_id=share_group_id, 

105 request_spec=request_spec_p, 

106 filter_properties=filter_properties) 

107 

108 def migrate_share_to_host( 

109 self, context, share_id, host, force_host_assisted_migration, 

110 preserve_metadata, writable, nondisruptive, preserve_snapshots, 

111 new_share_network_id, new_share_type_id, request_spec=None, 

112 filter_properties=None): 

113 

114 call_context = self.client.prepare(version='1.7') 

115 request_spec_p = jsonutils.to_primitive(request_spec) 

116 return call_context.cast( 

117 context, 'migrate_share_to_host', 

118 share_id=share_id, 

119 host=host, 

120 force_host_assisted_migration=force_host_assisted_migration, 

121 preserve_metadata=preserve_metadata, 

122 writable=writable, 

123 nondisruptive=nondisruptive, 

124 preserve_snapshots=preserve_snapshots, 

125 new_share_network_id=new_share_network_id, 

126 new_share_type_id=new_share_type_id, 

127 request_spec=request_spec_p, 

128 filter_properties=filter_properties) 

129 

130 def create_share_replica(self, context, request_spec=None, 

131 filter_properties=None): 

132 request_spec_p = jsonutils.to_primitive(request_spec) 

133 call_context = self.client.prepare(version='1.5') 

134 return call_context.cast(context, 

135 'create_share_replica', 

136 request_spec=request_spec_p, 

137 filter_properties=filter_properties) 

138 

139 def manage_share(self, context, share_id, driver_options, 

140 request_spec=None, filter_properties=None): 

141 

142 call_context = self.client.prepare(version='1.6') 

143 return call_context.cast(context, 'manage_share', 

144 share_id=share_id, 

145 driver_options=driver_options, 

146 request_spec=request_spec, 

147 filter_properties=filter_properties) 

148 

149 def extend_share(self, context, share_id, new_size, reservations, 

150 request_spec, filter_properties=None): 

151 call_context = self.client.prepare(version='1.11') 

152 

153 msg_args = { 

154 'share_id': share_id, 

155 'new_size': new_size, 

156 'reservations': reservations, 

157 'request_spec': request_spec, 

158 'filter_properties': filter_properties, 

159 } 

160 

161 return call_context.cast(context, 'extend_share', **msg_args)