lxd icon indicating copy to clipboard operation
lxd copied to clipboard

Improve resources data for create instance from copy operation

Open mas-who opened this issue 5 months ago • 1 comments

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.

mas-who avatar Aug 28 '24 11:08 mas-who