Skip to content

Commit

Permalink
Set up default root device for new projects
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Bolton <[email protected]>
  • Loading branch information
boltmark committed Jan 21, 2025
1 parent 4741e27 commit cc60bd6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lxd/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,30 @@ func projectCreateDefaultProfile(tx *db.ClusterTx, project string) error {
profile.Name = api.ProjectDefaultName
profile.Description = fmt.Sprintf("Default LXD profile for project %s", project)

_, err := cluster.CreateProfile(context.TODO(), tx.Tx(), profile)
profileID, err := cluster.CreateProfile(context.TODO(), tx.Tx(), profile)
if err != nil {
return fmt.Errorf("Add default profile to database: %w", err)
}

_, defaultProjectDefaultProfile, err := tx.GetProfile(context.TODO(), api.ProjectDefaultName, "default")
if err != nil {
return fmt.Errorf("Retrieve default project: %w", err)
}

rootDev := map[string]string{}
rootDev["path"] = "/"
rootDev["pool"] = defaultProjectDefaultProfile.Devices["root"]["pool"]
device := cluster.Device{
Name: "root",
Type: cluster.TypeDisk,
Config: rootDev,
}

err = cluster.CreateProfileDevices(context.TODO(), tx.Tx(), profileID, map[string]cluster.Device{"root": device})
if err != nil {
return fmt.Errorf("Add root device to default profile of new project: %w", err)
}

return nil
}

Expand Down

0 comments on commit cc60bd6

Please sign in to comment.