From 9da023eeb58fb7fc62a3898dd1296633fda467ae Mon Sep 17 00:00:00 2001 From: Kiran Pawar Date: Wed, 10 Nov 2021 10:00:56 +0000 Subject: [PATCH] Add support of scheduler_hints in share replica create The OnlyHostFilter added for share creation can be extended to use in share replica creation using scheduler-hints. e.g. manila share-replica-create share_id \ --scheduler-hints "only_host=host@backend#pool" OnlyHostFilter (https://review.opendev.org/c/openstack/manila/+/813293) Depends-on: I603434cac246e2c0946672d3f0fe469ed5423fa4 Closes-Bug: #1950313 Change-Id: I2e6d8709fc02df16622bdc910127fa489835db38 --- api-ref/source/parameters.yaml | 9 +++++++ .../samples/share-replica-create-request.json | 5 +++- api-ref/source/share-replicas.inc | 1 + manila/api/openstack/api_version_request.py | 4 +-- .../openstack/rest_api_version_history.rst | 4 +-- manila/api/v2/share_replicas.py | 26 +++++++++++++------ manila/share/api.py | 11 ++++++-- ..._hints_share_replica-ffeed5cf9adeddff.yaml | 7 +++++ 8 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 releasenotes/notes/scheduler_hints_share_replica-ffeed5cf9adeddff.yaml diff --git a/api-ref/source/parameters.yaml b/api-ref/source/parameters.yaml index faae2cb54c..c19962f071 100644 --- a/api-ref/source/parameters.yaml +++ b/api-ref/source/parameters.yaml @@ -2941,6 +2941,15 @@ share_replica_reset_replica_state: in: body required: true type: object +share_replica_scheduler_hints: + description: | + One or more scheduler_hints key and value pairs as a dictionary of + strings. Accepted hints are: + - ``only_host``: value must be a share manager service host in ``host@backend#POOL`` format (admin only) + in: body + required: false + type: object + min_version: 2.67 share_replica_share_id: description: | The UUID of the share from which to create a diff --git a/api-ref/source/samples/share-replica-create-request.json b/api-ref/source/samples/share-replica-create-request.json index 90338e1abe..7b9592d452 100644 --- a/api-ref/source/samples/share-replica-create-request.json +++ b/api-ref/source/samples/share-replica-create-request.json @@ -1,6 +1,9 @@ { "share_replica": { "share_id": "50a6a566-6bac-475c-ad69-5035c86696c0", - "availability_zone": "nova" + "availability_zone": "nova", + "scheduler_hints": { + "only_host": "host1@generic1#GENERIC1" + } } } diff --git a/api-ref/source/share-replicas.inc b/api-ref/source/share-replicas.inc index 0d6e067def..54b693c318 100644 --- a/api-ref/source/share-replicas.inc +++ b/api-ref/source/share-replicas.inc @@ -84,6 +84,7 @@ Request - share_id: share_replica_share_id - availability_zone: share_replica_az - share_network_id: share_replica_share_network_id + - scheduler_hints: share_replica_scheduler_hints Request example --------------- diff --git a/manila/api/openstack/api_version_request.py b/manila/api/openstack/api_version_request.py index 6b76b69f01..d9bd5480f4 100644 --- a/manila/api/openstack/api_version_request.py +++ b/manila/api/openstack/api_version_request.py @@ -173,8 +173,8 @@ REST_API_VERSION_HISTORY = """ * 2.65 - Added ability to set affinity scheduler hints via the share create API. * 2.66 - Added filter search by group spec for share group type list. - * 2.67 - Added ability to set 'only_host' scheduler hint via the share - create API. + * 2.67 - Added ability to set 'only_host' scheduler hint for the share + create and share replica create API. * 2.68 - Added admin only capabilities to share metadata API """ diff --git a/manila/api/openstack/rest_api_version_history.rst b/manila/api/openstack/rest_api_version_history.rst index 8c5fc7eee9..7e6a3acdbd 100644 --- a/manila/api/openstack/rest_api_version_history.rst +++ b/manila/api/openstack/rest_api_version_history.rst @@ -371,8 +371,8 @@ user documentation. 2.67 ____ Added support for 'only_host' key in "scheduler_hints" in the request body - of the POST/shares request. This hint will invoke OnlyHost scheduler - filter during share creation. + of the POST/shares and POST/share-replicas request. This hint will invoke + 'OnlyHost' scheduler filter during share and share-replica creation. 2.68 ---- diff --git a/manila/api/v2/share_replicas.py b/manila/api/v2/share_replicas.py index d012e778da..2a0a4e8cfd 100644 --- a/manila/api/v2/share_replicas.py +++ b/manila/api/v2/share_replicas.py @@ -127,28 +127,37 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): return self._view_builder.detail(req, replica) + def _validate_body(self, body): + if not self.is_valid_body(body, 'share_replica'): + msg = _("Body does not contain 'share_replica' information.") + raise exc.HTTPUnprocessableEntity(explanation=msg) + @wsgi.Controller.api_version( MIN_SUPPORTED_API_VERSION, PRE_GRADUATION_VERSION, experimental=True) @wsgi.response(202) def create(self, req, body): return self._create(req, body) - @wsgi.Controller.api_version(GRADUATION_VERSION) # noqa + @wsgi.Controller.api_version(GRADUATION_VERSION, "2.66") # noqa @wsgi.response(202) def create(self, req, body): # pylint: disable=function-redefined # noqa F811 return self._create(req, body) + @wsgi.Controller.api_version("2.67") # noqa + @wsgi.response(202) + def create(self, req, body): # pylint: disable=function-redefined # noqa F811 + return self._create(req, body, allow_scheduler_hints=True) + @wsgi.Controller.authorize('create') - def _create(self, req, body): + def _create(self, req, body, allow_scheduler_hints=False): """Add a replica to an existing share.""" context = req.environ['manila.context'] - - if not self.is_valid_body(body, 'share_replica'): - msg = _("Body does not contain 'share_replica' information.") - raise exc.HTTPUnprocessableEntity(explanation=msg) - + self._validate_body(body) share_id = body.get('share_replica').get('share_id') availability_zone = body.get('share_replica').get('availability_zone') + scheduler_hints = None + if allow_scheduler_hints: + scheduler_hints = body.get('share_replica').get('scheduler_hints') if not share_id: msg = _("Must provide Share ID to add replica.") @@ -169,7 +178,8 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): try: new_replica = self.share_api.create_share_replica( context, share_ref, availability_zone=availability_zone, - share_network_id=share_network_id) + share_network_id=share_network_id, + scheduler_hints=scheduler_hints) except exception.AvailabilityZoneNotFound as e: raise exc.HTTPBadRequest(explanation=e.message) except exception.ReplicationException as e: diff --git a/manila/share/api.py b/manila/share/api.py index 3023859405..b694d64c81 100644 --- a/manila/share/api.py +++ b/manila/share/api.py @@ -594,7 +594,7 @@ class API(base.Base): return request_spec, share_instance def create_share_replica(self, context, share, availability_zone=None, - share_network_id=None): + share_network_id=None, scheduler_hints=None): if not share.get('replication_type'): msg = _("Replication not supported for share %s.") @@ -604,6 +604,12 @@ class API(base.Base): msg = _("Replication not supported for shares in a group.") raise exception.InvalidShare(message=msg) + if scheduler_hints: + if ('only_host' not in scheduler_hints.keys() or len( + scheduler_hints) > 1): + msg = _("Arg 'scheduler_hints' supports only 'only_host' key.") + raise exception.InvalidInput(reason=msg) + self._check_is_share_busy(share) active_replica = self.db.share_replicas_get_available_active_replica( @@ -725,7 +731,8 @@ class API(base.Base): context, snapshot['id'], snapshot_instance) self.scheduler_rpcapi.create_share_replica( - context, request_spec=request_spec, filter_properties={}) + context, request_spec=request_spec, + filter_properties={'scheduler_hints': scheduler_hints}) return share_replica diff --git a/releasenotes/notes/scheduler_hints_share_replica-ffeed5cf9adeddff.yaml b/releasenotes/notes/scheduler_hints_share_replica-ffeed5cf9adeddff.yaml new file mode 100644 index 0000000000..97310e4ae8 --- /dev/null +++ b/releasenotes/notes/scheduler_hints_share_replica-ffeed5cf9adeddff.yaml @@ -0,0 +1,7 @@ +--- +features: + - Added option "scheduler_hints" to share replica create API. For now, the + onlyHostFilter will be supported using this option. The filter needs admin + to specify host@backend#pool to "share_replica.scheduler_hints.only_host" + in the request payload when creating a manila share replica. For non-admin + users the onlyHostFilter will always be ignored.