Skip to content

Commit

Permalink
incusd/instance: Set operations on snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Aug 5, 2024
1 parent 865c85d commit 7c9292f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/incusd/instance_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions cmd/incusd/instance_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 7c9292f

Please sign in to comment.