async Task ISwarmOperations.JoinSwarmAsync(SwarmJoinParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var data = new JsonRequestContent <SwarmJoinParameters>(parameters, this._client.JsonSerializer);

            await this._client.MakeRequestAsync(
                new ApiResponseErrorHandlingDelegate[]
            {
                (statusCode, responseBody) =>
                {
                    if (statusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        // TODO: Make typed error.
                        throw new Exception("Node is already part of a swarm.");
                    }
                }
            },
                HttpMethod.Post,
                "swarm/join",
                null,
                data).ConfigureAwait(false);
        }
        public Task <Stream> CopyFromContainerAsync(string id, CopyFromContainerParameters parameters, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Extra check for this field since it's required and API behaves and just returns
            // HTTP 500 Internal Server Error with response body as "EOF" which makes hard to debug.
            if (string.IsNullOrEmpty(parameters.Resource))
            {
                throw new ArgumentException("ResourcePath is empty", "parameters");
            }

            var data = new JsonRequestContent <CopyFromContainerParameters>(parameters, this.Client.JsonSerializer);

            string path = string.Format(CultureInfo.InvariantCulture, "containers/{0}/copy", id);

            return(this.Client.MakeRequestForStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, null, data, cancellationToken));
        }
        public async Task <CreateContainerResponse> CreateContainerAsync(CreateContainerParameters parameters)
        {
            IQueryString qs = null;

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (!string.IsNullOrEmpty(parameters.ContainerName))
            {
                qs = new QueryString <CreateContainerParameters>(parameters);
            }

            string path = "containers/create";
            JsonRequestContent <Config> data = null;

            if (parameters.Config != null)
            {
                data = new JsonRequestContent <Config>(parameters.Config, this.Client.JsonSerializer);
            }
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, qs, data).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <CreateContainerResponse>(response.Body));
        }
Beispiel #4
0
        public Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (authConfig == null)
            {
                throw new ArgumentNullException(nameof(authConfig));
            }
            var data = new JsonRequestContent <AuthConfig>(authConfig, this._client.JsonSerializer);

            return(this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken));
        }
        async Task ISwarmOperations.UnlockSwarmAsync(SwarmUnlockParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var body = new JsonRequestContent <SwarmUnlockParameters>(parameters, this._client.JsonSerializer);

            await this._client.MakeRequestAsync(new [] { SwarmResponseHandler }, HttpMethod.Post, "swarm/unlock", null, body).ConfigureAwait(false);
        }
        public Task AuthenticateAsync(AuthConfigParameters authConfig)
        {
            if (authConfig == null)
            {
                throw new ArgumentNullException(nameof(authConfig));
            }
            var data = new JsonRequestContent <AuthConfigParameters>(authConfig, this.Client.JsonSerializer);

            return(this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Post, "auth", null, data));
        }
        async Task <string> ISwarmOperations.InitSwarmAsync(SwarmInitParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var data     = new JsonRequestContent <SwarmInitParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new [] { SwarmResponseHandler }, HttpMethod.Post, "swarm/init", null, data).ConfigureAwait(false);

            return(response.Body);
        }
        async Task <ServiceCreateResponse> ISwarmOperations.CreateServiceAsync(ServiceCreateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var data     = new JsonRequestContent <ServiceCreateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, "services/create", null, RegistryAuthHeaders(parameters.RegistryAuth), data).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <ServiceCreateResponse>(response.Body));
        }
Beispiel #9
0
        public Task AuthenticateAsync(AuthConfig authConfig)
        {
            if (authConfig == null)
            {
                throw new ArgumentNullException("authConfig");
            }
            var data = new JsonRequestContent <AuthConfig>(authConfig, this.Client.JsonSerializer);

            const string path = "auth";

            return(this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Post, path, null, data));
        }
        async Task <VolumeResponse> IVolumeOperations.CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data     = new JsonRequestContent <VolumesCreateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "volumes/create", null, data, cancellationToken);

            return(this._client.JsonSerializer.DeserializeObject <VolumeResponse>(response.Body));
        }
        async Task <SecretOrConfigCreateResponse> ISecretsOperations.CreateAsync(SecretSpec body, CancellationToken cancellationToken)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            var data     = new JsonRequestContent <SecretSpec>(body, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "secrets/create", null, data, cancellationToken).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <SecretOrConfigCreateResponse>(response.Body));
        }
        public async Task <NetworksCreateResponse> CreateNetworkAsync(NetworksCreateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data     = new JsonRequestContent <NetworksCreateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "networks/create", null, data, null, cancellationToken).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <NetworksCreateResponse>(response.Body));
        }
