@@ -150,6 +150,12 @@ 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 ) hasSnapshot () bool  {
158+ 	return  cfg .Snapshot .MemFilePath  !=  ""  ||  cfg .Snapshot .SnapshotPath  !=  "" 
153159}
154160
155161// Validate will ensure that the required fields are set and that 
@@ -722,6 +728,17 @@ func (m *Machine) captureFifoToFileWithChannel(ctx context.Context, logger *log.
722728}
723729
724730func  (m  * Machine ) createMachine (ctx  context.Context ) error  {
731+ 	ss  :=  m .Cfg .Snapshot 
732+ 	if  ss .SnapshotPath  !=  ""  ||  ss .MemFilePath  !=  ""  {
733+ 		_ , err  :=  m .client .LoadSnapshot (ctx , & models.SnapshotLoadParams {
734+ 			SnapshotPath :        String (ss .SnapshotPath ),
735+ 			MemFilePath :         String (ss .MemFilePath ),
736+ 			EnableDiffSnapshots : ss .EnableDiffSnapshots ,
737+ 			ResumeVM :            ss .ResumeVM ,
738+ 		})
739+ 		return  err 
740+ 	}
741+ 
725742	resp , err  :=  m .client .PutMachineConfiguration (ctx , & m .Cfg .MachineCfg )
726743	if  err  !=  nil  {
727744		m .logger .Errorf ("PutMachineConfiguration returned %s" , resp .Error ())
@@ -738,6 +755,10 @@ func (m *Machine) createMachine(ctx context.Context) error {
738755}
739756
740757func  (m  * Machine ) createBootSource (ctx  context.Context , imagePath , initrdPath , kernelArgs  string ) error  {
758+ 	if  m .Cfg .hasSnapshot () {
759+ 		return  nil 
760+ 	}
761+ 
741762	bsrc  :=  models.BootSource {
742763		KernelImagePath : & imagePath ,
743764		InitrdPath :      initrdPath ,
@@ -845,6 +866,10 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
845866}
846867
847868func  (m  * Machine ) startInstance (ctx  context.Context ) error  {
869+ 	if  m .Cfg .hasSnapshot () {
870+ 		return  nil 
871+ 	}
872+ 
848873	action  :=  models .InstanceActionInfoActionTypeInstanceStart 
849874	info  :=  models.InstanceActionInfo {
850875		ActionType : & action ,
@@ -1096,22 +1121,6 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
10961121	return  nil 
10971122}
10981123
1099- // LoadSnapshot load a snapshot 
1100- func  (m  * Machine ) LoadSnapshot (ctx  context.Context , memFilePath , snapshotPath  string , opts  ... LoadSnapshotOpt ) error  {
1101- 	snapshotParams  :=  & models.SnapshotLoadParams {
1102- 		MemFilePath :  String (memFilePath ),
1103- 		SnapshotPath : String (snapshotPath ),
1104- 	}
1105- 
1106- 	if  _ , err  :=  m .client .LoadSnapshot (ctx , snapshotParams , opts ... ); err  !=  nil  {
1107- 		m .logger .Errorf ("failed to load a snapshot for VM: %v" , err )
1108- 		return  err 
1109- 	}
1110- 
1111- 	m .logger .Debug ("snapshot loaded successfully" )
1112- 	return  nil 
1113- }
1114- 
11151124// CreateBalloon creates a balloon device if one does not exist 
11161125func  (m  * Machine ) CreateBalloon (ctx  context.Context , amountMib  int64 , deflateOnOom  bool , statsPollingIntervals  int64 , opts  ... PutBalloonOpt ) error  {
11171126	balloon  :=  models.Balloon {
0 commit comments