diff --git a/openstack/block_storage/v2/_proxy.py b/openstack/block_storage/v2/_proxy.py index 80bfea696..50f065a79 100644 --- a/openstack/block_storage/v2/_proxy.py +++ b/openstack/block_storage/v2/_proxy.py @@ -37,6 +37,28 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): """ return self._get(_snapshot.Snapshot, snapshot) + def find_snapshot(self, name_or_id, ignore_missing=True): + """Find a single snapshot + + :param snapshot: The name or ID a snapshot + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be raised + when the snapshot does not exist. When set to ``True``, None will + be returned when attempting to find a nonexistent resource. + + :returns: One :class:`~openstack.block_storage.v2.snapshot.Snapshot` or + None. + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + :raises: :class:`~openstack.exceptions.DuplicateResource` when multiple + resources are found. + """ + return self._find( + _snapshot.Snapshot, + name_or_id, + ignore_missing=ignore_missing, + ) + def snapshots(self, details=True, **query): """Retrieve a generator of snapshots @@ -457,6 +479,26 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): """ return self._get(_backup.Backup, backup) + def find_backup(self, name_or_id, ignore_missing=True): + """Find a single backup + + :param snapshot: The name or ID a backup + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be raised + when the backup does not exist. + + :returns: One :class:`~openstack.block_storage.v2.backup.Backup` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + :raises: :class:`~openstack.exceptions.DuplicateResource` when multiple + resources are found. + """ + return self._find( + _backup.Backup, + name_or_id, + ignore_missing=ignore_missing, + ) + def create_backup(self, **attrs): """Create a new Backup from attributes with native API diff --git a/openstack/tests/unit/block_storage/v2/test_proxy.py b/openstack/tests/unit/block_storage/v2/test_proxy.py index 897addcf8..4bd5e84c2 100644 --- a/openstack/tests/unit/block_storage/v2/test_proxy.py +++ b/openstack/tests/unit/block_storage/v2/test_proxy.py @@ -220,6 +220,9 @@ class TestBackup(TestVolumeProxy): self.proxy._connection.has_service = mock.Mock(return_value=True) self.verify_get(self.proxy.get_backup, backup.Backup) + def test_backup_find(self): + self.verify_find(self.proxy.find_backup, backup.Backup) + def test_backup_delete(self): # NOTE: mock has_service self.proxy._connection = mock.Mock() @@ -272,6 +275,9 @@ class TestSnapshot(TestVolumeProxy): def test_snapshot_get(self): self.verify_get(self.proxy.get_snapshot, snapshot.Snapshot) + def test_snapshot_find(self): + self.verify_find(self.proxy.find_snapshot, snapshot.Snapshot) + def test_snapshots_detailed(self): self.verify_list(self.proxy.snapshots, snapshot.SnapshotDetail, method_kwargs={"details": True, "query": 1}, diff --git a/releasenotes/notes/add-find-backup-find-snapshot-v2-756a05ccd150db82.yaml b/releasenotes/notes/add-find-backup-find-snapshot-v2-756a05ccd150db82.yaml new file mode 100644 index 000000000..68789d3b8 --- /dev/null +++ b/releasenotes/notes/add-find-backup-find-snapshot-v2-756a05ccd150db82.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The ``find_snapshot`` and ``find_backup`` methods have been added to the + v2 block storage proxy API. These were previously only available for the v3 + proxy API.