[lxc-devel] [lxd/master] lxd init: allow rerunning
brauner on Github
lxc-bot at linuxcontainers.org
Tue Feb 28 11:12:19 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170228/72bdacd7/attachment.bin>
-------------- next part --------------
From 0248e3044d0497ac48a585aec24e8a6ccba3e95e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 28 Feb 2017 12:11:15 +0100
Subject: [PATCH] lxd init: allow rerunning
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/main_init.go | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/lxd/main_init.go b/lxd/main_init.go
index 7dbe75c..9755b8f 100644
--- a/lxd/main_init.go
+++ b/lxd/main_init.go
@@ -169,11 +169,11 @@ func cmdInit() error {
return fmt.Errorf("Unable to list the LXD images: %s", err)
}
- if len(containers) > 0 || len(images) > 0 {
- return fmt.Errorf("You have existing containers or images. lxd init requires an empty LXD.")
- }
-
if *argAuto {
+ if len(containers) > 0 || len(images) > 0 {
+ return fmt.Errorf("You have existing containers or images. lxd auto init requires an empty LXD.")
+ }
+
if *argStorageBackend == "" {
*argStorageBackend = "dir"
}
@@ -227,9 +227,20 @@ func cmdInit() error {
defaultStorage = "zfs"
}
+ // User chose an already existing storage pool name. Ask him
+ // again if he still wants to create one.
+ askAgain:
storageSetup = askBool("Do you want to configure a new storage pool (yes/no) [default=yes]? ", "yes")
if storageSetup {
storagePool = askString("Name of the new storage pool [default=default]: ", "default", nil)
+ _, err := c.StoragePoolGet(storagePool)
+ if err == nil {
+ fmt.Printf("The requested storage pool \"%s\" already exists. Please choose another name.\n", storagePool)
+ // Ask the user again if hew wants to create a
+ // storage pool.
+ goto askAgain
+ }
+
storageBackend = askChoice(fmt.Sprintf("Name of the storage backend to use (dir or zfs) [default=%s]: ", defaultStorage), backendsSupported, defaultStorage)
if !shared.StringInSlice(storageBackend, backendsSupported) {
@@ -389,10 +400,15 @@ they otherwise would.
return err
}
- props := []string{"path=/", fmt.Sprintf("pool=%s", storagePool)}
- _, err = c.ProfileDeviceAdd("default", "root", "disk", props)
- if err != nil {
- return err
+ // When lxd init is rerun and there are still containers or
+ // images do not try to set a root disk device in the default
+ // profile again. Let the user figure this out.
+ if len(containers) == 0 && len(images) == 0 {
+ props := []string{"path=/", fmt.Sprintf("pool=%s", storagePool)}
+ _, err = c.ProfileDeviceAdd("default", "root", "disk", props)
+ if err != nil {
+ return err
+ }
}
}
More information about the lxc-devel
mailing list