Beispiel #13
0
        public async Task <VolumeResponse> CreateVolumeAsync(VolumesCreateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data     = new JsonRequestContent <VolumesCreateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "volumes/create", null, data).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <VolumeResponse>(response.Body));
        }
        public async Task <NetworksCreateResponse> CreateNetworkAsync(NetworksCreateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var path     = "networks/create";
            var data     = new JsonRequestContent <NetworksCreateParameters>(parameters, this.Client.JsonSerializer);
            var response = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, path, null, data).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <NetworksCreateResponse>(response.Body));
        }
Beispiel #15
0
        async Task <ServiceUpdateResponse> ISwarmOperations.UpdateServiceAsync(string id, ServiceUpdateParameters parameters, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var query    = new QueryString <ServiceUpdateParameters>(parameters ?? throw new ArgumentNullException(nameof(parameters)));
            var body     = new JsonRequestContent <ServiceUpdateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Post, $"services/{id}", query, RegistryAuthHeaders(parameters.RegistryAuth), body, cancellationToken).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <ServiceUpdateResponse>(response.Body));
        }
Beispiel #16
0
        public async Task <CommitContainerChangesResponse> CommitContainerChangesAsync(CommitContainerChangesParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            JsonRequestContent <Config> data  = parameters.Config == null ? null : new JsonRequestContent <Config>(parameters.Config, this.Client.JsonSerializer);
            const string      path            = "commit";
            IQueryString      queryParameters = new QueryString <CommitContainerChangesParameters>(parameters);
            DockerApiResponse response        = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Post, path, queryParameters, data).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <CommitContainerChangesResponse>(response.Body));
        }
Beispiel #17
0
        // StartContainerExecAsync will start the process specified by id in detach mode with no connected
        // stdin, stdout, or stderr pipes.
        public Task StartContainerExecAsync(string id, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var parameters = new ContainerExecStartParameters
            {
                Detach = true,
            };
            var data = new JsonRequestContent <ContainerExecStartParameters>(parameters, this._client.JsonSerializer);

            return(this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, data, null, cancellationToken));
        }
        public Task DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (string.IsNullOrEmpty(parameters?.Container))
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data = new JsonRequestContent <NetworkDisconnectParameters>(parameters, this._client.JsonSerializer);

            return(this._client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Post, $"networks/{id}/disconnect", null, data, null, cancellationToken));
        }
        async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (parameters.Spec == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var query = new QueryString <SwarmUpdateParameters>(parameters);
            var body  = new JsonRequestContent <Spec>(parameters.Spec, this._client.JsonSerializer);

            await this._client.MakeRequestAsync(new [] { SwarmResponseHandler }, HttpMethod.Post, "swarm/update", query, body).ConfigureAwait(false);
        }
Beispiel #20
0
        public async Task <ContainerExecCreateResponse> ExecCreateContainerAsync(string id, ContainerExecCreateParameters parameters)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data     = new JsonRequestContent <ContainerExecCreateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/exec", null, data).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <ContainerExecCreateResponse>(response.Body));
        }
        public Task DisconnectNetworkAsync(string id, NetworkDisconnectParameters parameters)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (string.IsNullOrEmpty(parameters?.Container))
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var path = $"networks/{id}/disconnect";
            var data = new JsonRequestContent <NetworkDisconnectParameters>(parameters, this.Client.JsonSerializer);

            return(this.Client.MakeRequestAsync(new[] { NoSuchNetworkHandler }, HttpMethod.Get, path, null, data));
        }
        public async Task <ContainerUpdateResponse> UpdateContainerAsync(string id, ContainerUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var data     = new JsonRequestContent <ContainerUpdateParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/update", null, data, cancellationToken);

            return(this._client.JsonSerializer.DeserializeObject <ContainerUpdateResponse>(response.Body));
        }
