Enhancement for projects operations

Projects are a great way to logically group together containers and I have started using them as soon as I discovered they exist, a few months ago.

I would like to propose some improvements and collect feedback from other users:

  1. Allow working on a different projects in different terminals, that is define the scope of the project selection. I may need to work on two different projects at the same time, but as for now I need to do a switch operation if I want to issue a command on the other project.

  2. Allow starting and moving containers in other projects without being on that project scope, for example by putting the project name before the container:

Example:

lxc start project-name/container-name

lxc move project-name/container-name project-name-target/container-name

  1. Allow listing all the projects along all the instances. There is already some work on this, details here

  2. Give clear indication to the user of the currently selected project. A good example is Python virtualenv, that puts the environment name in the shell prompt.

It would be great to have some feedback on whether these requests make sense and if there is some effort in developing them.

Thanks!

lxc move --project SOURCE --target-project DESTINATION NAME

That is unfortunately incredibly difficult to do and would be extremely OS specific. We’d need a config overlay which is based on the tty index, that’d be messy to do and for folks to understand and would only really work on Linux (whereas the CLI also works on macOS and Windows).

The closest you could get to that I suspect is by having completely different config dirs and manually setting LXD_CONF in your environment to point to the right one for a particular terminal.

Right, that’s a work in progress, we should have lxc list --all or something that does that soon enough.

You should be able to do something like that by figuring out the right syntax for your shell of choice. For bash, you usually need to set PS1 to some odd escape sequence pattern. The main downside to this is that every single time the prompt is rendered, it will be calling some subcommands, so this can get an extremely high overhead.

I use this to show git branches here (which means git-branch is effectively called every time the prompt renders:

# Prompt syntax
parse_git_branch() {
    BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
    if [ "x$BRANCH" != "x" ]; then
        echo " ${BRANCH}"
    fi
}

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '

Thank you @stgraber for the quick and detailed answers!

To give some context I’m currently using LXD as a provider for Vagrant, leveraging the Vagrant plugin vagrant-lxd.

I also opened an issue for vagrant-lxd to support LXD projects: find it here.

UPDATE (removed old post by accident):
Moving container between projects works if container (running in default project) is stopped before action:

:; lxc stop test-CT
:; lxc move --project default --target-project test test-CT
:; lxc start test-CT
Error: Not Found
:; lxc start --project=test test-CT
:; lxc list --project=test test-CT # Displays it correctly

Regards.