-
Notifications
You must be signed in to change notification settings - Fork 3
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 #28 from srl-labs/execCmd
Add exec command setting & mapping
- Loading branch information
Showing
4 changed files
with
31 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"nokia_srlinux": "sr_cli", | ||
"cisco_xrd": "/pkg/bin/xr_cli.sh" | ||
} |
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 |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import * as vscode from "vscode"; | ||
import { execCommandInTerminal } from "./command"; | ||
import { ContainerlabNode } from "../containerlabTreeDataProvider"; | ||
import { execCmdMapping } from "../extension"; | ||
|
||
export function attachShell(node: ContainerlabNode) { | ||
if (!node) { | ||
vscode.window.showErrorMessage('No container node selected.'); | ||
return; | ||
} | ||
|
||
const containerId = node.details?.containerId; | ||
const nodeDetails = node.details; | ||
|
||
if(!nodeDetails) { return vscode.window.showErrorMessage("Couldn't fetch node details");} | ||
|
||
const containerId = nodeDetails.containerId; | ||
const containerKind = nodeDetails.kind; | ||
const containerLabel = node.label || "Container"; | ||
|
||
if (!containerId) { | ||
vscode.window.showErrorMessage('No containerId for shell attach.'); | ||
return; | ||
} | ||
if (!containerId) { return vscode.window.showErrorMessage('No containerId for shell attach.');} | ||
if (!containerKind) { return vscode.window.showErrorMessage('No container kind for shell attach.');} | ||
|
||
let execCmd = execCmdMapping[containerKind] || "sh"; | ||
|
||
// Use the sudoEnabledByDefault setting | ||
const config = vscode.workspace.getConfiguration("containerlab"); | ||
const useSudo = config.get<boolean>("sudoEnabledByDefault", true); | ||
|
||
const userExecMapping = config.get("node.execCommandMapping") as { [key: string]: string }; | ||
|
||
execCmd = userExecMapping[containerKind] || execCmd; | ||
|
||
execCommandInTerminal( | ||
`${useSudo ? "sudo " : ""}docker exec -it ${containerId} sh`, | ||
`${useSudo ? "sudo " : ""}docker exec -it ${containerId} ${execCmd}`, | ||
`Shell - ${containerLabel}` | ||
); | ||
} |
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