Skip to content

Commit e9fee53

Browse files
torbbanghellt
andauthored
Add snapshot save/restore functionality for vrnetlab nodes (#2904)
Adds snapshot functionality for vrnetlab-based VMs: - `clab tools snapshot save` - Save VM snapshots - `clab deploy --restore-all` - Restore from snapshots directory - `clab deploy --restore node=path` - Restore specific nodes Snapshots capture full VM state for fast restoration. Non-vrnetlab nodes are automatically skipped. Vrnetlab part of this PR - srl-labs/vrnetlab#403 --------- Co-authored-by: Roman Dodin <[email protected]>
1 parent 9c75281 commit e9fee53

File tree

11 files changed

+688
-9
lines changed

11 files changed

+688
-9
lines changed

.github/workflows/build-containerlab.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-24.04
1313
steps:
1414
- uses: actions/checkout@v5
15-
- uses: WillAbides/setup-go[email protected]
15+
- uses: actions/setup-go@v6
1616
with:
1717
go-version: ${{ inputs.go_ver }}
1818

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v5
20-
- uses: WillAbides/setup-go[email protected]
20+
- uses: actions/setup-go@v6
2121
with:
2222
go-version: ${{ inputs.go_ver }}
2323

cmd/deploy.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ func deployCmd(o *Options) (*cobra.Command, error) { //nolint: funlen
129129
"lab owner name (only for users in clab_admins group)",
130130
)
131131

132+
c.Flags().StringVar(
133+
&o.Deploy.RestoreAll,
134+
"restore-all",
135+
"",
136+
"restore all nodes that have snapshots in this directory (default: ./snapshots)",
137+
)
138+
// Allow flag without value to default to ./snapshots
139+
c.Flags().Lookup("restore-all").NoOptDefVal = "./snapshots"
140+
141+
c.Flags().StringArrayVar(
142+
&o.Deploy.RestoreNodeSnapshots,
143+
"restore",
144+
nil,
145+
"restore specific node from snapshot file (format: node=path/to/snapshot.tar). "+
146+
"Can be specified multiple times. Overrides --restore-all for specified nodes.",
147+
)
148+
132149
return c, nil
133150
}
134151

@@ -157,7 +174,9 @@ func deployFn(cobraCmd *cobra.Command, o *Options) error {
157174
SetReconfigure(o.Deploy.Reconfigure).
158175
SetGraph(o.Deploy.GenerateGraph).
159176
SetSkipPostDeploy(o.Deploy.SkipPostDeploy).
160-
SetSkipLabDirFileACLs(o.Deploy.SkipLabDirectoryFileACLs)
177+
SetSkipLabDirFileACLs(o.Deploy.SkipLabDirectoryFileACLs).
178+
SetRestoreAll(o.Deploy.RestoreAll).
179+
SetRestoreNodeSnapshots(o.Deploy.RestoreNodeSnapshots)
161180

162181
containers, err := c.Deploy(cobraCmd.Context(), deploymentOptions)
163182
if err != nil {

cmd/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func GetOptions() *Options {
107107
SrcPort: 0,
108108
DeletionPrefix: "vx-",
109109
},
110+
ToolsSnapshot: &ToolsSnapshotOptions{
111+
OutputDir: "./snapshots",
112+
Format: "table",
113+
Timeout: 5 * time.Minute,
114+
MaxConcurrent: 0,
115+
},
110116
Version: &VersionOptions{
111117
Short: false,
112118
JSON: false,
@@ -135,6 +141,7 @@ type Options struct {
135141
ToolsSSHX *ToolsSSHXOptions
136142
ToolsVeth *ToolsVethOptions
137143
ToolsVxlan *ToolsVxlanOptions
144+
ToolsSnapshot *ToolsSnapshotOptions
138145
Version *VersionOptions
139146
}
140147

@@ -282,6 +289,8 @@ type DeployOptions struct {
282289
SkipLabDirectoryFileACLs bool
283290
ExportTemplate string
284291
LabOwner string
292+
RestoreAll string
293+
RestoreNodeSnapshots []string
285294
}
286295

287296
func (o *DeployOptions) toClabOptions() []clabcore.ClabOption {
@@ -456,6 +465,13 @@ type ToolsVxlanOptions struct {
456465
DeletionPrefix string
457466
}
458467

468+
type ToolsSnapshotOptions struct {
469+
OutputDir string
470+
Format string
471+
Timeout time.Duration
472+
MaxConcurrent int
473+
}
474+
459475
type VersionOptions struct {
460476
Short bool
461477
JSON bool

cmd/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func toolsSubcommandRegisterFuncs() []func(*Options) (*cobra.Command, error) {
1919
disableTxOffloadCmd,
2020
gottyCmd,
2121
netemCmd,
22+
snapshotCmd,
2223
sshxCmd,
2324
vethCmd,
2425
vxlanCmd,

0 commit comments

Comments
 (0)