Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/snapshot/snapshot.go
2609 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package snapshot
5
6
import (
7
"context"
8
"fmt"
9
10
"github.com/lima-vm/lima/v2/pkg/driverutil"
11
"github.com/lima-vm/lima/v2/pkg/limatype"
12
)
13
14
func Del(ctx context.Context, inst *limatype.Instance, tag string) error {
15
limaDriver, err := driverutil.CreateConfiguredDriver(inst, 0)
16
if err != nil {
17
return fmt.Errorf("failed to create driver instance: %w", err)
18
}
19
20
return limaDriver.DeleteSnapshot(ctx, tag)
21
}
22
23
func Save(ctx context.Context, inst *limatype.Instance, tag string) error {
24
limaDriver, err := driverutil.CreateConfiguredDriver(inst, 0)
25
if err != nil {
26
return fmt.Errorf("failed to create driver instance: %w", err)
27
}
28
return limaDriver.CreateSnapshot(ctx, tag)
29
}
30
31
func Load(ctx context.Context, inst *limatype.Instance, tag string) error {
32
limaDriver, err := driverutil.CreateConfiguredDriver(inst, 0)
33
if err != nil {
34
return fmt.Errorf("failed to create driver instance: %w", err)
35
}
36
return limaDriver.ApplySnapshot(ctx, tag)
37
}
38
39
func List(ctx context.Context, inst *limatype.Instance) (string, error) {
40
limaDriver, err := driverutil.CreateConfiguredDriver(inst, 0)
41
if err != nil {
42
return "", fmt.Errorf("failed to create driver instance: %w", err)
43
}
44
45
return limaDriver.ListSnapshots(ctx)
46
}
47
48