[lxc-devel] [lxd/master] lxd: Fix error message when deleting storage pools
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Mon Feb 10 15:42:08 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 468 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200210/bfda4061/attachment.bin>
-------------- next part --------------
From f9339c0ac1ab9fd489eb614cd53ac356cec80968 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 10 Feb 2020 16:38:12 +0100
Subject: [PATCH] lxd: Fix error message when deleting storage pools
This checks all projects for attached volumes when attempting to
delete a storage pool.
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
lxd/storage_pools.go | 42 ++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go
index 2bc243885a..c978fc1c82 100644
--- a/lxd/storage_pools.go
+++ b/lxd/storage_pools.go
@@ -674,27 +674,41 @@ func storagePoolDeleteCheckPreconditions(cluster *db.Cluster, poolName string, p
return response.InternalError(err)
}
+ var projects []string
+
+ err = cluster.Transaction(func(tx *db.ClusterTx) error {
+ projects, err = tx.ProjectNames()
+ return err
+ })
+ if err != nil {
+ return response.InternalError(err)
+ }
+
if len(volumeNames) > 0 {
- volumes, err := cluster.StoragePoolVolumesGet("default", poolID, supportedVolumeTypes)
- if err != nil {
- return response.InternalError(err)
- }
+ for _, project := range projects {
+ volumes, err := cluster.StoragePoolVolumesGet(project, poolID, supportedVolumeTypes)
+ if err != nil {
+ return response.InternalError(err)
+ }
- for _, volume := range volumes {
- if volume.Type != "image" {
- return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName))
+ for _, volume := range volumes {
+ if volume.Type != "image" {
+ return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName))
+ }
}
}
}
- // Check if the storage pool is still referenced in any profiles.
- profiles, err := profilesUsingPoolGetNames(cluster, "default", poolName)
- if err != nil {
- return response.SmartError(err)
- }
+ for _, project := range projects {
+ // Check if the storage pool is still referenced in any profiles.
+ profiles, err := profilesUsingPoolGetNames(cluster, project, poolName)
+ if err != nil {
+ return response.SmartError(err)
+ }
- if len(profiles) > 0 {
- return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n")))
+ if len(profiles) > 0 {
+ return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n")))
+ }
}
return nil
More information about the lxc-devel
mailing list