@@ -150,6 +150,22 @@ type Config struct {
150
150
// It is possible to use a valid IPv4 link-local address (169.254.0.0/16).
151
151
// If not provided, the default address (169.254.169.254) will be used.
152
152
MmdsAddress net.IP
153
+
154
+ Snapshot SnapshotConfig
155
+ }
156
+
157
+ func (cfg * Config ) validateSnapshot () error {
158
+ ss := cfg .Snapshot
159
+
160
+ if _ , err := os .Stat (ss .MemFilePath ); err != nil {
161
+ return fmt .Errorf ("failed to stat snapshot memory file path, %q: %v" , cfg .KernelImagePath , err )
162
+ }
163
+
164
+ if _ , err := os .Stat (ss .SnapshotPath ); err != nil {
165
+ return fmt .Errorf ("failed to stat snapshot file path, %q: %v" , cfg .InitrdPath , err )
166
+ }
167
+
168
+ return nil
153
169
}
154
170
155
171
// Validate will ensure that the required fields are set and that
@@ -159,6 +175,11 @@ func (cfg *Config) Validate() error {
159
175
return nil
160
176
}
161
177
178
+ ss := cfg .Snapshot
179
+ if ss .SnapshotPath != "" || ss .MemFilePath != "" {
180
+ return cfg .validateSnapshot ()
181
+ }
182
+
162
183
if _ , err := os .Stat (cfg .KernelImagePath ); err != nil {
163
184
return fmt .Errorf ("failed to stat kernel image path, %q: %v" , cfg .KernelImagePath , err )
164
185
}
@@ -718,6 +739,17 @@ func (m *Machine) captureFifoToFileWithChannel(ctx context.Context, logger *log.
718
739
}
719
740
720
741
func (m * Machine ) createMachine (ctx context.Context ) error {
742
+ ss := m .Cfg .Snapshot
743
+ if ss .SnapshotPath != "" || ss .MemFilePath != "" {
744
+ _ , err := m .client .LoadSnapshot (ctx , & models.SnapshotLoadParams {
745
+ SnapshotPath : String (ss .SnapshotPath ),
746
+ MemFilePath : String (ss .MemFilePath ),
747
+ EnableDiffSnapshots : ss .EnableDiffSnapshots ,
748
+ ResumeVM : ss .ResumeVM ,
749
+ })
750
+ return err
751
+ }
752
+
721
753
resp , err := m .client .PutMachineConfiguration (ctx , & m .Cfg .MachineCfg )
722
754
if err != nil {
723
755
m .logger .Errorf ("PutMachineConfiguration returned %s" , resp .Error ())
@@ -734,6 +766,11 @@ func (m *Machine) createMachine(ctx context.Context) error {
734
766
}
735
767
736
768
func (m * Machine ) createBootSource (ctx context.Context , imagePath , initrdPath , kernelArgs string ) error {
769
+ ss := m .Cfg .Snapshot
770
+ if ss .SnapshotPath != "" || ss .MemFilePath != "" {
771
+ return nil
772
+ }
773
+
737
774
bsrc := models.BootSource {
738
775
KernelImagePath : & imagePath ,
739
776
InitrdPath : initrdPath ,
@@ -841,6 +878,10 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
841
878
}
842
879
843
880
func (m * Machine ) startInstance (ctx context.Context ) error {
881
+ if m .Cfg .Snapshot .SnapshotPath != "" || m .Cfg .Snapshot .MemFilePath != "" {
882
+ return nil
883
+ }
884
+
844
885
action := models .InstanceActionInfoActionTypeInstanceStart
845
886
info := models.InstanceActionInfo {
846
887
ActionType : & action ,
0 commit comments