Skip to content

Commit

Permalink
lxd: Update copy op response body when source is snapshot (canonical#…
Browse files Browse the repository at this point in the history
…14139)

This PR updates the copy operation response body when using a snapshot
as the source. Previously, the response body allocated the snapshot to
`resources.instances` and `resources.containers`. This is not entirely
accurate, so we now check to see if the source is a snapshot, and if so,
we allocate it to `resources.instances_snapshots` instead of
`resources.instances` and `resources.containers`.

Closes canonical#13999.
  • Loading branch information
tomponline authored Sep 23, 2024
2 parents abbd18a + baa4e78 commit 57cc91c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lxd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,14 @@ func createFromCopy(s *state.State, r *http.Request, projectName string, profile
}

resources := map[string][]api.URL{}
resources["instances"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", req.Name), *api.NewURL().Path(version.APIVersion, "instances", req.Source.Source)}
resources["instances"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", req.Name)}

if shared.IsSnapshot(req.Source.Source) {
cName, sName, _ := api.GetParentAndSnapshotName(req.Source.Source)
resources["instances_snapshots"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", cName, "snapshots", sName)}
} else {
resources["instances"] = append(resources["instances"], *api.NewURL().Path(version.APIVersion, "instances", req.Source.Source))
}

if dbType == instancetype.Container {
resources["containers"] = resources["instances"]
Expand Down

0 comments on commit 57cc91c

Please sign in to comment.