The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5296

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #5295

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 669a53ffcf16824ad5dcae33d4b8b45b48ef2e73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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" {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to