Skip to content

Commit 4af1b25

Browse files
Gabriel Ionescugbionescu
authored andcommitted
add load snapshot implementation
This commit adds implementation for the LoadSnapshot API call. Signed-off-by: Gabriel Ionescu <gbi@amazon.com> Signed-off-by: Gabriel Ionescu <plp.github@gmail.com>
1 parent b18499f commit 4af1b25

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

firecracker.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ func (f *Client) CreateSnapshot(ctx context.Context, snapshotParams *models.Snap
265265
return f.client.Operations.CreateSnapshot(params)
266266
}
267267

268+
// LoadSnapshotOpt is a functional option to be used for the
269+
// LoadSnapshot API in setting any additional optional fields.
270+
type LoadSnapshotOpt func(*ops.LoadSnapshotParams)
271+
272+
// LoadSnapshot is a wrapper for the swagger generated client to make
273+
// calling of the API easier.
274+
func (f *Client) LoadSnapshot(ctx context.Context, snapshotParams *models.SnapshotLoadParams, opts ...LoadSnapshotOpt) (*ops.LoadSnapshotNoContent, error) {
275+
params := ops.NewLoadSnapshotParamsWithContext(ctx)
276+
params.SetBody(snapshotParams)
277+
278+
for _, opt := range opts {
279+
opt(params)
280+
}
281+
282+
return f.client.Operations.LoadSnapshot(params)
283+
}
284+
268285
// CreateSyncActionOpt is a functional option to be used for the
269286
// CreateSyncAction API in setting any additional optional fields.
270287
type CreateSyncActionOpt func(*ops.CreateSyncActionParams)

machine.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,26 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
10851085
return nil
10861086
}
10871087

1088+
// LoadSnapshot load a snapshot
1089+
func (m *Machine) LoadSnapshot(ctx context.Context, memFilePath, snapshotPath string, opts ...LoadSnapshotOpt) error {
1090+
snapshotParams := &models.SnapshotLoadParams{
1091+
MemFilePath: String(memFilePath),
1092+
SnapshotPath: String(snapshotPath),
1093+
}
1094+
1095+
if _, err := m.client.LoadSnapshot(ctx, snapshotParams, opts...); err != nil {
1096+
m.logger.Errorf("failed to load a snapshot for VM: %v", err)
1097+
return err
1098+
}
1099+
1100+
m.logger.Debug("snapshot loaded successfully")
1101+
return nil
1102+
}
1103+
10881104
// CreateBalloon creates a balloon device if one does not exist
10891105
func (m *Machine) CreateBalloon(ctx context.Context, amountMib int64, deflateOnOom bool, statsPollingIntervals int64, opts ...PutBalloonOpt) error {
10901106
balloon := models.Balloon{
1091-
AmountMib: &amountMib,
1107+
AmountMib: &amountMib,
10921108
DeflateOnOom: &deflateOnOom,
10931109
StatsPollingIntervals: statsPollingIntervals,
10941110
}

0 commit comments

Comments
 (0)