[lxc-devel] [lxd/master] lxd/init: Better handle disk sizes

stgraber on Github lxc-bot at linuxcontainers.org
Wed Nov 21 17:04:52 UTC 2018


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/20181121/49286498/attachment.bin>
-------------- next part --------------
From 669a53ffcf16824ad5dcae33d4b8b45b48ef2e73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 21 Nov 2018 11:59:06 -0500
Subject: [PATCH] lxd/init: Better handle disk sizes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #5295

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_init_interactive.go | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index de51bbd69d..c087326a4f 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -7,6 +7,7 @@ import (
 	"net"
 	"os"
 	"os/exec"
+	"strconv"
 	"strings"
 	"syscall"
 
@@ -520,8 +521,27 @@ func (c *cmdInit) askStoragePool(config *cmdInitData, d lxd.ContainerServer, poo
 					defaultSize = 15
 				}
 
-				pool.Config["size"] = fmt.Sprintf("%dGB", cli.AskInt(
-					fmt.Sprintf("Size in GB of the new loop device (1GB minimum) [default=%dGB]: ", defaultSize), 1, -1, fmt.Sprintf("%d", defaultSize)))
+				pool.Config["size"] = cli.AskString(
+					fmt.Sprintf("Size in GB of the new loop device (1GB minimum) [default=%dGB]: ", defaultSize),
+					fmt.Sprintf("%dGB", defaultSize),
+					func(input string) error {
+						input = strings.Split(input, "GB")[0]
+
+						result, err := strconv.ParseInt(input, 10, 64)
+						if err != nil {
+							return err
+						}
+
+						if result < 1 {
+							return fmt.Errorf("Minimum size is 1GB")
+						}
+
+						return nil
+					})
+
+				if !strings.HasSuffix(pool.Config["size"], "GB") {
+					pool.Config["size"] = fmt.Sprintf("%sGB", pool.Config["size"])
+				}
 			}
 		} else {
 			if pool.Driver == "ceph" {


More information about the lxc-devel mailing list