@@ -150,6 +150,12 @@ 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 ) hasSnapshot () bool {
158
+ return cfg .Snapshot .MemFilePath != "" || cfg .Snapshot .SnapshotPath != ""
153
159
}
154
160
155
161
// Validate will ensure that the required fields are set and that
@@ -722,6 +728,17 @@ func (m *Machine) captureFifoToFileWithChannel(ctx context.Context, logger *log.
722
728
}
723
729
724
730
func (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
+
725
742
resp , err := m .client .PutMachineConfiguration (ctx , & m .Cfg .MachineCfg )
726
743
if err != nil {
727
744
m .logger .Errorf ("PutMachineConfiguration returned %s" , resp .Error ())
@@ -738,6 +755,10 @@ func (m *Machine) createMachine(ctx context.Context) error {
738
755
}
739
756
740
757
func (m * Machine ) createBootSource (ctx context.Context , imagePath , initrdPath , kernelArgs string ) error {
758
+ if m .Cfg .hasSnapshot () {
759
+ return nil
760
+ }
761
+
741
762
bsrc := models.BootSource {
742
763
KernelImagePath : & imagePath ,
743
764
InitrdPath : initrdPath ,
@@ -845,6 +866,10 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
845
866
}
846
867
847
868
func (m * Machine ) startInstance (ctx context.Context ) error {
869
+ if m .Cfg .hasSnapshot () {
870
+ return nil
871
+ }
872
+
848
873
action := models .InstanceActionInfoActionTypeInstanceStart
849
874
info := models.InstanceActionInfo {
850
875
ActionType : & action ,
@@ -1096,22 +1121,6 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
1096
1121
return nil
1097
1122
}
1098
1123
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
-
1115
1124
// CreateBalloon creates a balloon device if one does not exist
1116
1125
func (m * Machine ) CreateBalloon (ctx context.Context , amountMib int64 , deflateOnOom bool , statsPollingIntervals int64 , opts ... PutBalloonOpt ) error {
1117
1126
balloon := models.Balloon {
0 commit comments