Skip to content

Commit

Permalink
Add a command to create the simplest network (#1350)
Browse files Browse the repository at this point in the history
* Add a command to create the simplest network
  • Loading branch information
stuartthomson authored and bwateratmsft committed Oct 22, 2019
1 parent f89cf97 commit 561a574
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"onCommand:vscode-docker.images.runInteractive",
"onCommand:vscode-docker.images.tag",
"onCommand:vscode-docker.networks.configureExplorer",
"onCommand:vscode-docker.networks.create",
"onCommand:vscode-docker.networks.inspect",
"onCommand:vscode-docker.networks.prune",
"onCommand:vscode-docker.networks.refresh",
Expand Down Expand Up @@ -221,10 +222,15 @@
"group": "navigation@9"
},
{
"command": "vscode-docker.networks.prune",
"command": "vscode-docker.networks.create",
"when": "view == dockerNetworks",
"group": "navigation@1"
},
{
"command": "vscode-docker.networks.prune",
"when": "view == dockerNetworks",
"group": "navigation@2"
},
{
"command": "vscode-docker.networks.refresh",
"when": "view == dockerNetworks",
Expand Down Expand Up @@ -1701,6 +1707,15 @@
"dark": "resources/dark/settings.svg"
}
},
{
"command": "vscode-docker.networks.create",
"title": "Create...",
"category": "Docker Networks",
"icon": {
"light": "resources/light/add.svg",
"dark": "resources/dark/add.svg"
}
},
{
"command": "vscode-docker.networks.inspect",
"title": "Inspect",
Expand Down
3 changes: 3 additions & 0 deletions resources/dark/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/light/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/commands/networks/createNetwork.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { window } from 'vscode';
import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { wrapDockerodeENOENT } from '../../utils/wrapError';

export async function createNetwork(_context: IActionContext): Promise<void> {

const name = await ext.ui.showInputBox({
value: '',
prompt: 'Name of the network'
});

const driverSelection = await ext.ui.showQuickPick(
[
{ label: 'bridge' },
{ label: 'host' },
{ label: 'overlay' },
{ label: 'macvlan' }
],
{
canPickMany: false,
placeHolder: 'Select the network driver to use (default is "bridge").'
}
);

const result = <{ id: string }>await wrapDockerodeENOENT(() => ext.dockerode.createNetwork({ Name: name, Driver: driverSelection.label }));

window.showInformationMessage(`Network Created with ID ${result.id.substr(0, 12)}`);
}
2 changes: 2 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { runAzureCliImage } from "./images/runAzureCliImage";
import { runImage, runImageInteractive } from "./images/runImage";
import { tagImage } from "./images/tagImage";
import { configureNetworksExplorer } from "./networks/configureNetworksExplorer";
import { createNetwork } from "./networks/createNetwork";
import { inspectNetwork } from "./networks/inspectNetwork";
import { pruneNetworks } from "./networks/pruneNetworks";
import { removeNetwork } from "./networks/removeNetwork";
Expand Down Expand Up @@ -88,6 +89,7 @@ export function registerCommands(): void {
registerCommand('vscode-docker.images.tag', tagImage);

registerCommand('vscode-docker.networks.configureExplorer', configureNetworksExplorer);
registerCommand('vscode-docker.networks.create', createNetwork);
registerCommand('vscode-docker.networks.inspect', inspectNetwork);
registerCommand('vscode-docker.networks.remove', removeNetwork);
registerCommand('vscode-docker.networks.prune', pruneNetworks);
Expand Down

0 comments on commit 561a574

Please sign in to comment.