From 7c9292f57d9288c44faa5691e9a23ccd85c8a954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 5 Aug 2024 00:07:56 -0400 Subject: [PATCH] incusd/instance: Set operations on snapshot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- cmd/incusd/instance_put.go | 7 +++++-- cmd/incusd/instance_snapshot.go | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/incusd/instance_put.go b/cmd/incusd/instance_put.go index 2e43e329b2f..0bb22c8e57f 100644 --- a/cmd/incusd/instance_put.go +++ b/cmd/incusd/instance_put.go @@ -182,7 +182,7 @@ func instancePut(d *Daemon, r *http.Request) response.Response { do = func(op *operations.Operation) error { defer unlock() - return instanceSnapRestore(s, projectName, name, configRaw.Restore, configRaw.Stateful) + return instanceSnapRestore(s, projectName, name, configRaw.Restore, configRaw.Stateful, op) } opType = operationtype.SnapshotRestore @@ -200,7 +200,7 @@ func instancePut(d *Daemon, r *http.Request) response.Response { return operations.OperationResponse(op) } -func instanceSnapRestore(s *state.State, projectName string, name string, snap string, stateful bool) error { +func instanceSnapRestore(s *state.State, projectName string, name string, snap string, stateful bool, op *operations.Operation) error { // normalize snapshot name if !internalInstance.IsSnapshot(snap) { snap = name + internalInstance.SnapshotDelimiter + snap @@ -211,6 +211,8 @@ func instanceSnapRestore(s *state.State, projectName string, name string, snap s return err } + inst.SetOperation(op) + source, err := instance.LoadByProjectAndName(s, projectName, snap) if err != nil { switch { @@ -220,6 +222,7 @@ func instanceSnapRestore(s *state.State, projectName string, name string, snap s return err } } + source.SetOperation(op) // Generate a new `volatile.uuid.generation` to differentiate this instance restored from a snapshot from the original instance. source.LocalConfig()["volatile.uuid.generation"] = uuid.New().String() diff --git a/cmd/incusd/instance_snapshot.go b/cmd/incusd/instance_snapshot.go index 29c73ffc5db..f8c24c94f4b 100644 --- a/cmd/incusd/instance_snapshot.go +++ b/cmd/incusd/instance_snapshot.go @@ -506,6 +506,8 @@ func snapshotPut(s *state.State, r *http.Request, snapInst instance.Instance) re // Update instance configuration do = func(op *operations.Operation) error { + snapInst.SetOperation(op) + args := db.InstanceArgs{ Architecture: snapInst.Architecture(), Config: snapInst.LocalConfig(), @@ -684,6 +686,7 @@ func snapshotPost(s *state.State, r *http.Request, snapInst instance.Instance) r resources["instances_snapshots"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", parentName, "snapshots", snapName)} run := func(op *operations.Operation) error { + ws.instance.SetOperation(op) return ws.Do(s, op) } @@ -733,6 +736,7 @@ func snapshotPost(s *state.State, r *http.Request, snapInst instance.Instance) r } rename := func(op *operations.Operation) error { + snapInst.SetOperation(op) return snapInst.Rename(fullName, false) } @@ -776,6 +780,7 @@ func snapshotPost(s *state.State, r *http.Request, snapInst instance.Instance) r // $ref: "#/responses/InternalServerError" func snapshotDelete(s *state.State, r *http.Request, snapInst instance.Instance) response.Response { remove := func(op *operations.Operation) error { + snapInst.SetOperation(op) return snapInst.Delete(false) }