-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from srl-labs/save
add save commands for lab and node configurations
- Loading branch information
Showing
6 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// src/commands/save.ts | ||
import * as vscode from "vscode"; | ||
import { SpinnerMsg } from "./command"; | ||
import { ClabCommand } from "./clabCommand"; | ||
import { ClabLabTreeNode, ClabContainerTreeNode } from "../clabTreeDataProvider"; | ||
import * as path from "path"; | ||
|
||
/** | ||
* Save the entire lab configuration. | ||
* Executes: containerlab -t <labPath> save | ||
*/ | ||
export async function saveLab(node: ClabLabTreeNode) { | ||
if (!node) { | ||
vscode.window.showErrorMessage("No lab node selected."); | ||
return; | ||
} | ||
const labPath = node.labPath && node.labPath.absolute; | ||
if (!labPath) { | ||
vscode.window.showErrorMessage("No labPath found for the lab."); | ||
return; | ||
} | ||
|
||
const spinnerMessages: SpinnerMsg = { | ||
progressMsg: `Saving lab configuration for ${node.label}...`, | ||
successMsg: `Lab configuration for ${node.label} saved successfully!`, | ||
failMsg: `Could not save lab configuration for ${node.label}` | ||
}; | ||
|
||
// Create a ClabCommand for "save" using the lab node. | ||
const saveCmd = new ClabCommand("save", node, spinnerMessages); | ||
// ClabCommand automatically appends "-t <labPath>". | ||
saveCmd.run(); | ||
} | ||
|
||
/** | ||
* Save the configuration for a specific container node. | ||
* Executes: containerlab -t <labPath> save --node-filter <shortNodeName> | ||
*/ | ||
export async function saveNode(node: ClabContainerTreeNode) { | ||
if (!node) { | ||
vscode.window.showErrorMessage("No container node selected."); | ||
return; | ||
} | ||
|
||
if (!node.labPath || !node.labPath.absolute) { | ||
vscode.window.showErrorMessage("Error: Could not determine lab path for this node."); | ||
return; | ||
} | ||
|
||
// Extract the short node name by removing the "clab-{labname}-" prefix | ||
const shortNodeName = node.name.replace(/^clab-[^-]+-/, ''); | ||
|
||
const spinnerMessages: SpinnerMsg = { | ||
progressMsg: `Saving configuration for node ${shortNodeName}...`, | ||
successMsg: `Configuration for node ${shortNodeName} saved successfully!`, | ||
failMsg: `Could not save configuration for node ${shortNodeName}` | ||
}; | ||
|
||
const tempLabNode = new ClabLabTreeNode( | ||
path.basename(node.labPath.absolute), | ||
vscode.TreeItemCollapsibleState.None, | ||
node.labPath, | ||
undefined, | ||
undefined, | ||
undefined, | ||
"containerlabLabDeployed" | ||
); | ||
|
||
const saveCmd = new ClabCommand("save", tempLabNode, spinnerMessages); | ||
// Use --node-filter instead of -n and use the short name | ||
saveCmd.run(["--node-filter", shortNodeName]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.