diff --git a/api-ref/source/v3/attachments.inc b/api-ref/source/v3/attachments.inc index 4ea253951d1..87b57d6092c 100644 --- a/api-ref/source/v3/attachments.inc +++ b/api-ref/source/v3/attachments.inc @@ -253,7 +253,7 @@ Request - project_id: project_id_path - attachment: attachment - - instance_uuid: instance_uuid_req + - instance_uuid: instance_uuid - connector: connector - volume_uuid: volume_id_attachment - mode: attach_mode diff --git a/cinder/api/schemas/attachments.py b/cinder/api/schemas/attachments.py index cc03461c4d5..bd434954821 100644 --- a/cinder/api/schemas/attachments.py +++ b/cinder/api/schemas/attachments.py @@ -17,6 +17,7 @@ Schema for V3 Attachments API. """ +import copy from cinder.api.validation import parameter_types @@ -32,7 +33,7 @@ 'connector': {'type': ['object', 'null']}, 'volume_uuid': parameter_types.uuid, }, - 'required': ['instance_uuid', 'volume_uuid'], + 'required': ['volume_uuid'], 'additionalProperties': False, }, }, @@ -56,3 +57,7 @@ 'required': ['attachment'], 'additionalProperties': False, } + +create_v354 = copy.deepcopy(create) +create_v354['properties']['attachment']['properties']['mode'] = ( + {'type': 'string', 'enum': ['rw', 'ro']}) diff --git a/cinder/api/v3/attachments.py b/cinder/api/v3/attachments.py index fa01cb5467f..f0c4110ccb5 100644 --- a/cinder/api/v3/attachments.py +++ b/cinder/api/v3/attachments.py @@ -107,7 +107,9 @@ def _items(self, req): @wsgi.Controller.api_version(mv.NEW_ATTACH) @wsgi.response(HTTPStatus.OK) - @validation.schema(attachment.create) + @validation.schema(attachment.create, mv.NEW_ATTACH, + mv.get_prior_version(mv.ATTACHMENT_CREATE_MODE_ARG)) + @validation.schema(attachment.create_v354, mv.ATTACHMENT_CREATE_MODE_ARG) def create(self, req, body): """Create an attachment. @@ -130,6 +132,9 @@ def create(self, req, body): referenced below is the UUID of the Instance, for non-nova consumers this can be a server UUID or some other arbitrary unique identifier. + Starting from microversion 3.54, we can pass the attach mode as + argument in the request body. + Expected format of the input parameter 'body': .. code-block:: json @@ -138,8 +143,9 @@ def create(self, req, body): "attachment": { "volume_uuid": "volume-uuid", - "instance_uuid": "nova-server-uuid", - "connector": "null|" + "instance_uuid": "null|nova-server-uuid", + "connector": "null|", + "mode": "null|rw|ro" } } @@ -167,7 +173,7 @@ def create(self, req, body): returns: A summary view of the attachment object """ context = req.environ['cinder.context'] - instance_uuid = body['attachment']['instance_uuid'] + instance_uuid = body['attachment'].get('instance_uuid') volume_uuid = body['attachment']['volume_uuid'] volume_ref = objects.Volume.get_by_id( context,