[lxc-devel] [lxd/master] lxd/db: Set ceph.user.name if missing

stgraber on Github lxc-bot at linuxcontainers.org
Wed Feb 19 22:00:59 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200219/411bd501/attachment.bin>
-------------- next part --------------
From 2df1e5b750b90042474b6a1a505d74e5c594eb43 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 19 Feb 2020 16:59:53 -0500
Subject: [PATCH] lxd/db: Set ceph.user.name if missing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #6898

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/db/cluster/schema.go |  2 +-
 lxd/db/cluster/update.go | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/lxd/db/cluster/schema.go b/lxd/db/cluster/schema.go
index 02f2057d10..979578656e 100644
--- a/lxd/db/cluster/schema.go
+++ b/lxd/db/cluster/schema.go
@@ -495,5 +495,5 @@ CREATE TABLE storage_volumes_config (
     FOREIGN KEY (storage_volume_id) REFERENCES storage_volumes (id) ON DELETE CASCADE
 );
 
-INSERT INTO schema (version, updated_at) VALUES (24, strftime("%s"))
+INSERT INTO schema (version, updated_at) VALUES (25, strftime("%s"))
 `
diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go
index 7b9763a238..43691eb38b 100644
--- a/lxd/db/cluster/update.go
+++ b/lxd/db/cluster/update.go
@@ -60,6 +60,38 @@ var updates = map[int]schema.Update{
 	22: updateFromV21,
 	23: updateFromV22,
 	24: updateFromV23,
+	25: updateFromV24,
+}
+
+// The ceph.user.name config key is required for Ceph to function.
+func updateFromV24(tx *sql.Tx) error {
+	// Fetch the IDs of all existing Ceph pools.
+	poolIDs, err := query.SelectIntegers(tx, `SELECT id FROM storage_pools WHERE driver='ceph'`)
+	if err != nil {
+		return errors.Wrap(err, "Failed to get IDs of current ceph pools")
+	}
+
+	for _, poolID := range poolIDs {
+		// Fetch the config for this Ceph pool.
+		config, err := query.SelectConfig(tx, "storage_pools_config", "storage_pool_id=?", poolID)
+		if err != nil {
+			return errors.Wrap(err, "Failed to fetch of ceph pool config")
+		}
+
+		// Check if already set.
+		_, ok := config["ceph.user.name"]
+		if ok {
+			continue
+		}
+
+		// Add ceph.user.name config entry.
+		_, err = tx.Exec("INSERT INTO storage_pools_config (storage_pool_id, key, value) VALUES (?, 'ceph.user.name', 'ceph')", poolID)
+		if err != nil {
+			return errors.Wrap(err, "Failed to create ceph.user.name config")
+		}
+	}
+
+	return nil
 }
 
 // The lvm.vg_name config key is required for LVM to function.


More information about the lxc-devel mailing list