@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"flag"
6
7
"fmt"
7
8
"log"
@@ -85,7 +86,15 @@ func runVM(ctx context.Context) error {
85
86
log .Println ("call stop" )
86
87
if err := vm .Stop (); err != nil {
87
88
log .Println ("stop with error" , err )
89
+ return
88
90
}
91
+ // if err := vm.Pause(); err != nil {
92
+ // log.Println("pause with error", err)
93
+ // return
94
+ // }
95
+ // if err := vm.SaveMachineStateToPath("savestate"); err != nil {
96
+ // log.Println("save state with error", err)
97
+ // }
89
98
}
90
99
}
91
100
log .Println ("finished cleanup" )
@@ -173,8 +182,15 @@ func createNetworkDeviceConfiguration() (*vz.VirtioNetworkDeviceConfiguration, e
173
182
return vz .NewVirtioNetworkDeviceConfiguration (natAttachment )
174
183
}
175
184
176
- func createKeyboardConfiguration () (* vz.USBKeyboardConfiguration , error ) {
177
- return vz .NewUSBKeyboardConfiguration ()
185
+ func createKeyboardConfiguration () (vz.KeyboardConfiguration , error ) {
186
+ config , err := vz .NewMacKeyboardConfiguration ()
187
+ if err != nil {
188
+ if errors .Is (err , vz .ErrUnsupportedOSVersion ) {
189
+ return vz .NewUSBKeyboardConfiguration ()
190
+ }
191
+ return nil , err
192
+ }
193
+ return config , nil
178
194
}
179
195
180
196
func createAudioDeviceConfiguration () (* vz.VirtioSoundDeviceConfiguration , error ) {
@@ -293,5 +309,11 @@ func setupVMConfiguration(platformConfig vz.PlatformConfiguration) (*vz.VirtualM
293
309
return nil , fmt .Errorf ("invalid configuration" )
294
310
}
295
311
312
+ // If you want to try this one, you need to comment out a few of configs.
313
+ //
314
+ // if _, err := config.ValidateSaveRestoreSupport(); err != nil {
315
+ // return nil, fmt.Errorf("failed to validate save restore configuration: %w", err)
316
+ // }
317
+
296
318
return config , nil
297
319
}
0 commit comments