Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define default profile for image #4567

randombenj opened this issue May 16, 2018 · 4 comments


Copy link

@randombenj randombenj commented May 16, 2018

When I launch a new container I can specify which profile it should take instead of the default profile with the -p option:

lxc launch [<remote>:]<image> -p <some profile>

This profile can contain some default network setup (bridge, devices, ...) and the container won't work properly if you don't launch it with the correct profile.

It would be nice if you could specify a custom default profile to take when launching a container from a specific image instead of the real default profile. This could look something like this:

lxc image edit <image>

With the option:

# ...
  default_profile: <profile>
# ...

Of course it would be nice to also include this option in the metadata.yaml file for importing an image

This topic was already mentioned in a linux container discussion thread but I wanted to know if there is anything planed like this.


This comment has been minimized.

Copy link

@stgraber stgraber commented May 18, 2018

That's come up a couple of times. It wouldn't be something that we'd store as part of the image itself as we don't want the image producer to be able to trick users into using a particular profile, but I'd be fine with it being something that the local admin can mark an image with, so that any container created from it after that would use the profiles.

@stgraber stgraber added this to the later milestone May 18, 2018
@stgraber stgraber modified the milestones: later, soon Aug 2, 2018
@stgraber stgraber added the Easy label Oct 3, 2019

This comment has been minimized.

Copy link

@jackstenglein jackstenglein commented Oct 19, 2019


Hello, myself and another student from UT Austin would like to take on this issue for our virtualization class.


This comment has been minimized.

Copy link

@stgraber stgraber commented Oct 20, 2019

Thanks, assigned to you.

For this issue, I think we want to extend the returned image structs to include a list of profiles to apply at creation time if none were provided by the user. When not set, the "default" profile will be assumed.

From a user's point of view, this will be visible in:

  • lxc image info
  • lxc image show
  • lxc image edit

This will show as a new "profiles" field which will default to nil.

There will be three valid values for it:

  • nil (the default, will cause lxd to use the default profile)
  • [] (an empty list indicates no profile will be applied at all, not even the default one)
  • A valid list of profiles, applied in order.

One catch is projects as projects may contain images and profiles but it's not guaranteed that both feature will be used together.

As a result, I think we'll want this list of profiles to be tied to the project and will become tied to the project if it has either the images or profiles feature enabled.

As for how to split this work, I'd suggest the following commits:

  • "api: Add image_profiles extension"
    • Add the entry to shared/version/api.go
    • Add a new section to doc/
  • "doc/image-handling: Add image profiles"
    • Update the documentation to cover the new feature and explain the valid values
  • "shared/api: Add image profiles"
    • Update ImagePut to add the new Profiles field as a slice of string. Add it as the last field of the struct with a suitable API extension comment.
  • "lxd/db: Add images_profiles table"
    • Add a schema extension to create that table. It should have a foreign key to the image, profile and project with cascading enabled.
    • Run make update-schema to generate schema.go
    • Update the image functions to fill the profile list in the struct and to allow setting the list of profiles in the database.
  • "lxd/images: Add support for image profiles"
    • Update lxd/image.go to properly query and update the database based on the content of the Profiles attribute. This is where you'll need to be careful about how projects are handled.
  • "tests: Add test for image profiles"
    • You'll want to add a new suite in test/suites, link it in test/ and have it validate:
    • Normal creation with nothing set
    • Creation with profiles set to empty list
    • Creation with profiles set to a list of alternate profiles
    • Each time, validate the profiles applied on the container.
    • Also test with a project that only has the images feature enabled, then one with only profiles and lastly with one that has both enabled.

One last thing to keep in mind, images can get refreshed by LXD. When this happens, we'll want those profiles to be copied to the new image.

Let me know if you have any questions or run into any problem!


This comment has been minimized.

Copy link

@randombenj randombenj commented Oct 21, 2019

Awesome! 🎊 If you need something mabe I could help with some stuff too.
Or try/test things in our environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.