Coverage for manila/share/rpcapi.py: 91%
218 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 2012, Intel, 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.
15"""
16Client side of the share RPC API.
17"""
19from oslo_config import cfg
20import oslo_messaging as messaging
21from oslo_serialization import jsonutils
23from manila import rpc
24from manila.share import utils
26CONF = cfg.CONF
29class ShareAPI(object):
30 """Client side of the share rpc API.
32 API version history:
34 1.0 - Initial version.
35 1.1 - Add manage_share() and unmanage_share() methods
36 1.2 - Add extend_share() method
37 1.3 - Add shrink_share() method
38 1.4 - Introduce Share Instances:
39 create_share() -> create_share_instance()
40 delete_share() -> delete_share_instance()
41 Add share_instance argument to allow_access() & deny_access()
42 1.5 - Add create_consistency_group, delete_consistency_group
43 create_cgsnapshot, and delete_cgsnapshot methods
44 1.6 - Introduce Share migration:
45 migrate_share()
46 get_migration_info()
47 get_driver_migration_info()
48 1.7 - Update target call API in allow/deny access methods (Removed
49 in 1.14)
50 1.8 - Introduce Share Replication:
51 create_share_replica()
52 delete_share_replica()
53 promote_share_replica()
54 update_share_replica()
55 1.9 - Add manage_snapshot() and unmanage_snapshot() methods
56 1.10 - Add migration_complete(), migration_cancel() and
57 migration_get_progress(), rename migrate_share() to
58 migration_start(), rename get_migration_info() to
59 migration_get_info(), rename get_driver_migration_info() to
60 migration_get_driver_info()
61 1.11 - Add create_replicated_snapshot() and
62 delete_replicated_snapshot() methods
63 1.12 - Add provide_share_server(), create_share_server() and
64 migration_driver_recovery(), remove migration_get_driver_info(),
65 update migration_cancel(), migration_complete() and
66 migration_get_progress method signature, rename
67 migration_get_info() to connection_get_info()
68 1.13 - Introduce share revert to snapshot: revert_to_snapshot()
69 1.14 - Add update_access() and remove allow_access() and deny_access().
70 1.15 - Updated migration_start() method with new parameter
71 "preserve_snapshots"
72 1.16 - Convert create_consistency_group, delete_consistency_group
73 create_cgsnapshot, and delete_cgsnapshot methods to
74 create_share_group, delete_share_group
75 create_share_group_snapshot, and delete_share_group_snapshot
76 1.17 - Add snapshot_update_access()
77 1.18 - Remove unused "share_id" parameter from revert_to_snapshot()
78 1.19 - Add manage_share_server() and unmanage_share_server()
79 1.20 - Add share_instance_id parameter for create_share_server() method
80 1.21 - Add share_server_migration_start, share_server_migration_check()
81 and share_server_get_progress()
82 1.22 - Add update_share_network_security_service() and
83 check_update_share_network_security_service()
84 1.23 - Add update_share_server_network_allocations() and
85 check_update_share_server_network_allocations()
86 1.24 - Add quiesce_wait_time paramater to promote_share_replica()
87 1.25 - Add transfer_accept()
88 1.26 - Add create_backup() and delete_backup()
89 restore_backup() methods
90 1.27 - Update delete_share_instance() and delete_snapshot() methods
91 1.28 - Add update_share_from_metadata() method
92 1.29 - Add ensure_shares()
93 1.30 - Add update_share_network_subnet_from_metadata() method
94 """
96 BASE_RPC_API_VERSION = '1.0'
98 def __init__(self, topic=None):
99 super(ShareAPI, self).__init__()
100 target = messaging.Target(topic=CONF.share_topic,
101 version=self.BASE_RPC_API_VERSION)
102 self.client = rpc.get_client(target, version_cap='1.30')
104 def create_share_instance(self, context, share_instance, host,
105 request_spec, filter_properties,
106 snapshot_id=None):
107 new_host = utils.extract_host(host)
108 call_context = self.client.prepare(server=new_host, version='1.4')
109 request_spec_p = jsonutils.to_primitive(request_spec)
110 call_context.cast(context,
111 'create_share_instance',
112 share_instance_id=share_instance['id'],
113 request_spec=request_spec_p,
114 filter_properties=filter_properties,
115 snapshot_id=snapshot_id)
117 def manage_share(self, context, share, driver_options=None):
118 host = utils.extract_host(share['instance']['host'])
119 call_context = self.client.prepare(server=host, version='1.1')
120 call_context.cast(context,
121 'manage_share',
122 share_id=share['id'],
123 driver_options=driver_options)
125 def unmanage_share(self, context, share):
126 host = utils.extract_host(share['instance']['host'])
127 call_context = self.client.prepare(server=host, version='1.1')
128 call_context.cast(context, 'unmanage_share', share_id=share['id'])
130 def manage_snapshot(self, context, snapshot, host,
131 driver_options=None):
132 new_host = utils.extract_host(host)
133 call_context = self.client.prepare(server=new_host, version='1.9')
134 call_context.cast(context,
135 'manage_snapshot',
136 snapshot_id=snapshot['id'],
137 driver_options=driver_options)
139 def unmanage_snapshot(self, context, snapshot, host):
140 new_host = utils.extract_host(host)
141 call_context = self.client.prepare(server=new_host, version='1.9')
142 call_context.cast(context,
143 'unmanage_snapshot',
144 snapshot_id=snapshot['id'])
146 def manage_share_server(
147 self, context, share_server, identifier, driver_opts):
148 host = utils.extract_host(share_server['host'])
149 call_context = self.client.prepare(server=host, version='1.19')
150 call_context.cast(context, 'manage_share_server',
151 share_server_id=share_server['id'],
152 identifier=identifier,
153 driver_opts=driver_opts)
155 def unmanage_share_server(self, context, share_server, force=False):
156 host = utils.extract_host(share_server['host'])
157 call_context = self.client.prepare(server=host, version='1.19')
158 call_context.cast(context, 'unmanage_share_server',
159 share_server_id=share_server['id'],
160 force=force)
162 def revert_to_snapshot(self, context, share, snapshot, host, reservations):
163 host = utils.extract_host(host)
164 call_context = self.client.prepare(server=host, version='1.18')
165 call_context.cast(context,
166 'revert_to_snapshot',
167 snapshot_id=snapshot['id'],
168 reservations=reservations)
170 def delete_share_instance(self, context, share_instance, force=False,
171 deferred_delete=False):
172 host = utils.extract_host(share_instance['host'])
173 call_context = self.client.prepare(server=host, version='1.27')
174 call_context.cast(context,
175 'delete_share_instance',
176 share_instance_id=share_instance['id'],
177 force=force,
178 deferred_delete=deferred_delete)
180 def migration_start(self, context, share, dest_host,
181 force_host_assisted_migration, preserve_metadata,
182 writable, nondisruptive, preserve_snapshots,
183 new_share_network_id, new_share_type_id):
184 new_host = utils.extract_host(share['instance']['host'])
185 call_context = self.client.prepare(server=new_host, version='1.15')
186 call_context.cast(
187 context,
188 'migration_start',
189 share_id=share['id'],
190 dest_host=dest_host,
191 force_host_assisted_migration=force_host_assisted_migration,
192 preserve_metadata=preserve_metadata,
193 writable=writable,
194 nondisruptive=nondisruptive,
195 preserve_snapshots=preserve_snapshots,
196 new_share_network_id=new_share_network_id,
197 new_share_type_id=new_share_type_id)
199 def share_server_migration_start(self, context, share_server, dest_host,
200 writable, nondisruptive,
201 preserve_snapshots, new_share_network_id):
202 host = utils.extract_host(dest_host)
203 call_context = self.client.prepare(server=host, version='1.21')
204 call_context.cast(
205 context,
206 'share_server_migration_start',
207 share_server_id=share_server['id'],
208 dest_host=dest_host,
209 writable=writable,
210 nondisruptive=nondisruptive,
211 preserve_snapshots=preserve_snapshots,
212 new_share_network_id=new_share_network_id)
214 def share_server_migration_check(self, context, share_server_id, dest_host,
215 writable, nondisruptive,
216 preserve_snapshots, new_share_network_id):
217 host = utils.extract_host(dest_host)
218 call_context = self.client.prepare(server=host, version='1.21')
219 return call_context.call(
220 context,
221 'share_server_migration_check',
222 share_server_id=share_server_id,
223 dest_host=dest_host,
224 writable=writable,
225 nondisruptive=nondisruptive,
226 preserve_snapshots=preserve_snapshots,
227 new_share_network_id=new_share_network_id)
229 def share_server_migration_cancel(self, context, dest_host, share_server,
230 dest_share_server):
231 host = utils.extract_host(dest_host)
232 call_context = self.client.prepare(server=host, version='1.21')
233 call_context.cast(
234 context,
235 'share_server_migration_cancel',
236 src_share_server_id=share_server['id'],
237 dest_share_server_id=dest_share_server['id'])
239 def share_server_migration_get_progress(self, context, dest_host,
240 share_server, dest_share_server):
241 host = utils.extract_host(dest_host)
242 call_context = self.client.prepare(server=host, version='1.21')
243 return call_context.call(context,
244 'share_server_migration_get_progress',
245 src_share_server_id=share_server['id'],
246 dest_share_server_id=dest_share_server['id'])
248 def share_server_migration_complete(self, context, dest_host,
249 share_server, dest_share_server):
250 host = utils.extract_host(dest_host)
251 call_context = self.client.prepare(server=host, version='1.21')
252 call_context.cast(context,
253 'share_server_migration_complete',
254 src_share_server_id=share_server['id'],
255 dest_share_server_id=dest_share_server['id'])
257 def connection_get_info(self, context, share_instance):
258 new_host = utils.extract_host(share_instance['host'])
259 call_context = self.client.prepare(server=new_host, version='1.12')
260 return call_context.call(context,
261 'connection_get_info',
262 share_instance_id=share_instance['id'])
264 def delete_share_server(self, context, share_server):
265 host = utils.extract_host(share_server['host'])
266 call_context = self.client.prepare(server=host, version='1.0')
267 call_context.cast(context,
268 'delete_share_server',
269 share_server=share_server)
271 def create_snapshot(self, context, share, snapshot):
272 host = utils.extract_host(share['instance']['host'])
273 call_context = self.client.prepare(server=host)
274 call_context.cast(context,
275 'create_snapshot',
276 share_id=share['id'],
277 snapshot_id=snapshot['id'])
279 def delete_snapshot(self, context, snapshot, host, force=False,
280 deferred_delete=False):
281 new_host = utils.extract_host(host)
282 call_context = self.client.prepare(server=new_host, version='1.27')
283 call_context.cast(context,
284 'delete_snapshot',
285 snapshot_id=snapshot['id'],
286 force=force,
287 deferred_delete=deferred_delete)
289 def create_replicated_snapshot(self, context, share, replicated_snapshot):
290 host = utils.extract_host(share['instance']['host'])
291 call_context = self.client.prepare(server=host, version='1.11')
292 call_context.cast(context,
293 'create_replicated_snapshot',
294 snapshot_id=replicated_snapshot['id'],
295 share_id=share['id'])
297 def delete_replicated_snapshot(self, context, replicated_snapshot, host,
298 share_id=None, force=False):
299 host = utils.extract_host(host)
300 call_context = self.client.prepare(server=host, version='1.11')
301 call_context.cast(context,
302 'delete_replicated_snapshot',
303 snapshot_id=replicated_snapshot['id'],
304 share_id=share_id,
305 force=force)
307 def update_access(self, context, share_instance):
308 host = utils.extract_host(share_instance['host'])
309 call_context = self.client.prepare(server=host, version='1.14')
310 call_context.cast(context, 'update_access',
311 share_instance_id=share_instance['id'])
313 def update_access_for_instances(self, context, dest_host,
314 share_instance_ids, share_server_id=None):
315 host = utils.extract_host(dest_host)
316 call_context = self.client.prepare(server=host, version='1.21')
317 call_context.cast(context, 'update_access_for_instances',
318 share_instance_ids=share_instance_ids,
319 share_server_id=share_server_id)
321 def publish_service_capabilities(self, context):
322 call_context = self.client.prepare(fanout=True, version='1.0')
323 call_context.cast(context, 'publish_service_capabilities')
325 def transfer_accept(self, ctxt, share, new_user,
326 new_project, clear_rules=False):
327 msg_args = {
328 'share_id': share['id'],
329 'new_user': new_user,
330 'new_project': new_project,
331 'clear_rules': clear_rules
332 }
333 host = utils.extract_host(share['instance']['host'])
334 call_context = self.client.prepare(server=host, version='1.25')
335 call_context.call(ctxt, 'transfer_accept', **msg_args)
337 def extend_share(self, context, share, new_size, reservations):
338 host = utils.extract_host(share['instance']['host'])
339 call_context = self.client.prepare(server=host, version='1.2')
340 call_context.cast(context,
341 'extend_share',
342 share_id=share['id'],
343 new_size=new_size,
344 reservations=reservations)
346 def shrink_share(self, context, share, new_size):
347 host = utils.extract_host(share['instance']['host'])
348 call_context = self.client.prepare(server=host, version='1.3')
349 call_context.cast(context,
350 'shrink_share',
351 share_id=share['id'],
352 new_size=new_size)
354 def create_share_group(self, context, share_group, host):
355 new_host = utils.extract_host(host)
356 call_context = self.client.prepare(server=new_host, version='1.16')
357 call_context.cast(
358 context, 'create_share_group', share_group_id=share_group['id'])
360 def delete_share_group(self, context, share_group):
361 new_host = utils.extract_host(share_group['host'])
362 call_context = self.client.prepare(server=new_host, version='1.16')
363 call_context.cast(
364 context, 'delete_share_group', share_group_id=share_group['id'])
366 def create_share_group_snapshot(self, context, share_group_snapshot, host):
367 new_host = utils.extract_host(host)
368 call_context = self.client.prepare(server=new_host, version='1.16')
369 call_context.cast(
370 context, 'create_share_group_snapshot',
371 share_group_snapshot_id=share_group_snapshot['id'])
373 def delete_share_group_snapshot(self, context, share_group_snapshot, host):
374 new_host = utils.extract_host(host)
375 call_context = self.client.prepare(server=new_host, version='1.16')
376 call_context.cast(
377 context, 'delete_share_group_snapshot',
378 share_group_snapshot_id=share_group_snapshot['id'])
380 def create_share_replica(self, context, share_replica, host,
381 request_spec, filter_properties):
382 new_host = utils.extract_host(host)
383 call_context = self.client.prepare(server=new_host, version='1.8')
384 request_spec_p = jsonutils.to_primitive(request_spec)
385 call_context.cast(context,
386 'create_share_replica',
387 share_replica_id=share_replica['id'],
388 request_spec=request_spec_p,
389 filter_properties=filter_properties,
390 share_id=share_replica['share_id'])
392 def delete_share_replica(self, context, share_replica, force=False):
393 host = utils.extract_host(share_replica['host'])
394 call_context = self.client.prepare(server=host, version='1.8')
395 call_context.cast(context,
396 'delete_share_replica',
397 share_replica_id=share_replica['id'],
398 share_id=share_replica['share_id'],
399 force=force)
401 def promote_share_replica(self, context, share_replica,
402 quiesce_wait_time=None):
403 host = utils.extract_host(share_replica['host'])
404 call_context = self.client.prepare(server=host, version='1.24')
405 call_context.cast(context,
406 'promote_share_replica',
407 share_replica_id=share_replica['id'],
408 share_id=share_replica['share_id'],
409 quiesce_wait_time=quiesce_wait_time)
411 def update_share_replica(self, context, share_replica):
412 host = utils.extract_host(share_replica['host'])
413 call_context = self.client.prepare(server=host, version='1.8')
414 call_context.cast(context,
415 'update_share_replica',
416 share_replica_id=share_replica['id'],
417 share_id=share_replica['share_id'])
419 def migration_complete(self, context, src_share_instance,
420 dest_instance_id):
421 new_host = utils.extract_host(src_share_instance['host'])
422 call_context = self.client.prepare(server=new_host, version='1.12')
423 call_context.cast(context,
424 'migration_complete',
425 src_instance_id=src_share_instance['id'],
426 dest_instance_id=dest_instance_id)
428 def migration_cancel(self, context, src_share_instance, dest_instance_id):
429 new_host = utils.extract_host(src_share_instance['host'])
430 call_context = self.client.prepare(server=new_host, version='1.12')
431 call_context.cast(context,
432 'migration_cancel',
433 src_instance_id=src_share_instance['id'],
434 dest_instance_id=dest_instance_id)
436 def migration_get_progress(self, context, src_share_instance,
437 dest_instance_id):
438 new_host = utils.extract_host(src_share_instance['host'])
439 call_context = self.client.prepare(server=new_host, version='1.12')
440 return call_context.call(context,
441 'migration_get_progress',
442 src_instance_id=src_share_instance['id'],
443 dest_instance_id=dest_instance_id)
445 def provide_share_server(self, context, share_instance, share_network_id,
446 snapshot_id=None):
447 new_host = utils.extract_host(share_instance['host'])
448 call_context = self.client.prepare(server=new_host, version='1.12')
449 return call_context.call(context,
450 'provide_share_server',
451 share_instance_id=share_instance['id'],
452 share_network_id=share_network_id,
453 snapshot_id=snapshot_id)
455 def create_share_server(self, context, share_instance, share_server_id):
456 new_host = utils.extract_host(share_instance['host'])
457 call_context = self.client.prepare(server=new_host, version='1.20')
458 call_context.cast(context,
459 'create_share_server',
460 share_server_id=share_server_id,
461 share_instance_id=share_instance['id'])
463 def snapshot_update_access(self, context, snapshot_instance):
464 host = utils.extract_host(snapshot_instance['share_instance']['host'])
465 call_context = self.client.prepare(server=host, version='1.17')
466 call_context.cast(context,
467 'snapshot_update_access',
468 snapshot_instance_id=snapshot_instance['id'])
470 def update_share_network_security_service(
471 self, context, dest_host, share_network_id,
472 new_security_service_id, current_security_service_id=None):
473 host = utils.extract_host(dest_host)
474 call_context = self.client.prepare(server=host, version='1.22')
475 call_context.cast(
476 context,
477 'update_share_network_security_service',
478 share_network_id=share_network_id,
479 new_security_service_id=new_security_service_id,
480 current_security_service_id=current_security_service_id)
482 def check_update_share_network_security_service(
483 self, context, dest_host, share_network_id,
484 new_security_service_id, current_security_service_id=None):
485 host = utils.extract_host(dest_host)
486 call_context = self.client.prepare(server=host, version='1.22')
487 call_context.cast(
488 context,
489 'check_update_share_network_security_service',
490 share_network_id=share_network_id,
491 new_security_service_id=new_security_service_id,
492 current_security_service_id=current_security_service_id)
494 def check_update_share_server_network_allocations(
495 self, context, dest_host, share_network_id,
496 new_share_network_subnet):
497 host = utils.extract_host(dest_host)
498 call_context = self.client.prepare(server=host, version='1.23')
499 call_context.cast(
500 context,
501 'check_update_share_server_network_allocations',
502 share_network_id=share_network_id,
503 new_share_network_subnet=new_share_network_subnet)
505 def update_share_server_network_allocations(
506 self, context, dest_host, share_network_id,
507 new_share_network_subnet_id):
508 host = utils.extract_host(dest_host)
509 call_context = self.client.prepare(server=host, version='1.23')
510 call_context.cast(
511 context,
512 'update_share_server_network_allocations',
513 share_network_id=share_network_id,
514 new_share_network_subnet_id=new_share_network_subnet_id)
516 def create_backup(self, context, backup):
517 host = utils.extract_host(backup['host'])
518 call_context = self.client.prepare(server=host, version='1.26')
519 return call_context.cast(context,
520 'create_backup',
521 backup=backup)
523 def delete_backup(self, context, backup):
524 host = utils.extract_host(backup['host'])
525 call_context = self.client.prepare(server=host, version='1.26')
526 return call_context.cast(context,
527 'delete_backup',
528 backup=backup)
530 def restore_backup(self, context, backup, share_id):
531 host = utils.extract_host(backup['host'])
532 call_context = self.client.prepare(server=host, version='1.26')
533 return call_context.cast(context,
534 'restore_backup',
535 backup=backup,
536 share_id=share_id)
538 def update_share_from_metadata(self, context, share, metadata):
539 host = utils.extract_host(share['instance']['host'])
540 call_context = self.client.prepare(server=host, version='1.28')
541 return call_context.cast(context,
542 'update_share_from_metadata',
543 share_id=share['id'],
544 metadata=metadata)
546 def update_share_network_subnet_from_metadata(self, context,
547 share_network_id,
548 share_network_subnet_id,
549 share_server,
550 metadata):
551 host = utils.extract_host(share_server['host'])
552 call_context = self.client.prepare(server=host, version='1.30')
553 call_context.cast(
554 context,
555 'update_share_network_subnet_from_metadata',
556 share_network_id=share_network_id,
557 share_network_subnet_id=share_network_subnet_id,
558 share_server_id=share_server['id'],
559 metadata=metadata)
561 def ensure_driver_resources(self, context, host):
562 host = utils.extract_host(host)
563 call_context = self.client.prepare(server=host, version='1.29')
564 return call_context.cast(
565 context,
566 'ensure_driver_resources',
567 skip_backend_info_check=True
568 )