...
1
2
3 package hcs
4
5 import (
6 "context"
7 "sync"
8
9 "github.com/Microsoft/go-winio/pkg/guid"
10 "github.com/Microsoft/hcsshim/internal/hcs"
11 hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
12 "github.com/Microsoft/hcsshim/internal/vm"
13 "github.com/pkg/errors"
14 "golang.org/x/sys/windows"
15 )
16
17 var _ vm.UVM = &utilityVM{}
18
19 type utilityVM struct {
20 id string
21 guestOS vm.GuestOS
22 cs *hcs.System
23 backingType vm.MemoryBackingType
24 vmmemProcess windows.Handle
25 vmmemErr error
26 vmmemOnce sync.Once
27 vmID guid.GUID
28 }
29
30 func (uvm *utilityVM) ID() string {
31 return uvm.id
32 }
33
34 func (uvm *utilityVM) Start(ctx context.Context) (err error) {
35 if err := uvm.cs.Start(ctx); err != nil {
36 return errors.Wrap(err, "failed to start utility VM")
37 }
38 return nil
39 }
40
41 func (uvm *utilityVM) Stop(ctx context.Context) error {
42 if err := uvm.cs.Terminate(ctx); err != nil {
43 return errors.Wrap(err, "failed to terminate utility VM")
44 }
45 return nil
46 }
47
48 func (uvm *utilityVM) Pause(ctx context.Context) error {
49 if err := uvm.cs.Pause(ctx); err != nil {
50 return errors.Wrap(err, "failed to pause utility VM")
51 }
52 return nil
53 }
54
55 func (uvm *utilityVM) Resume(ctx context.Context) error {
56 if err := uvm.cs.Resume(ctx); err != nil {
57 return errors.Wrap(err, "failed to resume utility VM")
58 }
59 return nil
60 }
61
62 func (uvm *utilityVM) Save(ctx context.Context) error {
63 saveOptions := hcsschema.SaveOptions{
64 SaveType: "AsTemplate",
65 }
66 if err := uvm.cs.Save(ctx, saveOptions); err != nil {
67 return errors.Wrap(err, "failed to save utility VM state")
68 }
69 return nil
70 }
71
72 func (uvm *utilityVM) Wait() error {
73 return uvm.cs.Wait()
74 }
75
76 func (uvm *utilityVM) ExitError() error {
77 return uvm.cs.ExitError()
78 }
79
View as plain text