diff --git a/doc/source/user/proxies/shared_file_system.rst b/doc/source/user/proxies/shared_file_system.rst index 07581978f..e5c5cddd4 100644 --- a/doc/source/user/proxies/shared_file_system.rst +++ b/doc/source/user/proxies/shared_file_system.rst @@ -80,6 +80,16 @@ service. :members: share_snapshots, get_share_snapshot, delete_share_snapshot, update_share_snapshot, create_share_snapshot +Shared File System Share Snapshot Instances +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Interact with Share Snapshot Instances supported by the +Shared File Systems service. + +.. autoclass:: openstack.shared_file_system.v2._proxy.Proxy + :noindex: + :members: share_snapshot_instances, get_share_snapshot_instance + Shared File System Share Networks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/source/user/resources/shared_file_system/index.rst b/doc/source/user/resources/shared_file_system/index.rst index d769a0a49..3ae1cead5 100644 --- a/doc/source/user/resources/shared_file_system/index.rst +++ b/doc/source/user/resources/shared_file_system/index.rst @@ -10,4 +10,5 @@ Shared File System service resources v2/share v2/user_message v2/share_snapshot + v2/share_snapshot_instance v2/share_network diff --git a/doc/source/user/resources/shared_file_system/v2/share_snapshot_instance.rst b/doc/source/user/resources/shared_file_system/v2/share_snapshot_instance.rst new file mode 100644 index 000000000..918459990 --- /dev/null +++ b/doc/source/user/resources/shared_file_system/v2/share_snapshot_instance.rst @@ -0,0 +1,13 @@ +openstack.shared_file_system.v2.share_snapshot_instance +======================================================= + +.. automodule:: openstack.shared_file_system.v2.share_snapshot_instance + +The ShareSnapshotInstance Class +------------------------------- + +The ``ShareSnapshotInstance`` class inherits from +:class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.shared_file_system.v2.share_snapshot_instance.ShareSnapshotInstance + :members: diff --git a/openstack/shared_file_system/v2/_proxy.py b/openstack/shared_file_system/v2/_proxy.py index 9325d9834..33307dab5 100644 --- a/openstack/shared_file_system/v2/_proxy.py +++ b/openstack/shared_file_system/v2/_proxy.py @@ -20,6 +20,9 @@ from openstack.shared_file_system.v2 import ( from openstack.shared_file_system.v2 import ( share_snapshot as _share_snapshot ) +from openstack.shared_file_system.v2 import ( + share_snapshot_instance as _share_snapshot_instance +) from openstack.shared_file_system.v2 import ( storage_pool as _storage_pool ) @@ -38,7 +41,9 @@ class Proxy(proxy.Proxy): "user_message": _user_message.UserMessage, "limit": _limit.Limit, "share": _share.Share, - "share_network": _share_network.ShareNetwork + "share_network": _share_network.ShareNetwork, + "share_snapshot_instance": + _share_snapshot_instance.ShareSnapshotInstance, } def availability_zones(self): @@ -331,6 +336,39 @@ class Proxy(proxy.Proxy): """ return resource.wait_for_delete(self, res, interval, wait) + def share_snapshot_instances(self, details=True, **query): + """Lists all share snapshot instances with details. + + :param bool details: Whether to fetch detailed resource + descriptions. Defaults to True. + :param kwargs query: Optional query parameters to be sent to limit + the share snapshot instance being returned. + Available parameters include: + + * snapshot_id: The UUID of the share’s base snapshot to filter + the request based on. + * project_id: The project ID of the user or service making the + request. + + :returns: A generator of share snapshot instance resources + :rtype: :class:`~openstack.shared_file_system.v2. + share_snapshot_instance.ShareSnapshotInstance` + """ + base_path = '/snapshot-instances/detail' if details else None + return self._list(_share_snapshot_instance.ShareSnapshotInstance, + base_path=base_path, **query) + + def get_share_snapshot_instance(self, snapshot_instance_id): + """Lists details of a single share snapshot instance + + :param snapshot_instance_id: The ID of the snapshot instance to get + :returns: Details of the identified snapshot instance + :rtype: :class:`~openstack.shared_file_system.v2. + share_snapshot_instance.ShareSnapshotInstance` + """ + return self._get(_share_snapshot_instance.ShareSnapshotInstance, + snapshot_instance_id) + def share_networks(self, details=True, **query): """Lists all share networks with details. diff --git a/openstack/shared_file_system/v2/share_snapshot_instance.py b/openstack/shared_file_system/v2/share_snapshot_instance.py new file mode 100644 index 000000000..6b0acb96b --- /dev/null +++ b/openstack/shared_file_system/v2/share_snapshot_instance.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack import resource + + +class ShareSnapshotInstance(resource.Resource): + resource_key = "snapshot_instance" + resources_key = "snapshot_instances" + base_path = "/snapshot-instances" + + # capabilities + allow_create = False + allow_fetch = True + allow_commit = False + allow_delete = False + allow_list = True + allow_head = False + + #: Properties + #: The date and time stamp when the resource was created within the + #: service’s database. + created_at = resource.Body("created_at", type=str) + #: The progress of the snapshot creation. + progress = resource.Body("progress", type=str) + #: Provider location of the snapshot on the backend. + provider_location = resource.Body("provider_location", type=str) + #: The UUID of the share. + share_id = resource.Body("share_id", type=str) + #: The UUID of the share instance. + share_instance_id = resource.Body("share_instance_id", type=str) + #: The UUID of the snapshot. + snapshot_id = resource.Body("snapshot_id", type=str) + #: The snapshot instance status. + status = resource.Body("status", type=str) + #: The date and time stamp when the resource was updated within the + #: service’s database. + updated_at = resource.Body("updated_at", type=str) diff --git a/openstack/tests/functional/shared_file_system/test_share_snapshot_instance.py b/openstack/tests/functional/shared_file_system/test_share_snapshot_instance.py new file mode 100644 index 000000000..0a7fc1ad6 --- /dev/null +++ b/openstack/tests/functional/shared_file_system/test_share_snapshot_instance.py @@ -0,0 +1,37 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.tests.functional.shared_file_system import base + + +class ShareSnapshotInstanceTest(base.BaseSharedFileSystemTest): + + def setUp(self): + super(ShareSnapshotInstanceTest, self).setUp() + + self.SHARE_NAME = self.getUniqueString() + my_share = self.create_share( + name=self.SHARE_NAME, size=2, share_type="dhss_false", + share_protocol='NFS', description=None) + self.SHARE_ID = my_share.id + self.create_share_snapshot( + share_id=self.SHARE_ID + ) + + def test_share_snapshot_instances(self): + sots = \ + self.operator_cloud.shared_file_system.share_snapshot_instances() + self.assertGreater(len(list(sots)), 0) + for sot in sots: + for attribute in ('id', 'name', 'created_at', 'updated_at'): + self.assertTrue(hasattr(sot, attribute)) + self.assertIsInstance(getattr(sot, attribute), 'str') diff --git a/openstack/tests/unit/shared_file_system/v2/test_proxy.py b/openstack/tests/unit/shared_file_system/v2/test_proxy.py index 9c5c879f3..82eeb3a5e 100644 --- a/openstack/tests/unit/shared_file_system/v2/test_proxy.py +++ b/openstack/tests/unit/shared_file_system/v2/test_proxy.py @@ -17,6 +17,7 @@ from openstack.shared_file_system.v2 import limit from openstack.shared_file_system.v2 import share from openstack.shared_file_system.v2 import share_network from openstack.shared_file_system.v2 import share_snapshot +from openstack.shared_file_system.v2 import share_snapshot_instance from openstack.shared_file_system.v2 import storage_pool from openstack.shared_file_system.v2 import user_message from openstack.tests.unit import test_proxy_base @@ -175,6 +176,41 @@ class TestShareSnapshotResource(test_proxy_base.TestProxyBase): mock_wait.assert_called_once_with(self.proxy, mock_resource, 2, 120) +class TestShareSnapshotInstanceResource(test_proxy_base.TestProxyBase): + + def setUp(self): + super(TestShareSnapshotInstanceResource, self).setUp() + self.proxy = _proxy.Proxy(self.session) + + def test_share_snapshot_instances(self): + self.verify_list( + self.proxy.share_snapshot_instances, + share_snapshot_instance.ShareSnapshotInstance) + + def test_share_snapshot_instance_detailed(self): + self.verify_list(self.proxy.share_snapshot_instances, + share_snapshot_instance.ShareSnapshotInstance, + method_kwargs={ + "details": True, + "query": {'snapshot_id': 'fake'} + }, + expected_kwargs={"query": {'snapshot_id': 'fake'}}) + + def test_share_snapshot_instance_not_detailed(self): + self.verify_list(self.proxy.share_snapshot_instances, + share_snapshot_instance.ShareSnapshotInstance, + method_kwargs={ + "details": False, + "query": {'snapshot_id': 'fake'} + }, + expected_kwargs={"query": {'snapshot_id': 'fake'}}) + + def test_share_snapshot_instance_get(self): + self.verify_get( + self.proxy.get_share_snapshot_instance, + share_snapshot_instance.ShareSnapshotInstance) + + class TestShareNetworkResource(test_proxy_base.TestProxyBase): def setUp(self): diff --git a/openstack/tests/unit/shared_file_system/v2/test_share_snapshot_instance.py b/openstack/tests/unit/shared_file_system/v2/test_share_snapshot_instance.py new file mode 100644 index 000000000..7998d0a9f --- /dev/null +++ b/openstack/tests/unit/shared_file_system/v2/test_share_snapshot_instance.py @@ -0,0 +1,50 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.shared_file_system.v2 import share_snapshot_instance +from openstack.tests.unit import base + +EXAMPLE = { + "status": "available", + "share_id": "618599ab-09a1-432d-973a-c102564c7fec", + "share_instance_id": "8edff0cb-e5ce-4bab-aa99-afe02ed6a76a", + "snapshot_id": "d447de19-a6d3-40b3-ae9f-895c86798924", + "progress": "100%", + "created_at": "2021-06-04T00:44:52.000000", + "id": "275516e8-c998-4e78-a41e-7dd3a03e71cd", + "provider_location": "/path/to/fake...", + "updated_at": "2017-06-04T00:44:54.000000" +} + + +class TestShareSnapshotInstances(base.TestCase): + + def test_basic(self): + instances = share_snapshot_instance.ShareSnapshotInstance() + self.assertEqual('snapshot_instance', instances.resource_key) + self.assertEqual('snapshot_instances', instances.resources_key) + self.assertEqual('/snapshot-instances', instances.base_path) + self.assertTrue(instances.allow_list) + + def test_make_share_snapshot_instance(self): + instance = share_snapshot_instance.ShareSnapshotInstance(**EXAMPLE) + self.assertEqual(EXAMPLE['id'], instance.id) + self.assertEqual(EXAMPLE['share_id'], instance.share_id) + self.assertEqual( + EXAMPLE['share_instance_id'], instance.share_instance_id) + self.assertEqual(EXAMPLE['snapshot_id'], instance.snapshot_id) + self.assertEqual(EXAMPLE['status'], instance.status) + self.assertEqual(EXAMPLE['progress'], instance.progress) + self.assertEqual(EXAMPLE['created_at'], instance.created_at) + self.assertEqual(EXAMPLE['updated_at'], instance.updated_at) + self.assertEqual( + EXAMPLE['provider_location'], instance.provider_location) diff --git a/releasenotes/notes/add-share-snapshot-instance-to-shared-file-4d935f12d67bf59d.yaml b/releasenotes/notes/add-share-snapshot-instance-to-shared-file-4d935f12d67bf59d.yaml new file mode 100644 index 000000000..385bc44f9 --- /dev/null +++ b/releasenotes/notes/add-share-snapshot-instance-to-shared-file-4d935f12d67bf59d.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added support to list and get share snapshot instances + on the shared file system service.