Beispiel #23
0
        public async Task <bool> StartContainerAsync(string id, HostConfig hostConfig)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            JsonRequestContent <HostConfig> data = null;

            if (hostConfig != null)
            {
                data = new JsonRequestContent <HostConfig>(hostConfig, this._client.JsonSerializer);
            }
            var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"containers/{id}/start", null, data).ConfigureAwait(false);

            return(response.StatusCode != HttpStatusCode.NotModified);
        }
Beispiel #24
0
        public async Task <MultiplexedStream> StartWithConfigContainerExecAsync(string id, ExecConfig eConfig, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var data   = new JsonRequestContent <ContainerExecStartParameters>(new ContainerExecStartParameters(eConfig), this._client.JsonSerializer);
            var stream = await this._client.MakeRequestForHijackedStreamAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, $"exec/{id}/start", null, null, data, cancellationToken).ConfigureAwait(false);

            if (!stream.CanCloseWrite)
            {
                stream.Dispose();
                throw new NotSupportedException("Cannot shutdown write on this transport");
            }

            return(new MultiplexedStream(stream, !eConfig.Tty));
        }
        public async Task <ExecCreateContainerResponse> ExecCreateContainerAsync(string id, ExecCreateContainerParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            string path = string.Format(CultureInfo.InvariantCulture, "containers/{0}/exec", id);
            JsonRequestContent <ExecCreateContainerConfig> data = null;

            if (parameters.Config != null)
            {
                data = new JsonRequestContent <ExecCreateContainerConfig>(parameters.Config, this.Client.JsonSerializer);
            }
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, null, data).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <ExecCreateContainerResponse>(response.Body));
        }
        public async Task <bool> StartContainerAsync(string id, HostConfig hostConfig)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            string path = string.Format(CultureInfo.InvariantCulture, "containers/{0}/start", id);
            JsonRequestContent <HostConfig> data = null;

            if (hostConfig != null)
            {
                data = new JsonRequestContent <HostConfig>(hostConfig, this.Client.JsonSerializer);
            }
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, null, data).ConfigureAwait(false);

            return(response.StatusCode != HttpStatusCode.NotModified);
        }
Beispiel #27
0
        public async Task <CreateContainerResponse> CreateContainerAsync(CreateContainerParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            IQueryString qs = null;

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (!string.IsNullOrEmpty(parameters.Name))
            {
                qs = new QueryString <CreateContainerParameters>(parameters);
            }

            var data     = new JsonRequestContent <CreateContainerParameters>(parameters, this._client.JsonSerializer);
            var response = await this._client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, "containers/create", qs, data, cancellationToken).ConfigureAwait(false);

            return(this._client.JsonSerializer.DeserializeObject <CreateContainerResponse>(response.Body));
        }
        public Task ConfigurePluginAsync(string name, PluginConfigureParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Args == null)
            {
                throw new ArgumentNullException(nameof(parameters.Args));
            }

            var body = new JsonRequestContent <IList <string> >(parameters.Args, this._client.JsonSerializer);

            return(this._client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/set", null, body, cancellationToken));
        }
        public Task UpgradePluginAsync(string name, PluginUpgradeParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Privileges == null)
            {
                throw new ArgumentNullException(nameof(parameters.Privileges));
            }

            var query = new QueryString <PluginUpgradeParameters>(parameters);
            var data  = new JsonRequestContent <IList <PluginPrivilege> >(parameters.Privileges, this._client.JsonSerializer);

            return(this._client.MakeRequestAsync(new[] { NoSuchPluginHandler }, HttpMethod.Post, $"plugins/{name}/upgrade", query, data, cancellationToken));
        }
        public Task InstallPluginAsync(PluginInstallParameters parameters, IProgress <JSONMessage> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (parameters.Privileges == null)
            {
                throw new ArgumentNullException(nameof(parameters.Privileges));
            }

            var data = new JsonRequestContent <IList <PluginPrivilege> >(parameters.Privileges, this._client.JsonSerializer);

            IQueryString queryParameters = new QueryString <PluginInstallParameters>(parameters);

            return(StreamUtil.MonitorStreamForMessagesAsync(
                       this._client.MakeRequestForStreamAsync(this._client.NoErrorHandlers, HttpMethod.Post, $"plugins/pull", queryParameters, data, null, CancellationToken.None),
                       this._client,
                       cancellationToken,
                       progress));
        }