-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Restart' command for containers. (#152)
Currently user can stop container and remove stopped container from the context menu. To start existing one they need to use console command.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { docker } from './utils/docker-endpoint'; | ||
import { ContainerItem, quickPickContainer } from './utils/quick-pick-container'; | ||
import { reporter } from '../telemetry/telemetry'; | ||
import { ContainerNode } from '../explorer/models/containerNode'; | ||
import { dockerExplorerProvider } from '../dockerExtension'; | ||
|
||
import vscode = require('vscode'); | ||
|
||
const teleCmdId: string = 'vscode-docker.container.restart'; | ||
|
||
|
||
export async function restartContainer(context?: ContainerNode) { | ||
|
||
let containersToRestart: Docker.ContainerDesc[]; | ||
|
||
if (context && context.containerDesc) { | ||
containersToRestart = [context.containerDesc]; | ||
} | ||
else { | ||
const opts = { | ||
"filters": { | ||
"status": ["running", "paused", "exited"] | ||
} | ||
}; | ||
const selectedItem: ContainerItem = await quickPickContainer(true, opts); | ||
if (selectedItem) { | ||
if (selectedItem.label.toLocaleLowerCase().includes("all containers")) { | ||
containersToRestart = await docker.getContainerDescriptors(opts); | ||
} | ||
else { | ||
containersToRestart = [selectedItem.containerDesc]; | ||
} | ||
} | ||
} | ||
|
||
if (containersToRestart) { | ||
|
||
const numContainers: number = containersToRestart.length; | ||
let containerCounter: number = 0; | ||
|
||
vscode.window.setStatusBarMessage("Docker: Restarting Container(s)...", new Promise((resolve, reject) => { | ||
containersToRestart.forEach((container) => { | ||
docker.getContainer(container.Id).restart((err: Error, data: any) => { | ||
containerCounter++; | ||
if (err) { | ||
vscode.window.showErrorMessage(err.message); | ||
dockerExplorerProvider.refreshContainers(); | ||
reject(); | ||
} | ||
if (containerCounter === numContainers) { | ||
dockerExplorerProvider.refreshContainers(); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
})); | ||
|
||
if (reporter) { | ||
reporter.sendTelemetryEvent('command', { | ||
command: teleCmdId | ||
}); | ||
} | ||
} | ||
} |
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