[lxc-devel] [lxd/master] Consider the container's project when loading profiles in containerLoadAllInternal

freeekanayaka on Github lxc-bot at linuxcontainers.org
Mon Oct 29 08:41:31 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 418 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181029/85d2ac55/attachment.bin>
-------------- next part --------------
From 35b1b9a5031e9a7712c1c0bab999275b62e7b9bd Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Mon, 29 Oct 2018 09:39:33 +0100
Subject: [PATCH] Consider the container's project when loading profiles in
 containerLoadAllInternal

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/container.go | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index 4eba3930c8..350d9fb8fa 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -1351,24 +1351,31 @@ func containerLoadNodeProjectAll(s *state.State, project string) ([]container, e
 
 func containerLoadAllInternal(cts []db.Container, s *state.State) ([]container, error) {
 	// Figure out what profiles are in use
-	profiles := map[string]api.Profile{}
+	profiles := map[string]map[string]api.Profile{}
 	for _, cArgs := range cts {
+		projectProfiles, ok := profiles[cArgs.Project]
+		if !ok {
+			projectProfiles = map[string]api.Profile{}
+			profiles[cArgs.Project] = projectProfiles
+		}
 		for _, profile := range cArgs.Profiles {
-			_, ok := profiles[profile]
+			_, ok := projectProfiles[profile]
 			if !ok {
-				profiles[profile] = api.Profile{}
+				projectProfiles[profile] = api.Profile{}
 			}
 		}
 	}
 
 	// Get the profile data
-	for name := range profiles {
-		_, profile, err := s.Cluster.ProfileGet("default", name)
-		if err != nil {
-			return nil, err
-		}
+	for project, projectProfiles := range profiles {
+		for name := range projectProfiles {
+			_, profile, err := s.Cluster.ProfileGet(project, name)
+			if err != nil {
+				return nil, err
+			}
 
-		profiles[name] = *profile
+			projectProfiles[name] = *profile
+		}
 	}
 
 	// Load the container structs
@@ -1377,7 +1384,7 @@ func containerLoadAllInternal(cts []db.Container, s *state.State) ([]container,
 		// Figure out the container's profiles
 		cProfiles := []api.Profile{}
 		for _, name := range container.Profiles {
-			cProfiles = append(cProfiles, profiles[name])
+			cProfiles = append(cProfiles, profiles[container.Project][name])
 		}
 
 		args := db.ContainerToArgs(&container)


More information about the lxc-devel mailing list