This repository was archived by the owner on Apr 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathStopContainer.cs
62 lines (54 loc) · 1.89 KB
/
StopContainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Management.Automation;
using Docker.PowerShell.Objects;
using Docker.DotNet.Models;
using System.Threading.Tasks;
namespace Docker.PowerShell.Cmdlets
{
[Cmdlet(VerbsLifecycle.Stop, "Container",
DefaultParameterSetName = CommonParameterSetNames.Default)]
[OutputType(typeof(ContainerListResponse))]
public class StopContainer : MultiContainerOperationCmdlet
{
#region Parameters
/// <summary>
/// Whether or not to force the termination of the container.
/// </summary>
[Parameter]
public SwitchParameter Force { get; set; }
/// <summary>
/// If specified, the resulting container object will be output after it has finished
/// starting.
/// </summary>
[Parameter]
public SwitchParameter PassThru { get; set; }
#endregion
#region Overrides
protected override async Task ProcessRecordAsync()
{
foreach (var id in ParameterResolvers.GetContainerIds(Container, Id))
{
if (Force.ToBool())
{
await DkrClient.Containers.KillContainerAsync(
id,
new ContainerKillParameters());
}
else
{
if (!await DkrClient.Containers.StopContainerAsync(
id,
new ContainerStopParameters(),
CmdletCancellationToken))
{
throw new ApplicationFailedException("The container has already stopped.");
}
}
if (PassThru.ToBool())
{
WriteObject(await ContainerOperations.GetContainerByIdOrName(id, DkrClient));
}
}
}
#endregion
}
}