Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command to create the simplest network #1350

Merged
merged 3 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1697,6 +1703,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