[lxc-devel] [lxd/master] lxc/project: Check existence on switch

stgraber on Github lxc-bot at linuxcontainers.org
Mon Nov 19 21:57:24 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181119/b9ea617b/attachment.bin>
-------------- next part --------------
From 85268314f2bb82789eb9643e1da440698438d555 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 19 Nov 2018 16:56:59 -0500
Subject: [PATCH] lxc/project: Check existence on switch
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>
---
 lxc/project.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lxc/project.go b/lxc/project.go
index efd6c8b210..641305ce10 100644
--- a/lxc/project.go
+++ b/lxc/project.go
@@ -690,12 +690,23 @@ func (c *cmdProjectSwitch) Run(cmd *cobra.Command, args []string) error {
 		project = args[1]
 	}
 
-	// make sure the remote exists
+	// Make sure the remote exists
 	rc, ok := conf.Remotes[remote]
 	if !ok {
 		return fmt.Errorf(i18n.G("Remote %s doesn't exist"), remote)
 	}
 
+	// Make sure the project exists
+	d, err := conf.GetContainerServer(remote)
+	if err != nil {
+		return err
+	}
+
+	_, _, err = d.GetProject(project)
+	if err != nil {
+		return err
+	}
+
 	rc.Project = project
 
 	conf.Remotes[remote] = rc


More information about the lxc-devel mailing list