[lxc-devel] [lxd/master] Clustering questions

stgraber on Github lxc-bot at linuxcontainers.org
Thu Mar 29 21:45:15 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180329/ff6bf236/attachment.bin>
-------------- next part --------------
From 95dd45815495e7ef3a7307d74a436429d02736df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 29 Mar 2018 17:14:21 -0400
Subject: [PATCH 1/2] lxd/init: Improve storage configuration questions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_init.go             | 13 +++++++++--
 lxd/main_init_auto.go        |  2 +-
 lxd/main_init_interactive.go | 51 ++++++++++++++++++++++++++++++++++++++------
 3 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/lxd/main_init.go b/lxd/main_init.go
index 06fd19bd4..6ed65867a 100644
--- a/lxd/main_init.go
+++ b/lxd/main_init.go
@@ -117,8 +117,8 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
 	return c.ApplyConfig(cmd, args, d, *config)
 }
 
-func (c *cmdInit) availableStorageDrivers() []string {
-	drivers := []string{"dir"}
+func (c *cmdInit) availableStorageDrivers(poolType string) []string {
+	drivers := []string{}
 
 	backingFs, err := util.FilesystemDetect(shared.VarPath())
 	if err != nil {
@@ -127,7 +127,16 @@ func (c *cmdInit) availableStorageDrivers() []string {
 
 	// Check available backends
 	for _, driver := range supportedStoragePoolDrivers {
+		if poolType == "remote" && driver != "ceph" {
+			continue
+		}
+
+		if poolType == "local" && driver == "ceph" {
+			continue
+		}
+
 		if driver == "dir" {
+			drivers = append(drivers, driver)
 			continue
 		}
 
diff --git a/lxd/main_init_auto.go b/lxd/main_init_auto.go
index 432838a67..94389956b 100644
--- a/lxd/main_init_auto.go
+++ b/lxd/main_init_auto.go
@@ -17,7 +17,7 @@ func (c *cmdInit) RunAuto(cmd *cobra.Command, args []string, d lxd.ContainerServ
 		return nil, fmt.Errorf("The requested backend '%s' isn't supported by lxd init", c.flagStorageBackend)
 	}
 
-	if c.flagStorageBackend != "" && !shared.StringInSlice(c.flagStorageBackend, c.availableStorageDrivers()) {
+	if c.flagStorageBackend != "" && !shared.StringInSlice(c.flagStorageBackend, c.availableStorageDrivers("all")) {
 		return nil, fmt.Errorf("The requested backend '%s' isn't available on your system (missing tools)", c.flagStorageBackend)
 	}
 
diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index 8094fad65..06830ab40 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -328,12 +328,38 @@ func (c *cmdInit) askNetworking(config *initData, d lxd.ContainerServer) error {
 }
 
 func (c *cmdInit) askStorage(config *initData, d lxd.ContainerServer) error {
+	if config.Cluster != nil {
+		if cli.AskBool("Do you want to configure a new local storage pool (yes/no) [default=yes]? ", "yes") {
+			err := c.askStoragePool(config, d, "local")
+			if err != nil {
+				return err
+			}
+		}
+
+		if cli.AskBool("Do you want to configure a new remote storage pool (yes/no) [default=yes]? ", "yes") {
+			err := c.askStoragePool(config, d, "remote")
+			if err != nil {
+				return err
+			}
+		}
+
+		return nil
+	}
+
 	if !cli.AskBool("Do you want to configure a new storage pool (yes/no) [default=yes]? ", "yes") {
 		return nil
 	}
 
+	return c.askStoragePool(config, d, "all")
+}
+
+func (c *cmdInit) askStoragePool(config *initData, d lxd.ContainerServer, poolType string) error {
 	// Figure out the preferred storage driver
-	availableBackends := c.availableStorageDrivers()
+	availableBackends := c.availableStorageDrivers(poolType)
+
+	if len(availableBackends) == 0 {
+		return fmt.Errorf("No %s storage backends available", poolType)
+	}
 
 	backingFs, err := util.FilesystemDetect(shared.VarPath())
 	if err != nil {
@@ -354,11 +380,20 @@ func (c *cmdInit) askStorage(config *initData, d lxd.ContainerServer) error {
 		pool := api.StoragePoolsPost{}
 		pool.Config = map[string]string{}
 
-		pool.Name = cli.AskString("Name of the new storage pool [default=default]: ", "default", nil)
+		if poolType == "all" {
+			pool.Name = cli.AskString("Name of the new storage pool [default=default]: ", "default", nil)
+		} else {
+			pool.Name = poolType
+		}
+
 		_, _, err := d.GetStoragePool(pool.Name)
 		if err == nil {
-			fmt.Printf("The requested storage pool \"%s\" already exists. Please choose another name.\n", pool.Name)
-			continue
+			if poolType == "all" {
+				fmt.Printf("The requested storage pool \"%s\" already exists. Please choose another name.\n", pool.Name)
+				continue
+			}
+
+			return fmt.Errorf("The %s storage pool already exists", poolType)
 		}
 
 		// Add to the default profile
@@ -369,8 +404,12 @@ func (c *cmdInit) askStorage(config *initData, d lxd.ContainerServer) error {
 		}
 
 		// Storage backend
-		pool.Driver = cli.AskChoice(
-			fmt.Sprintf("Name of the storage backend to use (%s) [default=%s]: ", strings.Join(availableBackends, ", "), defaultStorage), availableBackends, defaultStorage)
+		if len(availableBackends) > 1 {
+			pool.Driver = cli.AskChoice(
+				fmt.Sprintf("Name of the storage backend to use (%s) [default=%s]: ", strings.Join(availableBackends, ", "), defaultStorage), availableBackends, defaultStorage)
+		} else {
+			pool.Driver = availableBackends[0]
+		}
 
 		// Optimization for dir
 		if pool.Driver == "dir" {

From 035cd3d401a0f993393d04461400e6f6e8d03b6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 29 Mar 2018 17:32:21 -0400
Subject: [PATCH 2/2] lxd/init: Add MAAS integration questions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_init_interactive.go    | 27 +++++++++++++++++++++++++++
 test/suites/init_interactive.sh |  1 +
 2 files changed, 28 insertions(+)

diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index 06830ab40..f48116899 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -52,6 +52,12 @@ func (c *cmdInit) RunInteractive(cmd *cobra.Command, args []string, d lxd.Contai
 			return nil, err
 		}
 
+		// MAAS
+		err = c.askMAAS(&config, d)
+		if err != nil {
+			return nil, err
+		}
+
 		// Networking
 		err = c.askNetworking(&config, d)
 		if err != nil {
@@ -239,6 +245,27 @@ func (c *cmdInit) askClustering(config *initData, d lxd.ContainerServer) error {
 	return nil
 }
 
+func (c *cmdInit) askMAAS(config *initData, d lxd.ContainerServer) error {
+	if !cli.AskBool("Would you like to connect to a MAAS server (yes/no) [default=no]? ", "no") {
+		return nil
+	}
+
+	serverName, err := os.Hostname()
+	if err != nil {
+		serverName = "lxd"
+	}
+
+	maasHostname := cli.AskString("What's the name of this host in MAAS? [default=%s]? ", serverName, nil)
+	if maasHostname != serverName {
+		config.Config["maas.machine"] = maasHostname
+	}
+
+	config.Config["maas.api.url"] = cli.AskString("What's the URL of your MAAS server? ", "", nil)
+	config.Config["maas.api.key"] = cli.AskString("What's a valid API key for your MAAS server? ", "", nil)
+
+	return nil
+}
+
 func (c *cmdInit) askNetworking(config *initData, d lxd.ContainerServer) error {
 	if !cli.AskBool("Would you like to create a new network bridge (yes/no) [default=yes]? ", "yes") {
 		if cli.AskBool("Would you like to configure LXD to use an existing bridge or host interface (yes/no) [default=no]? ", "no") {
diff --git a/test/suites/init_interactive.sh b/test/suites/init_interactive.sh
index 2ebc0fcc7..284710de0 100644
--- a/test/suites/init_interactive.sh
+++ b/test/suites/init_interactive.sh
@@ -20,6 +20,7 @@ no
 yes
 my-storage-pool
 dir
+no
 yes
 lxdt$$
 auto


More information about the lxc-devel mailing list