Exemple #1
0
        public async Task <SystemInfoResponse> GetSystemInfoAsync()
        {
            const string      path     = "info";
            DockerApiResponse response = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, path, null).ConfigureAwait(false);;

            return(this.Client.JsonSerializer.DeserializeObject <SystemInfoResponse>(response.Body));
        }
        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));
        }
        public async Task <VersionResponse> GetVersionAsync()
        {
            const string      path     = "version";
            DockerApiResponse response = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, path, null);

            return(this.Client.JsonSerializer.DeserializeObject <VersionResponse>(response.Body));
        }
        public async Task <ContainerResponse> InspectContainerAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            string            path     = string.Format(CultureInfo.InvariantCulture, "containers/{0}/json", id);
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, path, null).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <ContainerResponse>(response.Body));
        }
        public async Task <WaitContainerResponse> WaitContainerAsync(string id, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            string            path     = string.Format(CultureInfo.InvariantCulture, "containers/{0}/wait", id);
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, null, null, new TimeSpan(Timeout.Infinite), cancellationToken).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <WaitContainerResponse>(response.Body));
        }
        public async Task <IList <ImageHistoryResponse> > GetImageHistoryAsync(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            string            path     = string.Format(CultureInfo.InvariantCulture, "images/{0}/history", name);
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Get, path, null).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <ImageHistoryResponse[]>(response.Body));
        }
        public async Task <IList <FilesystemChange> > InspectChangesAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            string            path     = string.Format(CultureInfo.InvariantCulture, "containers/{0}/changes", id);
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, path, null);

            return(this.Client.JsonSerializer.DeserializeObject <FilesystemChange[]>(response.Body));
        }
        public async Task <IList <ContainerListResponse> > ListContainersAsync(ListContainersParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            string            path            = "containers/json";
            IQueryString      queryParameters = new QueryString <ListContainersParameters>(parameters);
            DockerApiResponse response        = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, path, queryParameters).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <ContainerListResponse[]>(response.Body));
        }
        public async Task <IList <ImageSearchResponse> > SearchImagesAsync(SearchImagesParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            string            path            = "images/search";
            IQueryString      queryParameters = new QueryString <SearchImagesParameters>(parameters);
            DockerApiResponse response        = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, path, queryParameters);

            return(this.Client.JsonSerializer.DeserializeObject <ImageSearchResponse[]>(response.Body));
        }
Exemple #10
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));
        }
        public async Task <ContainerProcessesResponse> ListProcessesAsync(string id, ListProcessesParameters parameters)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

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

            string            path            = string.Format(CultureInfo.InvariantCulture, "containers/{0}/top", id);
            IQueryString      queryParameters = new QueryString <ListProcessesParameters>(parameters);
            DockerApiResponse response        = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Get, path, queryParameters).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <ContainerProcessesResponse>(response.Body));
        }
        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);
        }
        public async Task <IList <IDictionary <string, string> > > DeleteImageAsync(string name, ImageDeleteParameters parameters)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

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

            string            path            = string.Format(CultureInfo.InvariantCulture, "images/{0}", name);
            IQueryString      queryParameters = new QueryString <ImageDeleteParameters>(parameters);
            DockerApiResponse response        = await this.Client.MakeRequestAsync(new[] { NoSuchImageHandler }, HttpMethod.Delete, path, queryParameters).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <Dictionary <string, string>[]>(response.Body));
        }
        public async Task <bool> StopContainerAsync(string id, StopContainerParameters parameters, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

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

            string       path            = string.Format(CultureInfo.InvariantCulture, "containers/{0}/stop", id);
            IQueryString queryParameters = new QueryString <StopContainerParameters>(parameters);
            // since specified wait timespan can be greater than HttpClient's default, we set the
            // client timeout to infinite and provide a cancellation token.
            DockerApiResponse response = await this.Client.MakeRequestAsync(new[] { NoSuchContainerHandler }, HttpMethod.Post, path, queryParameters, null, new TimeSpan(Timeout.Infinite), cancellationToken).ConfigureAwait(false);

            return(response.StatusCode != HttpStatusCode.NotModified);
        }
        public async Task <VersionResponse> GetVersionAsync()
        {
            DockerApiResponse response = await this.Client.MakeRequestAsync(this.Client.NoErrorHandlers, HttpMethod.Get, "version", null).ConfigureAwait(false);

            return(this.Client.JsonSerializer.DeserializeObject <VersionResponse>(response.Body));
        }