How to work with different projects¶
If you have more projects than just the default
project, you must make sure to use or address the correct project when working with LXD.
Note
If you have projects that are confined to specific users, only users with full access to LXD can see all projects.
Users without full access can only see information for the projects to which they have access.
List projects¶
To list all projects (that you have permission to see), enter the following command:
lxc project list
By default, the output is presented as a list:
user@host:~$
lxc project list
+----------------------+--------+----------+-----------------+-----------------+----------+---------------+---------------------+---------+
| NAME | IMAGES | PROFILES | STORAGE VOLUMES | STORAGE BUCKETS | NETWORKS | NETWORK ZONES | DESCRIPTION | USED BY |
+----------------------+--------+----------+-----------------+-----------------+----------+---------------+---------------------+---------+
| default | YES | YES | YES | YES | YES | YES | Default LXD project | 19 |
+----------------------+--------+----------+-----------------+-----------------+----------+---------------+---------------------+---------+
| my-project (current) | YES | NO | NO | NO | YES | YES | | 0 |
+----------------------+--------+----------+-----------------+-----------------+----------+---------------+---------------------+---------+
You can request a different output format by adding the --format
flag.
See lxc project list --help
for more information.
To list all projects (that you have permission to see), send the following request:
lxc query --request GET /1.0/projects
To display information about each project, use Recursion:
lxc query --request GET /1.0/projects?recursion=1
See GET /1.0/projects
and GET /1.0/projects?recursion=1
for more information.
To list all projects (that you have permission to see), expand the Project drop-down.
Switch projects¶
By default, all commands that you issue in LXD affect the project that you are currently using.
To see which project you are in, use the lxc project list
command.
To switch to a different project, enter the following command:
lxc project switch <project_name>
The API does not have the concept of switching projects. All requests target the default project unless a different project is specified (see Target a project).
To switch to another project, select a different project from the Project drop-down.
Target a project¶
When using the CLI or the API, you can target a specific project when running a command.
Many LXD commands support the --project
flag or the project
parameter to run an action in a different project.
Note
You can target only projects that you have permission for.
An example for targeting another project instead of switching to it is listing the instances in a specific project:
To list the instances in a specific project, add the --project
flag to the lxc list
command.
For example:
lxc list --project my-project
To list the instances in a specific project, add the project
parameter to the request.
For example:
lxc query --request GET /1.0/instances?project=my-project
Or with Recursion:
lxc query --request GET /1.0/instances?recursion=2\&project=my-project
The UI does not currently support targeting another project. Instead, switch to the other project.
Move an instance to another project¶
To move an instance from one project to another, enter the following command:
lxc move <instance_name> <new_instance_name> --project <source_project> --target-project <target_project>
You can keep the same instance name if no instance with that name exists in the target project.
For example, to move the instance my-instance
from the default
project to my-project
and keep the instance name, enter the following command:
lxc move my-instance my-instance --project default --target-project my-project
To move an instance from one project to another, send a POST request to the instance:
lxc query --request POST /1.0/instances/<instance_name>?project=<source_project> --data '{
"name": "<new_instance_name>",
"project": "<target_project>",
"migration": true
}'
If no instance with that name exists in the target project, you can leave out the name for the new instance to keep the existing name.
For example, to move the instance my-instance
from the default
project to my-project
and keep the instance name, enter the following command:
lxc query --request POST /1.0/instances/my-instance?project=default --data '{
"project": "my-project",
"migration": true
}'
Depending on your projects, you might need to change other configuration options when moving the instance. For example, you might need to change the root disk device if one of the projects uses isolated storage volumes.
See POST /1.0/instances/{name}
for more information.
The UI does not currently support moving instances between projects.
Copy a profile to another project¶
If you create a project with the default settings, profiles are isolated in the project (features.profiles
is set to true
).
Therefore, the project does not have access to the default profile (which is part of the default
project), and you will see an error similar to the following when trying to create an instance:
Error: Failed instance creation: Failed creating instance record: Failed initialising instance: Failed getting root disk: No root device could be found
To fix this, you can copy the contents of the default
project’s default profile into the current project’s default profile.
To do so:
Enter the following command:
lxc profile show default --project default | lxc profile edit default
Send the following request, replacing <project>
with the new project that has an empty default profile:
lxc query --request PUT /1.0/profiles/default?projects=<project> --data \
"$(lxc query --request GET /1.0/profiles/default)"
Select the
default
project from the Project drop-down.Go to Profiles and select the default profile.
In the profile view, switch to the Configuration tab.
Select YAML configuration and copy the YAML representation of the profile.
Select the project with the empty default profile from the Project drop-down.
Go to Profiles and select the empty default profile for the project.
In the profile view, switch to the Configuration tab.
Select YAML configuration and click Edit profile.
Paste the YAML representation that you copied and save the changes.