...
1
2
3 package computestorage
4
5 import (
6 "context"
7 "encoding/json"
8
9 "github.com/Microsoft/hcsshim/internal/oc"
10 "github.com/Microsoft/hcsshim/osversion"
11 "github.com/pkg/errors"
12 "go.opencensus.io/trace"
13 "golang.org/x/sys/windows"
14 )
15
16
17
18
19
20
21
22
23
24
25 func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) {
26 title := "hcsshim::SetupBaseOSLayer"
27 ctx, span := oc.StartSpan(ctx, title)
28 defer span.End()
29 defer func() { oc.SetSpanStatus(span, err) }()
30 span.AddAttributes(
31 trace.StringAttribute("layerPath", layerPath),
32 )
33
34 bytes, err := json.Marshal(options)
35 if err != nil {
36 return err
37 }
38
39 err = hcsSetupBaseOSLayer(layerPath, vhdHandle, string(bytes))
40 if err != nil {
41 return errors.Wrap(err, "failed to setup base OS layer")
42 }
43 return nil
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57 func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, options OsLayerOptions) (err error) {
58 if osversion.Build() < 19645 {
59 return errors.New("SetupBaseOSVolume is not present on builds older than 19645")
60 }
61 title := "hcsshim::SetupBaseOSVolume"
62 ctx, span := oc.StartSpan(ctx, title)
63 defer span.End()
64 defer func() { oc.SetSpanStatus(span, err) }()
65 span.AddAttributes(
66 trace.StringAttribute("layerPath", layerPath),
67 trace.StringAttribute("volumePath", volumePath),
68 )
69
70 bytes, err := json.Marshal(options)
71 if err != nil {
72 return err
73 }
74
75 err = hcsSetupBaseOSVolume(layerPath, volumePath, string(bytes))
76 if err != nil {
77 return errors.Wrap(err, "failed to setup base OS layer")
78 }
79 return nil
80 }
81
View as plain text