|
15 | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | # |
17 | 17 |
|
18 | | -from sm_typing import override |
| 18 | +from sm_typing import Dict, override |
19 | 19 |
|
20 | 20 | import errno |
21 | 21 | import json |
@@ -682,10 +682,16 @@ def destroy_volume(self, volume_uuid): |
682 | 682 | Destroy a volume. |
683 | 683 | :param str volume_uuid: The volume uuid to destroy. |
684 | 684 | """ |
685 | | - |
686 | 685 | self._ensure_volume_exists(volume_uuid) |
687 | 686 | self.ensure_volume_is_not_locked(volume_uuid) |
688 | 687 |
|
| 688 | + is_volume_in_use = any(node["in-use"] for node in self.get_resource_info(volume_uuid)["nodes"].values()) |
| 689 | + if is_volume_in_use: |
| 690 | + raise LinstorVolumeManagerError( |
| 691 | + f"Could not destroy volume `{volume_uuid}` as it is currently in use", |
| 692 | + LinstorVolumeManagerError.ERR_VOLUME_DESTROY |
| 693 | + ) |
| 694 | + |
689 | 695 | # Mark volume as destroyed. |
690 | 696 | volume_properties = self._get_volume_properties(volume_uuid) |
691 | 697 | volume_properties[self.PROP_NOT_EXISTS] = self.STATE_NOT_EXISTS |
@@ -1741,6 +1747,21 @@ def get_resources_info(self): |
1741 | 1747 |
|
1742 | 1748 | return resources |
1743 | 1749 |
|
| 1750 | + def get_resource_info(self, volume_uuid: str) -> Dict: |
| 1751 | + """ |
| 1752 | + Give all resources info with provided uuid on current group name. |
| 1753 | + :param: volume_uuid |
| 1754 | + :rtype: dict |
| 1755 | + """ |
| 1756 | + for volume in self.get_resources_info().values(): |
| 1757 | + if volume["uuid"] == volume_uuid: |
| 1758 | + return volume |
| 1759 | + |
| 1760 | + raise LinstorVolumeManagerError( |
| 1761 | + f"Could not find info about volume `{volume_uuid}`", |
| 1762 | + LinstorVolumeManagerError.ERR_VOLUME_DESTROY |
| 1763 | + ) |
| 1764 | + |
1744 | 1765 | def get_database_path(self): |
1745 | 1766 | """ |
1746 | 1767 | Get the database path. |
|
0 commit comments