/// <summary>
        /// Creates a new container and lists it to output.
        /// </summary>
        protected override async Task ProcessRecordAsync()
        {
            foreach (var id in ParameterResolvers.GetImageIds(Image, ImageIdOrName))
            {
                var createResult = await ContainerOperations.CreateContainer(
                    id,
                    this.MemberwiseClone() as CreateContainerCmdlet,
                    DkrClient);

                if (createResult.Warnings != null)
                {
                    foreach (var w in createResult.Warnings)
                    {
                        if (!String.IsNullOrEmpty(w))
                        {
                            WriteWarning(w);
                        }
                    }
                }

                if (!String.IsNullOrEmpty(createResult.ID))
                {
                    WriteObject((await ContainerOperations.GetContainersById(createResult.ID, DkrClient)).Single());
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Outputs container objects for each container matching the provided parameters.
 /// </summary>
 protected override async Task ProcessRecordAsync()
 {
     if (Id != null)
     {
         foreach (var id in Id)
         {
             WriteObject(await ContainerOperations.GetContainersById(id, DkrClient));
         }
     }
     else if (Name != null)
     {
         foreach (var name in Name)
         {
             WriteObject(await ContainerOperations.GetContainersByName(name, DkrClient));
         }
     }
     else
     {
         foreach (var c in await DkrClient.Containers.ListContainersAsync(
                      new ContainersListParameters()
         {
             All = true
         }))
         {
             WriteObject(c);
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Creates a new container and lists it to output.
        /// </summary>
        protected override async Task ProcessRecordAsync()
        {
            foreach (var id in ParameterResolvers.GetImageIds(Image, ImageIdOrName))
            {
                var createResult = await ContainerOperations.CreateContainer(
                    id,
                    this.MemberwiseClone() as CreateContainerCmdlet,
                    DkrClient);

                if (createResult.Warnings != null)
                {
                    foreach (var w in createResult.Warnings)
                    {
                        if (!String.IsNullOrEmpty(w))
                        {
                            WriteWarning(w);
                        }
                    }
                }

                if (!String.IsNullOrEmpty(createResult.ID))
                {
                    ContainerAttachParameters attachParams = null;
                    if (!Detach)
                    {
                        attachParams = new ContainerAttachParameters
                        {
                            Stdin  = Input,
                            Stdout = true,
                            Stderr = true,
                            Stream = true
                        };
                    }

                    await ContainerOperations.StartContainerAsync(
                        this.DkrClient,
                        createResult.ID,
                        attachParams,
                        this.Terminal,
                        null,
                        this.CmdletCancellationToken);

                    if (RemoveAutomatically && !Detach)
                    {
                        await DkrClient.Containers.RemoveContainerAsync(createResult.ID,
                                                                        new ContainerRemoveParameters());
                    }
                    else if (PassThru)
                    {
                        WriteObject((await ContainerOperations.GetContainersById(createResult.ID, DkrClient)).Single());
                    }
                }
            }
        }
Exemple #4
0
    public IEnumerable <CompletionResult> CompleteArgument(string commandName,
                                                           string parameterName,
                                                           string wordToComplete,
                                                           CommandAst commandAst,
                                                           IDictionary fakeBoundParameters)
    {
        var client = DockerFactory.CreateClient(fakeBoundParameters);
        IList <ContainerListResponse> result;

        if (wordToComplete == "")
        {
            result = client.Containers.ListContainersAsync(new ContainersListParameters
            {
                All = true
            }).Result;
        }
        else
        {
            result = ContainerOperations.GetContainersById(wordToComplete, client).Result;
            result = result.Concat(ContainerOperations.GetContainersByName(wordToComplete, client).Result).ToList();
        }

        return(result.SelectMany(container =>
        {
            // If the user has already typed part of the name, then include IDs that start
            // with that portion. Otherwise, just let the user tab through the names.

            // Special handling for Get-Container, where Id an Name are separate parameters.
            if (commandName == "Get-Container" && parameterName == "Id")
            {
                return new List <string> {
                    container.ID
                };
            }
            else if (wordToComplete == "" || parameterName == "Name")
            {
                return container.Names;
            }
            else
            {
                return container.Names.Concat(new List <string> {
                    container.ID
                });
            }
        })
               .Select(name => name.StartsWith("/") && !wordToComplete.StartsWith("/") ? name.Substring(1) : name)
               .Distinct()
               .Where(name => name.StartsWith(wordToComplete, StringComparison.CurrentCultureIgnoreCase))
               .OrderBy(name => name)
               .Select(name => new CompletionResult(name, name, CompletionResultType.Text, name)));
    }
Exemple #5
0
        /// <summary>
        /// Creates a new container and lists it to output.
        /// </summary>
        protected override async Task ProcessRecordAsync()
        {
            foreach (var id in ParameterResolvers.GetImageIds(Image, Id))
            {
                var createResult = await ContainerOperations.CreateContainer(
                    id,
                    this.MemberwiseClone() as CreateContainerCmdlet,
                    DkrClient);

                if (createResult.Warnings != null)
                {
                    foreach (var w in createResult.Warnings)
                    {
                        if (!String.IsNullOrEmpty(w))
                        {
                            WriteWarning(w);
                        }
                    }
                }

                if (!String.IsNullOrEmpty(createResult.ID))
                {
                    if (!await DkrClient.Containers.StartContainerAsync(
                            createResult.ID, HostConfiguration))
                    {
                        throw new ApplicationFailedException("The container has already started.");
                    }

                    var waitResponse = await DkrClient.Containers.WaitContainerAsync(
                        createResult.ID,
                        CmdletCancellationToken);

                    WriteVerbose("Status Code: " + waitResponse.StatusCode.ToString());
                    ContainerOperations.ThrowOnProcessExitCode(waitResponse.StatusCode);

                    if (RemoveAutomatically.ToBool())
                    {
                        await DkrClient.Containers.RemoveContainerAsync(createResult.ID,
                                                                        new ContainerRemoveParameters());
                    }
                    else if (PassThru.ToBool())
                    {
                        WriteObject((await ContainerOperations.GetContainersById(createResult.ID, DkrClient)).Single());
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new container and lists it to output.
        /// </summary>
        protected override async Task ProcessRecordAsync()
        {
            foreach (var id in ParameterResolvers.GetImageIds(Image, Id))
            {
                var createResult = await ContainerOperations.CreateContainer(
                    id,
                    this.MemberwiseClone() as CreateContainerCmdlet,
                    DkrClient);

                if (createResult.Warnings != null)
                {
                    foreach (var w in createResult.Warnings)
                    {
                        if (!String.IsNullOrEmpty(w))
                        {
                            WriteWarning(w);
                        }
                    }
                }

                if (!String.IsNullOrEmpty(createResult.ID))
                {
                    MultiplexedStream stream = null;
                    Task streamTask          = null;
                    try
                    {
                        if (!Detach)
                        {
                            var parameters = new ContainerAttachParameters
                            {
                                Stdin  = Input,
                                Stdout = true,
                                Stderr = true,
                                Stream = true
                            };

                            stream = await DkrClient.Containers.AttachContainerAsync(createResult.ID, Terminal, parameters, CmdletCancellationToken);

                            streamTask = stream.CopyToConsoleAsync(Terminal, Input, CmdletCancellationToken);
                        }

                        if (!await DkrClient.Containers.StartContainerAsync(createResult.ID, new ContainerStartParameters()))
                        {
                            throw new ApplicationFailedException("The container has already started.");
                        }

                        if (!Detach)
                        {
                            await streamTask;
                        }
                    }
                    finally
                    {
                        stream?.Dispose();
                    }

                    if (RemoveAutomatically && !Detach)
                    {
                        await DkrClient.Containers.RemoveContainerAsync(createResult.ID,
                                                                        new ContainerRemoveParameters());
                    }
                    else if (PassThru)
                    {
                        WriteObject((await ContainerOperations.GetContainersById(createResult.ID, DkrClient)).Single());
                    }
                }
            }
        }