@@ -150,6 +150,22 @@ type Config struct {
150150 // It is possible to use a valid IPv4 link-local address (169.254.0.0/16).
151151 // If not provided, the default address (169.254.169.254) will be used.
152152 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
153169}
154170
155171// Validate will ensure that the required fields are set and that
@@ -159,6 +175,11 @@ func (cfg *Config) Validate() error {
159175 return nil
160176 }
161177
178+ ss := cfg .Snapshot
179+ if ss .SnapshotPath != "" || ss .MemFilePath != "" {
180+ return cfg .validateSnapshot ()
181+ }
182+
162183 if _ , err := os .Stat (cfg .KernelImagePath ); err != nil {
163184 return fmt .Errorf ("failed to stat kernel image path, %q: %v" , cfg .KernelImagePath , err )
164185 }
@@ -718,6 +739,17 @@ func (m *Machine) captureFifoToFileWithChannel(ctx context.Context, logger *log.
718739}
719740
720741func (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+
721753 resp , err := m .client .PutMachineConfiguration (ctx , & m .Cfg .MachineCfg )
722754 if err != nil {
723755 m .logger .Errorf ("PutMachineConfiguration returned %s" , resp .Error ())
@@ -734,6 +766,11 @@ func (m *Machine) createMachine(ctx context.Context) error {
734766}
735767
736768func (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+
737774 bsrc := models.BootSource {
738775 KernelImagePath : & imagePath ,
739776 InitrdPath : initrdPath ,
@@ -841,6 +878,10 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
841878}
842879
843880func (m * Machine ) startInstance (ctx context.Context ) error {
881+ if m .Cfg .Snapshot .SnapshotPath != "" || m .Cfg .Snapshot .MemFilePath != "" {
882+ return nil
883+ }
884+
844885 action := models .InstanceActionInfoActionTypeInstanceStart
845886 info := models.InstanceActionInfo {
846887 ActionType : & action ,
0 commit comments