2018-08-17 03:17:28 +03:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2018-07-18 02:42:00 +03:00
|
|
|
import { ContainerNode } from '../explorer/models/containerNode';
|
2019-02-14 04:28:47 +03:00
|
|
|
import { dockerExplorerProvider } from '../extension';
|
2019-01-17 01:50:16 +03:00
|
|
|
import { docker, ListContainerDescOptions } from './utils/docker-endpoint';
|
2019-02-14 04:28:47 +03:00
|
|
|
import { quickPickContainerOrAll } from './utils/quick-pick-container';
|
2017-08-11 09:17:33 +03:00
|
|
|
|
|
|
|
import vscode = require('vscode');
|
2018-09-05 02:06:04 +03:00
|
|
|
import { IActionContext } from 'vscode-azureextensionui';
|
|
|
|
import { RootNode } from '../explorer/models/rootNode';
|
2017-08-11 09:17:33 +03:00
|
|
|
|
2018-09-05 02:06:04 +03:00
|
|
|
export async function stopContainer(actionContext: IActionContext, context: RootNode | ContainerNode | undefined): Promise<void> {
|
2017-08-11 09:17:33 +03:00
|
|
|
let containersToStop: Docker.ContainerDesc[];
|
|
|
|
|
2018-09-05 02:06:04 +03:00
|
|
|
if (context instanceof ContainerNode && context.containerDesc) {
|
2017-08-11 09:17:33 +03:00
|
|
|
containersToStop = [context.containerDesc];
|
|
|
|
} else {
|
2019-01-17 01:50:16 +03:00
|
|
|
const opts: ListContainerDescOptions = {
|
2017-08-11 09:17:33 +03:00
|
|
|
"filters": {
|
|
|
|
"status": ["restarting", "running", "paused"]
|
2016-09-20 19:47:56 +03:00
|
|
|
}
|
2017-08-11 09:17:33 +03:00
|
|
|
};
|
2019-01-17 01:50:16 +03:00
|
|
|
containersToStop = await quickPickContainerOrAll(actionContext, opts);
|
2017-08-11 09:17:33 +03:00
|
|
|
}
|
|
|
|
|
2019-01-17 01:50:16 +03:00
|
|
|
const numContainers: number = containersToStop.length;
|
|
|
|
let containerCounter: number = 0;
|
2017-08-11 09:17:33 +03:00
|
|
|
|
2019-01-17 01:50:16 +03:00
|
|
|
vscode.window.setStatusBarMessage("Docker: Stopping Container(s)...", new Promise((resolve, reject) => {
|
|
|
|
containersToStop.forEach((c) => {
|
|
|
|
// tslint:disable-next-line:no-function-expression no-any // Grandfathered in
|
|
|
|
docker.getContainer(c.Id).stop(function (err: Error, _data: any): void {
|
|
|
|
containerCounter++;
|
|
|
|
if (err) {
|
|
|
|
vscode.window.showErrorMessage(err.message);
|
|
|
|
dockerExplorerProvider.refreshContainers();
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
if (containerCounter === numContainers) {
|
|
|
|
dockerExplorerProvider.refreshContainers();
|
|
|
|
resolve();
|
|
|
|
}
|
2017-08-11 09:17:33 +03:00
|
|
|
});
|
2019-01-17 01:50:16 +03:00
|
|
|
});
|
|
|
|
}));
|
2018-07-07 02:49:46 +03:00
|
|
|
}
|