Merge "Add volume manage support"

This commit is contained in:
Zuul 2024-01-30 09:09:25 +00:00 committed by Gerrit Code Review
commit 67a885124d
5 changed files with 120 additions and 1 deletions

View File

@ -26,6 +26,7 @@ Volume Operations
upload_volume_to_image, reserve_volume, unreserve_volume,
begin_volume_detaching, abort_volume_detaching,
init_volume_attachment, terminate_volume_attachment,
manage_volume,
Backend Pools Operations
^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -809,6 +809,18 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
volume = self._get_resource(_volume.Volume, volume)
volume.detach(self, attachment, force, connector)
def manage_volume(self, **attrs):
"""Creates a volume by using existing storage rather than
allocating new storage.
:param dict attrs: Keyword arguments which will be used to create
a :class:`~openstack.block_storage.v3.volume.Volume`,
comprised of the properties on the Volume class.
:returns: The results of volume creation
:rtype: :class:`~openstack.block_storage.v3.volume.Volume`
"""
return _volume.Volume.manage(self, **attrs)
def unmanage_volume(self, volume):
"""Removes a volume from Block Storage management without removing the
back-end storage object that is associated with it.
@ -816,7 +828,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
:param volume: The value can be either the ID of a volume or a
:class:`~openstack.block_storage.v3.volume.Volume` instance.
:returns: None"""
:returns: None
"""
volume = self._get_resource(_volume.Volume, volume)
volume.unmanage(self)

View File

@ -181,6 +181,44 @@ class Volume(resource.Resource, metadata.MetadataMixin):
self._action(session, body)
@classmethod
def manage(
cls,
session,
host,
ref,
name=None,
description=None,
volume_type=None,
availability_zone=None,
metadata=None,
bootable=False,
cluster=None,
):
"""Manage an existing volume."""
url = '/manageable_volumes'
if not utils.supports_microversion(session, '3.8'):
url = '/os-volume-manage'
body = {
'volume': {
'host': host,
'ref': ref,
'name': name,
'description': description,
'volume_type': volume_type,
'availability_zone': availability_zone,
'metadata': metadata,
'bootable': bootable,
}
}
if cluster is not None:
body['volume']['cluster'] = cluster
resp = session.post(url, json=body, microversion=cls._max_microversion)
exceptions.raise_from_response(resp)
volume = Volume()
volume._translate_response(resp)
return volume
def unmanage(self, session):
"""Unmanage volume"""
body = {'os-unmanage': None}

View File

@ -31,6 +31,7 @@ IMAGE_METADATA = {
u'size': '13167616',
}
FAKE_HOST = "fake_host@fake_backend#fake_pool"
VOLUME = {
"status": "creating",
"name": "my_volume",
@ -598,3 +599,65 @@ class TestVolumeActions(TestVolume):
headers={},
params={},
)
@mock.patch(
'openstack.utils.supports_microversion',
autospec=True,
return_value=True,
)
def test_manage(self, mock_mv):
resp = mock.Mock()
resp.body = {'volume': copy.deepcopy(VOLUME)}
resp.json = mock.Mock(return_value=resp.body)
resp.headers = {}
resp.status_code = 202
self.sess.post = mock.Mock(return_value=resp)
sot = volume.Volume.manage(self.sess, host=FAKE_HOST, ref=FAKE_ID)
self.assertIsNotNone(sot)
url = '/manageable_volumes'
body = {
'volume': {
'host': FAKE_HOST,
'ref': FAKE_ID,
'name': None,
'description': None,
'volume_type': None,
'availability_zone': None,
'metadata': None,
'bootable': False,
}
}
self.sess.post.assert_called_with(
url, json=body, microversion=sot._max_microversion
)
@mock.patch(
'openstack.utils.supports_microversion',
autospec=True,
return_value=False,
)
def test_manage_pre_38(self, mock_mv):
resp = mock.Mock()
resp.body = {'volume': copy.deepcopy(VOLUME)}
resp.json = mock.Mock(return_value=resp.body)
resp.headers = {}
resp.status_code = 202
self.sess.post = mock.Mock(return_value=resp)
sot = volume.Volume.manage(self.sess, host=FAKE_HOST, ref=FAKE_ID)
self.assertIsNotNone(sot)
url = '/os-volume-manage'
body = {
'volume': {
'host': FAKE_HOST,
'ref': FAKE_ID,
'name': None,
'description': None,
'volume_type': None,
'availability_zone': None,
'metadata': None,
'bootable': False,
}
}
self.sess.post.assert_called_with(
url, json=body, microversion=sot._max_microversion
)

View File

@ -0,0 +1,4 @@
---
features:
- |
Added support for manage volume operation.