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

View File

@ -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"
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

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.