@@ -27,7 +27,12 @@ import (
27
27
"github.com/sirupsen/logrus"
28
28
)
29
29
30
- func startVM (ctx context.Context , driver * driver.BaseDriver ) (* vz.VirtualMachine , chan error , error ) {
30
+ type virtualMachineWrapper struct {
31
+ * vz.VirtualMachine
32
+ stopped bool
33
+ }
34
+
35
+ func startVM (ctx context.Context , driver * driver.BaseDriver ) (* virtualMachineWrapper , chan error , error ) {
31
36
server , client , err := createSockPair ()
32
37
if err != nil {
33
38
return nil , nil , err
@@ -55,6 +60,8 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
55
60
return nil , nil , err
56
61
}
57
62
63
+ wrapper := & virtualMachineWrapper {VirtualMachine : machine , stopped : false }
64
+
58
65
errCh := make (chan error )
59
66
go func () {
60
67
//Handle errors via errCh and handle stop vm during context close
@@ -83,6 +90,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
83
90
logrus .Info ("[VZ] - vm state change: running" )
84
91
case vz .VirtualMachineStateStopped :
85
92
logrus .Info ("[VZ] - vm state change: stopped" )
93
+ wrapper .stopped = true
86
94
errCh <- errors .New ("vz driver state stopped" )
87
95
default :
88
96
logrus .Debugf ("[VZ] - vm state change: %q" , newState )
@@ -91,7 +99,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
91
99
}
92
100
}()
93
101
94
- return machine , errCh , err
102
+ return wrapper , errCh , err
95
103
}
96
104
97
105
func createVM (driver * driver.BaseDriver , networkConn * os.File ) (* vz.VirtualMachine , error ) {
0 commit comments