Merge "Add support of scheduler_hints in share replica create"

This commit is contained in:
Zuul 2022-02-16 23:49:33 +00:00 committed by Gerrit Code Review
commit 7c04fcb904
8 changed files with 52 additions and 15 deletions

View File

@ -2941,6 +2941,15 @@ share_replica_reset_replica_state:
in: body in: body
required: true required: true
type: object 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: share_replica_share_id:
description: | description: |
The UUID of the share from which to create a The UUID of the share from which to create a

View File

@ -1,6 +1,9 @@
{ {
"share_replica": { "share_replica": {
"share_id": "50a6a566-6bac-475c-ad69-5035c86696c0", "share_id": "50a6a566-6bac-475c-ad69-5035c86696c0",
"availability_zone": "nova" "availability_zone": "nova",
"scheduler_hints": {
"only_host": "host1@generic1#GENERIC1"
}
} }
} }

View File

@ -84,6 +84,7 @@ Request
- share_id: share_replica_share_id - share_id: share_replica_share_id
- availability_zone: share_replica_az - availability_zone: share_replica_az
- share_network_id: share_replica_share_network_id - share_network_id: share_replica_share_network_id
- scheduler_hints: share_replica_scheduler_hints
Request example Request example
--------------- ---------------

View File

@ -173,8 +173,8 @@ REST_API_VERSION_HISTORY = """
* 2.65 - Added ability to set affinity scheduler hints via the share * 2.65 - Added ability to set affinity scheduler hints via the share
create API. create API.
* 2.66 - Added filter search by group spec for share group type list. * 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 * 2.67 - Added ability to set 'only_host' scheduler hint for the share
create API. create and share replica create API.
* 2.68 - Added admin only capabilities to share metadata API * 2.68 - Added admin only capabilities to share metadata API
""" """

View File

@ -371,8 +371,8 @@ user documentation.
2.67 2.67
____ ____
Added support for 'only_host' key in "scheduler_hints" in the request body Added support for 'only_host' key in "scheduler_hints" in the request body
of the POST/shares request. This hint will invoke OnlyHost scheduler of the POST/shares and POST/share-replicas request. This hint will invoke
filter during share creation. 'OnlyHost' scheduler filter during share and share-replica creation.
2.68 2.68
---- ----

View File

@ -127,28 +127,37 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin):
return self._view_builder.detail(req, replica) 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( @wsgi.Controller.api_version(
MIN_SUPPORTED_API_VERSION, PRE_GRADUATION_VERSION, experimental=True) MIN_SUPPORTED_API_VERSION, PRE_GRADUATION_VERSION, experimental=True)
@wsgi.response(202) @wsgi.response(202)
def create(self, req, body): def create(self, req, body):
return self._create(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) @wsgi.response(202)
def create(self, req, body): # pylint: disable=function-redefined # noqa F811 def create(self, req, body): # pylint: disable=function-redefined # noqa F811
return self._create(req, body) 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') @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.""" """Add a replica to an existing share."""
context = req.environ['manila.context'] context = req.environ['manila.context']
self._validate_body(body)
if not self.is_valid_body(body, 'share_replica'):
msg = _("Body does not contain 'share_replica' information.")
raise exc.HTTPUnprocessableEntity(explanation=msg)
share_id = body.get('share_replica').get('share_id') share_id = body.get('share_replica').get('share_id')
availability_zone = body.get('share_replica').get('availability_zone') 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: if not share_id:
msg = _("Must provide Share ID to add replica.") msg = _("Must provide Share ID to add replica.")
@ -169,7 +178,8 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin):
try: try:
new_replica = self.share_api.create_share_replica( new_replica = self.share_api.create_share_replica(
context, share_ref, availability_zone=availability_zone, 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: except exception.AvailabilityZoneNotFound as e:
raise exc.HTTPBadRequest(explanation=e.message) raise exc.HTTPBadRequest(explanation=e.message)
except exception.ReplicationException as e: except exception.ReplicationException as e:

View File

@ -594,7 +594,7 @@ class API(base.Base):
return request_spec, share_instance return request_spec, share_instance
def create_share_replica(self, context, share, availability_zone=None, 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'): if not share.get('replication_type'):
msg = _("Replication not supported for share %s.") msg = _("Replication not supported for share %s.")
@ -604,6 +604,12 @@ class API(base.Base):
msg = _("Replication not supported for shares in a group.") msg = _("Replication not supported for shares in a group.")
raise exception.InvalidShare(message=msg) 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) self._check_is_share_busy(share)
active_replica = self.db.share_replicas_get_available_active_replica( active_replica = self.db.share_replicas_get_available_active_replica(
@ -725,7 +731,8 @@ class API(base.Base):
context, snapshot['id'], snapshot_instance) context, snapshot['id'], snapshot_instance)
self.scheduler_rpcapi.create_share_replica( 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 return share_replica

View File

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