2018-07-18 02:42:00 +03:00
|
|
|
import { dockerExplorerProvider } from '../dockerExtension';
|
|
|
|
import { ContainerNode } from '../explorer/models/containerNode';
|
|
|
|
import { reporter } from '../telemetry/telemetry';
|
2017-03-02 04:49:54 +03:00
|
|
|
import { docker } from './utils/docker-endpoint';
|
|
|
|
import { ContainerItem, quickPickContainer } from './utils/quick-pick-container';
|
2017-08-11 09:17:33 +03:00
|
|
|
|
|
|
|
import vscode = require('vscode');
|
|
|
|
|
2017-03-04 04:13:14 +03:00
|
|
|
const teleCmdId: string = 'vscode-docker.container.stop';
|
2016-09-14 08:20:20 +03:00
|
|
|
|
2018-07-18 02:41:39 +03:00
|
|
|
export async function stopContainer(context?: ContainerNode): Promise<void> {
|
2017-08-11 09:17:33 +03:00
|
|
|
|
|
|
|
let containersToStop: Docker.ContainerDesc[];
|
|
|
|
|
|
|
|
if (context && context.containerDesc) {
|
|
|
|
containersToStop = [context.containerDesc];
|
|
|
|
} else {
|
|
|
|
const opts = {
|
|
|
|
"filters": {
|
|
|
|
"status": ["restarting", "running", "paused"]
|
2016-09-20 19:47:56 +03:00
|
|
|
}
|
2017-08-11 09:17:33 +03:00
|
|
|
};
|
|
|
|
const selectedItem: ContainerItem = await quickPickContainer(true, opts);
|
|
|
|
if (selectedItem) {
|
|
|
|
if (selectedItem.label.toLowerCase().includes('all containers')) {
|
|
|
|
containersToStop = await docker.getContainerDescriptors(opts);
|
|
|
|
} else {
|
|
|
|
containersToStop = [selectedItem.containerDesc];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (containersToStop) {
|
|
|
|
|
|
|
|
const numContainers: number = containersToStop.length;
|
|
|
|
let containerCounter: number = 0;
|
|
|
|
|
|
|
|
vscode.window.setStatusBarMessage("Docker: Stopping Container(s)...", new Promise((resolve, reject) => {
|
|
|
|
containersToStop.forEach((c) => {
|
2018-07-14 00:16:56 +03:00
|
|
|
// tslint:disable-next-line:no-function-expression // Grandfathered in
|
2018-07-18 02:41:39 +03:00
|
|
|
docker.getContainer(c.Id).stop(function (err: Error, data: any): void {
|
2017-08-11 09:17:33 +03:00
|
|
|
containerCounter++;
|
|
|
|
if (err) {
|
|
|
|
vscode.window.showErrorMessage(err.message);
|
2017-09-28 05:46:01 +03:00
|
|
|
dockerExplorerProvider.refreshContainers();
|
2017-08-11 09:17:33 +03:00
|
|
|
reject();
|
|
|
|
}
|
|
|
|
if (containerCounter === numContainers) {
|
2017-09-28 05:46:01 +03:00
|
|
|
dockerExplorerProvider.refreshContainers();
|
2017-08-11 09:17:33 +03:00
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (reporter) {
|
2017-11-25 07:11:19 +03:00
|
|
|
/* __GDPR__
|
|
|
|
"command" : {
|
|
|
|
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
|
|
|
|
}
|
|
|
|
*/
|
2017-08-11 09:17:33 +03:00
|
|
|
reporter.sendTelemetryEvent('command', {
|
|
|
|
command: teleCmdId
|
|
|
|
});
|
2016-09-14 08:20:20 +03:00
|
|
|
}
|
2017-06-06 03:55:05 +03:00
|
|
|
}
|
2018-07-07 02:49:46 +03:00
|
|
|
}
|