canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.32k stars 928 forks source link

Improve resources data for create instance from copy operation #13999

Open mas-who opened 2 weeks ago

mas-who commented 2 weeks ago

Issue description

Currently when making a request to POST /1.0/instances and setting source.type=copy and source.source to the source instance snapshot within the payload, the resulting InstanceCreate operation will allocate the snapshot to resources.instances and resources.containers within the operation response body (see below example).

{
  "running": [
    {
      "id": "388b0be4-b40a-4aa2-9e11-d81e9edb0bdd",
      "class": "task",
      "description": "Creating instance",
      "created_at": "2024-08-27T10:25:22.454012783Z",
      "updated_at": "2024-08-27T10:25:22.454012783Z",
      "status": "Running",
      "status_code": 103,
      "resources": {
        "containers": [
          "/1.0/instances/alpine-2-poopoo-copy",
          "/1.0/instances/alpine-2%2Fpoopoo"
        ],
        "instances": [
          "/1.0/instances/alpine-2-poopoo-copy",
          "/1.0/instances/alpine-2%2Fpoopoo"
        ]
      },
      "metadata": null,
      "may_cancel": false,
      "err": "",
      "location": "none"
    }
  ]
}

I believe this behaviour is caused by this line and introduced in this commit.

IMO this is a bit confusing and the operation can be improved and made more clear if the snapshot is added to the resources.instances_snapshots field instead (similar to how it's done here). We would just need to determine if the source is a snapshot first.

tomponline commented 2 weeks ago

@boltmark care to take a look at this one and see if @mas-who suggestion is viable? Thanks