
de.gesellix.docker.remote.api.client.ContainerApi.kt Maven / Gradle / Ivy
/**
* Docker Engine API
*
* The Engine API is an HTTP API served by Docker Engine. It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API. Most of the client's commands map directly to API endpoints (e.g. `docker ps` is `GET /containers/json`). The notable exception is running containers, which consists of several API calls. # Errors The API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format: ``` { \"message\": \"page not found\" } ``` # Versioning The API is usually changed in each release, so API calls are versioned to ensure that clients don't break. To lock to a specific version of the API, you prefix the URL with its version, for example, call `/v1.30/info` to use the v1.30 version of the `/info` endpoint. If the API version specified in the URL is not supported by the daemon, a HTTP `400 Bad Request` error message is returned. If you omit the version-prefix, the current version of the API (v1.41) is used. For example, calling `/info` is the same as calling `/v1.41/info`. Using the API without a version-prefix is deprecated and will be removed in a future release. Engine releases in the near future should support this version of the API, so your client will continue to work even if it is talking to a newer Engine. The API uses an open schema model, which means server may add extra properties to responses. Likewise, the server will ignore any extra query parameters and request body properties. When you write clients, you need to ignore additional properties in responses to ensure they do not break when talking to newer daemons. # Authentication Authentication for registries is handled client side. The client has to send authentication details to various endpoints that need to communicate with registries, such as `POST /images/(name)/push`. These are sent as `X-Registry-Auth` header as a [base64url encoded](https://tools.ietf.org/html/rfc4648#section-5) (JSON) string with the following structure: ``` { \"username\": \"string\", \"password\": \"string\", \"email\": \"string\", \"serveraddress\": \"string\" } ``` The `serveraddress` is a domain/IP without a protocol. Throughout this structure, double quotes are required. If you have already got an identity token from the [`/auth` endpoint](#operation/SystemAuth), you can just pass this instead of credentials: ``` { \"identitytoken\": \"9cbaf023786cd7...\" } ```
*
* The version of the OpenAPI document: 1.41
*
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*/
package de.gesellix.docker.remote.api.client
import com.squareup.moshi.Json
import com.squareup.moshi.Moshi
import de.gesellix.docker.engine.DockerClientConfig
import de.gesellix.docker.engine.RequestMethod.*
import de.gesellix.docker.remote.api.ContainerCreateRequest
import de.gesellix.docker.remote.api.ContainerCreateResponse
import de.gesellix.docker.remote.api.ContainerInspectResponse
import de.gesellix.docker.remote.api.ContainerPruneResponse
import de.gesellix.docker.remote.api.ContainerSummary
import de.gesellix.docker.remote.api.ContainerTopResponse
import de.gesellix.docker.remote.api.ContainerUpdateRequest
import de.gesellix.docker.remote.api.ContainerUpdateResponse
import de.gesellix.docker.remote.api.ContainerWaitResponse
import de.gesellix.docker.remote.api.FilesystemChange
import de.gesellix.docker.remote.api.core.ApiClient
import de.gesellix.docker.remote.api.core.ClientError
import de.gesellix.docker.remote.api.core.ClientException
import de.gesellix.docker.remote.api.core.Frame
import de.gesellix.docker.remote.api.core.MultiValueMap
import de.gesellix.docker.remote.api.core.RequestConfig
import de.gesellix.docker.remote.api.core.ResponseType
import de.gesellix.docker.remote.api.core.ServerError
import de.gesellix.docker.remote.api.core.ServerException
import de.gesellix.docker.remote.api.core.StreamCallback
import de.gesellix.docker.remote.api.core.Success
import de.gesellix.docker.remote.api.core.SuccessStream
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import okio.Source
import okio.source
import java.io.InputStream
import java.net.HttpURLConnection.HTTP_NOT_FOUND
import java.net.HttpURLConnection.HTTP_NOT_MODIFIED
import java.net.Proxy
import java.util.*
class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, proxy: Proxy?) : ApiClient(dockerClientConfig, proxy) {
constructor(dockerClientConfig: DockerClientConfig = defaultClientConfig) : this(dockerClientConfig, null)
companion object {
@JvmStatic
val defaultClientConfig: DockerClientConfig by lazy {
DockerClientConfig()
}
}
/**
* Get an archive of a filesystem resource in a container
* Get a tar archive of a resource in the filesystem of container id.
* @param id ID or name of the container
* @param path Resource in the container’s filesystem to archive.
* @return InputStream
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerArchive(id: String, path: String): InputStream {
val localVariableConfig = containerArchiveRequestConfig(id = id, path = path)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as InputStream
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerArchive
*
* @param id ID or name of the container
* @param path Resource in the container’s filesystem to archive.
* @return RequestConfig
*/
fun containerArchiveRequestConfig(id: String, path: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
put("path", listOf(path))
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/archive".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Get information about files in a container
* A response header `X-Docker-Container-Path-Stat` is returned, containing a base64 - encoded JSON object with some filesystem header information about the path.
* @param id ID or name of the container
* @param path Resource in the container’s filesystem to archive.
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerArchiveInfo(id: String, path: String): Any? {
val localVariableConfig = containerArchiveInfoRequestConfig(id = id, path = path)
val localVarResponse = request(
localVariableConfig
)
when (localVarResponse.responseType) {
ResponseType.Success -> {
val stats = localVarResponse.headers["X-Docker-Container-Path-Stat".lowercase()]?.first()
return if (stats == null) {
null
} else {
val jsonAdapter = Moshi.Builder().build().adapter(Map::class.java)
jsonAdapter.fromJson(String(Base64.getDecoder().decode(stats)))
}
}
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerArchiveInfo
*
* @param id ID or name of the container
* @param path Resource in the container’s filesystem to archive.
* @return RequestConfig
*/
fun containerArchiveInfoRequestConfig(id: String, path: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
put("path", listOf(path))
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = HEAD,
path = "/containers/{id}/archive".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Attach to a container
* Attach to a container to read its output or send it input. You can attach to the same container multiple times and you can reattach to containers that have been detached. Either the `stream` or `logs` parameter must be `true` for this endpoint to do anything. See the [documentation for the `docker attach` command](https://docs.docker.com/engine/reference/commandline/attach/) for more details. ### Hijacking This endpoint hijacks the HTTP connection to transport `stdin`, `stdout`, and `stderr` on the same socket. This is the response from the daemon for an attach request: ``` HTTP/1.1 200 OK Content-Type: application/vnd.docker.raw-stream [STREAM] ``` After the headers and two new lines, the TCP connection can now be used for raw, bidirectional communication between the client and server. To hint potential proxies about connection hijacking, the Docker client can also optionally send connection upgrade headers. For example, the client sends this request to upgrade the connection: ``` POST /containers/16253994b7c4/attach?stream=1&stdout=1 HTTP/1.1 Upgrade: tcp Connection: Upgrade ``` The Docker daemon will respond with a `101 UPGRADED` response, and will similarly follow with the raw stream: ``` HTTP/1.1 101 UPGRADED Content-Type: application/vnd.docker.raw-stream Connection: Upgrade Upgrade: tcp [STREAM] ``` ### Stream format When the TTY setting is disabled in [`POST /containers/create`](#operation/ContainerCreate), the HTTP Content-Type header is set to application/vnd.docker.multiplexed-stream and the stream over the hijacked connected is multiplexed to separate out `stdout` and `stderr`. The stream consists of a series of frames, each containing a header and a payload. The header contains the information which the stream writes (`stdout` or `stderr`). It also contains the size of the associated frame encoded in the last four bytes (`uint32`). It is encoded on the first eight bytes like this: ```go header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} ``` `STREAM_TYPE` can be: - 0: `stdin` (is written on `stdout`) - 1: `stdout` - 2: `stderr` `SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of the `uint32` size encoded as big endian. Following the header is the payload, which is the specified number of bytes of `STREAM_TYPE`. The simplest way to implement this protocol is the following: 1. Read 8 bytes. 2. Choose `stdout` or `stderr` depending on the first byte. 3. Extract the frame size from the last four bytes. 4. Read the extracted size and output it on the correct output. 5. Goto 1. ### Stream format when using a TTY When the TTY setting is enabled in [`POST /containers/create`](#operation/ContainerCreate), the stream is not multiplexed. The data exchanged over the hijacked connection is simply the raw data from the process PTY and client's `stdin`.
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. (optional)
* @param logs Replay previous logs from the container. This is useful for attaching to a container that has started and you want to output everything since the container started. If `stream` is also enabled, once all the previous output has been returned, it will seamlessly transition into streaming current output. (optional, default to false)
* @param stream Stream attached streams from the time the request was made onwards. (optional, default to false)
* @param stdin Attach to `stdin` (optional, default to false)
* @param stdout Attach to `stdout` (optional, default to false)
* @param stderr Attach to `stderr` (optional, default to false)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerAttach(
id: String, detachKeys: String?, logs: Boolean?, stream: Boolean?, stdin: Boolean?, stdout: Boolean?, stderr: Boolean?,
callback: StreamCallback, timeoutMillis: Long /*= 24.hours.toLongMilliseconds()*/
) {
val localVariableConfig = containerAttachRequestConfig(id = id, detachKeys = detachKeys, logs = logs, stream = stream, stdin = stdin, stdout = stdout, stderr = stderr)
val expectMultiplexedResponse = !(containerInspect(id, false).config?.tty ?: false)
val localVarResponse = requestFrames(
localVariableConfig, expectMultiplexedResponse
)
when (localVarResponse.responseType) {
ResponseType.Success -> {
runBlocking {
launch {
withTimeout(timeoutMillis) {
callback.onStarting(this@launch::cancel)
((localVarResponse as SuccessStream<*>).data as Flow).collect { callback.onNext(it) }
callback.onFinished()
}
}
}
}
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerAttach
*
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. (optional)
* @param logs Replay previous logs from the container. This is useful for attaching to a container that has started and you want to output everything since the container started. If `stream` is also enabled, once all the previous output has been returned, it will seamlessly transition into streaming current output. (optional, default to false)
* @param stream Stream attached streams from the time the request was made onwards. (optional, default to false)
* @param stdin Attach to `stdin` (optional, default to false)
* @param stdout Attach to `stdout` (optional, default to false)
* @param stderr Attach to `stderr` (optional, default to false)
* @return RequestConfig
*/
fun containerAttachRequestConfig(
id: String,
detachKeys: String?,
logs: Boolean?,
stream: Boolean?,
stdin: Boolean?,
stdout: Boolean?,
stderr: Boolean?
): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (detachKeys != null) {
put("detachKeys", listOf(detachKeys.toString()))
}
if (logs != null) {
put("logs", listOf(logs.toString()))
}
if (stream != null) {
put("stream", listOf(stream.toString()))
}
if (stdin != null) {
put("stdin", listOf(stdin.toString()))
}
if (stdout != null) {
put("stdout", listOf(stdout.toString()))
}
if (stderr != null) {
put("stderr", listOf(stderr.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/attach".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Attach to a container via a websocket
*
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,`, or `_`. (optional)
* @param logs Return logs (optional, default to false)
* @param stream Return stream (optional, default to false)
* @param stdin Attach to `stdin` (optional, default to false)
* @param stdout Attach to `stdout` (optional, default to false)
* @param stderr Attach to `stderr` (optional, default to false)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerAttachWebsocket(
id: String,
detachKeys: String?,
logs: Boolean?,
stream: Boolean?,
stdin: Boolean?,
stdout: Boolean?,
stderr: Boolean?
) {
val localVariableConfig = containerAttachWebsocketRequestConfig(id = id, detachKeys = detachKeys, logs = logs, stream = stream, stdin = stdin, stdout = stdout, stderr = stderr)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerAttachWebsocket
*
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,`, or `_`. (optional)
* @param logs Return logs (optional, default to false)
* @param stream Return stream (optional, default to false)
* @param stdin Attach to `stdin` (optional, default to false)
* @param stdout Attach to `stdout` (optional, default to false)
* @param stderr Attach to `stderr` (optional, default to false)
* @return RequestConfig
*/
fun containerAttachWebsocketRequestConfig(
id: String,
detachKeys: String?,
logs: Boolean?,
stream: Boolean?,
stdin: Boolean?,
stdout: Boolean?,
stderr: Boolean?
): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (detachKeys != null) {
put("detachKeys", listOf(detachKeys.toString()))
}
if (logs != null) {
put("logs", listOf(logs.toString()))
}
if (stream != null) {
put("stream", listOf(stream.toString()))
}
if (stdin != null) {
put("stdin", listOf(stdin.toString()))
}
if (stdout != null) {
put("stdout", listOf(stdout.toString()))
}
if (stderr != null) {
put("stderr", listOf(stderr.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/attach/ws".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Get changes on a container’s filesystem
* Returns which files in a container's filesystem have been added, deleted, or modified. The `Kind` of modification can be one of: - `0`: Modified - `1`: Added - `2`: Deleted
* @param id ID or name of the container
* @return kotlin.collections.List
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerChanges(id: String): List {
val localVariableConfig = containerChangesRequestConfig(id = id)
val localVarResponse = request>(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as List
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerChanges
*
* @param id ID or name of the container
* @return RequestConfig
*/
fun containerChangesRequestConfig(id: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/changes".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody,
elementType = FilesystemChange::class.java
)
}
/**
* Create a container
*
* @param body Container to create
* @param name Assign the specified name to the container. Must match `/?[a-zA-Z0-9][a-zA-Z0-9_.-]+`. (optional)
* @return ContainerCreateResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
@JvmOverloads
fun containerCreate(body: ContainerCreateRequest, name: String? = ""): ContainerCreateResponse {
val localVariableConfig = containerCreateRequestConfig(body = body, name = name)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerCreateResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerCreate
*
* @param body Container to create
* @param name Assign the specified name to the container. Must match `/?[a-zA-Z0-9][a-zA-Z0-9_.-]+`. (optional)
* @return RequestConfig
*/
fun containerCreateRequestConfig(body: ContainerCreateRequest, name: String?): RequestConfig {
val localVariableBody = body
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (name != null) {
put("name", listOf(name.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/create",
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Remove a container
*
* @param id ID or name of the container
* @param v Remove anonymous volumes associated with the container. (optional, default to false)
* @param force If the container is running, kill it before removing it. (optional, default to false)
* @param link Remove the specified link associated with the container. (optional, default to false)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerDelete(id: String, v: Boolean?, force: Boolean?, link: Boolean?) {
val localVariableConfig = containerDeleteRequestConfig(id = id, v = v, force = force, link = link)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
if (localVarError.statusCode == HTTP_NOT_FOUND) {
return
}
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerDelete
*
* @param id ID or name of the container
* @param v Remove anonymous volumes associated with the container. (optional, default to false)
* @param force If the container is running, kill it before removing it. (optional, default to false)
* @param link Remove the specified link associated with the container. (optional, default to false)
* @return RequestConfig
*/
fun containerDeleteRequestConfig(id: String, v: Boolean?, force: Boolean?, link: Boolean?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (v != null) {
put("v", listOf(v.toString()))
}
if (force != null) {
put("force", listOf(force.toString()))
}
if (link != null) {
put("link", listOf(link.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = DELETE,
path = "/containers/{id}".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Export a container
* Export the contents of a container as a tarball.
* @param id ID or name of the container
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerExport(id: String): InputStream {
val localVariableConfig = containerExportRequestConfig(id = id)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as InputStream
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerExport
*
* @param id ID or name of the container
* @return RequestConfig
*/
fun containerExportRequestConfig(id: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/export".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Inspect a container
* Return low-level information about a container.
* @param id ID or name of the container
* @param size Return the size of container as fields `SizeRw` and `SizeRootFs` (optional, default to false)
* @return ContainerInspectResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerInspect(id: String, size: Boolean?): ContainerInspectResponse {
val localVariableConfig = containerInspectRequestConfig(id = id, size = size)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerInspectResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerInspect
*
* @param id ID or name of the container
* @param size Return the size of container as fields `SizeRw` and `SizeRootFs` (optional, default to false)
* @return RequestConfig
*/
fun containerInspectRequestConfig(id: String, size: Boolean?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (size != null) {
put("size", listOf(size.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/json".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Kill a container
* Send a POSIX signal to a container, defaulting to killing to the container.
* @param id ID or name of the container
* @param signal Signal to send to the container as an integer or string (e.g. `SIGINT`) (optional, default to "SIGKILL")
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerKill(id: String, signal: String?) {
val localVariableConfig = containerKillRequestConfig(id = id, signal = signal)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerKill
*
* @param id ID or name of the container
* @param signal Signal to send to the container as an integer or string (e.g. `SIGINT`). (optional, default to "SIGKILL")
* @return RequestConfig
*/
fun containerKillRequestConfig(id: String, signal: String?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (signal != null) {
put("signal", listOf(signal.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/kill".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* List containers
* Returns a list of containers. For details on the format, see the [inspect endpoint](#operation/ContainerInspect). Note that it uses a different, smaller representation of a container than inspecting a single container. For example, the list of linked containers is not propagated .
* @param all Return all containers. By default, only running containers are shown. (optional, default to false)
* @param limit Return this number of most recently created containers, including non-running ones. (optional)
* @param size Return the size of container as fields `SizeRw` and `SizeRootFs`. (optional, default to false)
* @param filters Filters to process on the container list, encoded as JSON (a `map[string][]string`). For example, `{\"status\": [\"paused\"]}` will only return paused containers. Available filters: - `ancestor`=(`<image-name>[:<tag>]`, `<image id>`, or `<image@digest>`) - `before`=(`<container id>` or `<container name>`) - `expose`=(`<port>[/<proto>]`|`<startport-endport>/[<proto>]`) - `exited=<int>` containers with exit code of `<int>` - `health`=(`starting`|`healthy`|`unhealthy`|`none`) - `id=<ID>` a container's ID - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - `is-task=`(`true`|`false`) - `label=key` or `label=\"key=value\"` of a container label - `name=<name>` a container's name - `network`=(`<network id>` or `<network name>`) - `publish`=(`<port>[/<proto>]`|`<startport-endport>/[<proto>]`) - `since`=(`<container id>` or `<container name>`) - `status=`(`created`|`restarting`|`running`|`removing`|`paused`|`exited`|`dead`) - `volume`=(`<volume name>` or `<mount point destination>`) (optional)
* @return kotlin.collections.List
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerList(all: Boolean?, limit: Int?, size: Boolean?, filters: String?): List {
val localVariableConfig = containerListRequestConfig(all = all, limit = limit, size = size, filters = filters)
val localVarResponse = request>(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as List
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerList
*
* @param all Return all containers. By default, only running containers are shown. (optional, default to false)
* @param limit Return this number of most recently created containers, including non-running ones. (optional)
* @param size Return the size of container as fields `SizeRw` and `SizeRootFs`. (optional, default to false)
* @param filters Filters to process on the container list, encoded as JSON (a `map[string][]string`). For example, `{\"status\": [\"paused\"]}` will only return paused containers. Available filters: - `ancestor`=(`<image-name>[:<tag>]`, `<image id>`, or `<image@digest>`) - `before`=(`<container id>` or `<container name>`) - `expose`=(`<port>[/<proto>]`|`<startport-endport>/[<proto>]`) - `exited=<int>` containers with exit code of `<int>` - `health`=(`starting`|`healthy`|`unhealthy`|`none`) - `id=<ID>` a container's ID - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - `is-task=`(`true`|`false`) - `label=key` or `label=\"key=value\"` of a container label - `name=<name>` a container's name - `network`=(`<network id>` or `<network name>`) - `publish`=(`<port>[/<proto>]`|`<startport-endport>/[<proto>]`) - `since`=(`<container id>` or `<container name>`) - `status=`(`created`|`restarting`|`running`|`removing`|`paused`|`exited`|`dead`) - `volume`=(`<volume name>` or `<mount point destination>`) (optional)
* @return RequestConfig
*/
fun containerListRequestConfig(all: Boolean?, limit: Int?, size: Boolean?, filters: String?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (all != null) {
put("all", listOf(all.toString()))
}
if (limit != null) {
put("limit", listOf(limit.toString()))
}
if (size != null) {
put("size", listOf(size.toString()))
}
if (filters != null) {
put("filters", listOf(filters.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/json",
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody,
elementType = ContainerSummary::class.java
)
}
/**
* Get container logs
* Get `stdout` and `stderr` logs from a container. Note: This endpoint works only for containers with the `json-file` or `journald` logging driver.
* @param id ID or name of the container
* @param follow Keep connection after returning logs. (optional, default to false)
* @param stdout Return logs from `stdout` (optional, default to false)
* @param stderr Return logs from `stderr` (optional, default to false)
* @param since Only return logs since this time, as a UNIX timestamp (optional, default to 0)
* @param until Only return logs before this time, as a UNIX timestamp (optional, default to 0)
* @param timestamps Add timestamps to every log line (optional, default to false)
* @param tail Only return this number of log lines from the end of the logs. Specify as an integer or `all` to output all log lines. (optional, default to "all")
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerLogs(
id: String,
follow: Boolean?,
stdout: Boolean?,
stderr: Boolean?,
since: Int?,
until: Int?,
timestamps: Boolean?,
tail: String?,
callback: StreamCallback, timeoutMillis: Long /*= 24.hours.toLongMilliseconds()*/
) {
val localVariableConfig = containerLogsRequestConfig(id = id, follow = follow, stdout = stdout, stderr = stderr, since = since, until = until, timestamps = timestamps, tail = tail)
val expectMultiplexedResponse = !(containerInspect(id, false).config?.tty ?: false)
val localVarResponse = requestFrames(
localVariableConfig, expectMultiplexedResponse
)
when (localVarResponse.responseType) {
ResponseType.Success -> {
runBlocking {
launch {
withTimeout(timeoutMillis) {
callback.onStarting(this@launch::cancel)
((localVarResponse as SuccessStream<*>).data as Flow).collect { callback.onNext(it) }
callback.onFinished()
}
}
}
}
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerLogs
*
* @param id ID or name of the container
* @param follow Keep connection after returning logs. (optional, default to false)
* @param stdout Return logs from `stdout` (optional, default to false)
* @param stderr Return logs from `stderr` (optional, default to false)
* @param since Only return logs since this time, as a UNIX timestamp (optional, default to 0)
* @param until Only return logs before this time, as a UNIX timestamp (optional, default to 0)
* @param timestamps Add timestamps to every log line (optional, default to false)
* @param tail Only return this number of log lines from the end of the logs. Specify as an integer or `all` to output all log lines. (optional, default to "all")
* @return RequestConfig
*/
fun containerLogsRequestConfig(
id: String,
follow: Boolean?,
stdout: Boolean?,
stderr: Boolean?,
since: Int?,
until: Int?,
timestamps: Boolean?,
tail: String?
): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (follow != null) {
put("follow", listOf(follow.toString()))
}
if (stdout != null) {
put("stdout", listOf(stdout.toString()))
}
if (stderr != null) {
put("stderr", listOf(stderr.toString()))
}
if (since != null) {
put("since", listOf(since.toString()))
}
if (until != null) {
put("until", listOf(until.toString()))
}
if (timestamps != null) {
put("timestamps", listOf(timestamps.toString()))
}
if (tail != null) {
put("tail", listOf(tail.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/logs".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Pause a container
* Use the freezer cgroup to suspend all processes in a container. Traditionally, when suspending a process the `SIGSTOP` signal is used, which is observable by the process being suspended. With the freezer cgroup the process is unaware, and unable to capture, that it is being suspended, and subsequently resumed.
* @param id ID or name of the container
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerPause(id: String) {
val localVariableConfig = containerPauseRequestConfig(id = id)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerPause
*
* @param id ID or name of the container
* @return RequestConfig
*/
fun containerPauseRequestConfig(id: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/pause".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Delete stopped containers
*
* @param filters Filters to process on the prune list, encoded as JSON (a `map[string][]string`). Available filters: - `until=<timestamp>` Prune containers created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time. - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune containers with (or without, in case `label!=...` is used) the specified labels. (optional)
* @return ContainerPruneResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerPrune(filters: String?): ContainerPruneResponse {
val localVariableConfig = containerPruneRequestConfig(filters = filters)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerPruneResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerPrune
*
* @param filters Filters to process on the prune list, encoded as JSON (a `map[string][]string`). Available filters: - `until=<timestamp>` Prune containers created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time. - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune containers with (or without, in case `label!=...` is used) the specified labels. (optional)
* @return RequestConfig
*/
fun containerPruneRequestConfig(filters: String?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (filters != null) {
put("filters", listOf(filters.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/prune",
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Rename a container
*
* @param id ID or name of the container
* @param name New name for the container
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerRename(id: String, name: String) {
val localVariableConfig = containerRenameRequestConfig(id = id, name = name)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerRename
*
* @param id ID or name of the container
* @param name New name for the container
* @return RequestConfig
*/
fun containerRenameRequestConfig(id: String, name: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
put("name", listOf(name))
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/rename".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Resize a container TTY
* Resize the TTY for a container.
* @param id ID or name of the container
* @param h Height of the TTY session in characters (optional)
* @param w Width of the TTY session in characters (optional)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerResize(id: String, h: Int?, w: Int?) {
val localVariableConfig = containerResizeRequestConfig(id = id, h = h, w = w)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerResize
*
* @param id ID or name of the container
* @param h Height of the TTY session in characters (optional)
* @param w Width of the TTY session in characters (optional)
* @return RequestConfig
*/
fun containerResizeRequestConfig(id: String, h: Int?, w: Int?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (h != null) {
put("h", listOf(h.toString()))
}
if (w != null) {
put("w", listOf(w.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/resize".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Restart a container
*
* @param id ID or name of the container
* @param t Number of seconds to wait before killing the container (optional)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerRestart(id: String, t: Int?) {
val localVariableConfig = containerRestartRequestConfig(id = id, t = t)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerRestart
*
* @param id ID or name of the container
* @param t Number of seconds to wait before killing the container (optional)
* @return RequestConfig
*/
fun containerRestartRequestConfig(id: String, t: Int?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (t != null) {
put("t", listOf(t.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/restart".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Start a container
*
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. (optional)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerStart(id: String, detachKeys: String?) {
val localVariableConfig = containerStartRequestConfig(id = id, detachKeys = detachKeys)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerStart
*
* @param id ID or name of the container
* @param detachKeys Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. (optional)
* @return RequestConfig
*/
fun containerStartRequestConfig(id: String, detachKeys: String?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (detachKeys != null) {
put("detachKeys", listOf(detachKeys.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/start".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Get container stats based on resource usage
* This endpoint returns a live stream of a container’s resource usage statistics. The `precpu_stats` is the CPU statistic of the *previous* read, and is used to calculate the CPU usage percentage. It is not an exact copy of the `cpu_stats` field. If either `precpu_stats.online_cpus` or `cpu_stats.online_cpus` is nil then for compatibility with older daemons the length of the corresponding `cpu_usage.percpu_usage` array should be used. On a cgroup v2 host, the following fields are not set * `blkio_stats`: all fields other than `io_service_bytes_recursive` * `cpu_stats`: `cpu_usage.percpu_usage` * `memory_stats`: `max_usage` and `failcnt` Also, `memory_stats.stats` fields are incompatible with cgroup v1. To calculate the values shown by the `stats` command of the docker cli tool the following formulas can be used: * used_memory = `memory_stats.usage - memory_stats.stats.cache` * available_memory = `memory_stats.limit` * Memory usage % = `(used_memory / available_memory) * 100.0` * cpu_delta = `cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage` * system_cpu_delta = `cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage` * number_cpus = `lenght(cpu_stats.cpu_usage.percpu_usage)` or `cpu_stats.online_cpus` * CPU usage % = `(cpu_delta / system_cpu_delta) * number_cpus * 100.0`
* @param id ID or name of the container
* @param stream Stream the output. If false, the stats will be output once and then it will disconnect. (optional, default to true)
* @param oneShot Only get a single stat instead of waiting for 2 cycles. Must be used with `stream=false`. (optional, default to false)
* @return kotlin.Any
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerStats(id: String, stream: Boolean?, oneShot: Boolean?, callback: StreamCallback, timeoutMillis: Long /*= 24.hours.toLongMilliseconds()*/): Any {
val localVariableConfig = containerStatsRequestConfig(id = id, stream = stream, oneShot = oneShot)
val localVarResponse = requestStream(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> {
runBlocking {
launch {
withTimeout(timeoutMillis) {
callback.onStarting(this@launch::cancel)
(localVarResponse as SuccessStream<*>).data.collect { callback.onNext(it) }
callback.onFinished()
}
}
}
Unit
}
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerStats
*
* @param id ID or name of the container
* @param stream Stream the output. If false, the stats will be output once and then it will disconnect. (optional, default to true)
* @param oneShot Only get a single stat instead of waiting for 2 cycles. Must be used with `stream=false`. (optional, default to false)
* @return RequestConfig
*/
fun containerStatsRequestConfig(id: String, stream: Boolean?, oneShot: Boolean?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (stream != null) {
put("stream", listOf(stream.toString()))
}
if (oneShot != null) {
put("one-shot", listOf(oneShot.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/stats".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Stop a container
*
* @param id ID or name of the container
* @param t Number of seconds to wait before killing the container (optional)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerStop(id: String, t: Int?) {
val localVariableConfig = containerStopRequestConfig(id = id, t = t)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
if (localVarError.statusCode == HTTP_NOT_FOUND) {
return
}
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
if (localVarError.statusCode == HTTP_NOT_MODIFIED) {
return
}
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerStop
*
* @param id ID or name of the container
* @param t Number of seconds to wait before killing the container (optional)
* @return RequestConfig
*/
fun containerStopRequestConfig(id: String, t: Int?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (t != null) {
put("t", listOf(t.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/stop".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* List processes running inside a container
* On Unix systems, this is done by running the `ps` command. This endpoint is not supported on Windows.
* @param id ID or name of the container
* @param psArgs The arguments to pass to `ps`. For example, `aux` (optional, default to "-ef")
* @return ContainerTopResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerTop(id: String, psArgs: String?): ContainerTopResponse {
val localVariableConfig = containerTopRequestConfig(id = id, psArgs = psArgs)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerTopResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerTop
*
* @param id ID or name of the container
* @param psArgs The arguments to pass to `ps`. For example, `aux` (optional, default to "-ef")
* @return RequestConfig
*/
fun containerTopRequestConfig(id: String, psArgs: String?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (psArgs != null) {
put("ps_args", listOf(psArgs.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = GET,
path = "/containers/{id}/top".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Unpause a container
* Resume a container which has been paused.
* @param id ID or name of the container
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerUnpause(id: String) {
val localVariableConfig = containerUnpauseRequestConfig(id = id)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerUnpause
*
* @param id ID or name of the container
* @return RequestConfig
*/
fun containerUnpauseRequestConfig(id: String): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/unpause".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Update a container
* Change various configuration options of a container without having to recreate it.
* @param id ID or name of the container
* @param update
* @return ContainerUpdateResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerUpdate(id: String, update: ContainerUpdateRequest): ContainerUpdateResponse {
val localVariableConfig = containerUpdateRequestConfig(id = id, update = update)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerUpdateResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerUpdate
*
* @param id ID or name of the container
* @param update
* @return RequestConfig
*/
fun containerUpdateRequestConfig(id: String, update: ContainerUpdateRequest): RequestConfig {
val localVariableBody = update
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/update".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
enum class ConditionContainerWait(val value: String) {
@Json(name = "not-running")
NotMinusRunning("not-running"),
@Json(name = "next-exit")
NextMinusExit("next-exit"),
@Json(name = "removed")
Removed("removed")
}
/**
* Wait for a container
* Block until a container stops, then returns the exit code.
* @param id ID or name of the container
* @param condition Wait until a container state reaches the given condition. Defaults to `not-running` if omitted or empty. (optional, default to not-running)
* @return ContainerWaitResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun containerWait(id: String, condition: String?): ContainerWaitResponse {
return if (condition.isNullOrBlank()) {
containerWait(id, ConditionContainerWait.NotMinusRunning)
} else {
containerWait(id, ConditionContainerWait.valueOf(condition))
}
}
/**
* Wait for a container
* Block until a container stops, then returns the exit code.
* @param id ID or name of the container
* @param condition Wait until a container state reaches the given condition. Defaults to `not-running` if omitted or empty. (optional, default to not-running)
* @return ContainerWaitResponse
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
@JvmOverloads
fun containerWait(id: String, condition: ConditionContainerWait? = ConditionContainerWait.NotMinusRunning): ContainerWaitResponse {
val localVariableConfig = containerWaitRequestConfig(id = id, condition = condition)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> (localVarResponse as Success<*>).data as ContainerWaitResponse
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation containerWait
*
* @param id ID or name of the container
* @param condition Wait until a container state reaches the given condition. Defaults to `not-running` if omitted or empty. (optional, default to not-running)
* @return RequestConfig
*/
fun containerWaitRequestConfig(id: String, condition: ConditionContainerWait?): RequestConfig {
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
if (condition != null) {
put("condition", listOf(condition.value))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = POST,
path = "/containers/{id}/wait".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
/**
* Extract an archive of files or folders to a directory in a container
* Upload a tar archive to be extracted to a path in the filesystem of container id. `path` parameter is asserted to be a directory. If it exists as a file, 400 error will be returned with message \"not a directory\".
* @param id ID or name of the container
* @param path Path to a directory in the container to extract the archive’s contents into.
* @param inputStream The input stream must be a tar archive compressed with one of the following algorithms: `identity` (no compression), `gzip`, `bzip2`, or `xz`.
* @param noOverwriteDirNonDir If `1`, `true`, or `True` then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa. (optional)
* @param copyUIDGID If `1`, `true`, then it will copy UID/GID maps to the dest file or dir (optional)
* @return void
* @throws UnsupportedOperationException If the API returns an informational or redirection response
* @throws ClientException If the API returns a client error response
* @throws ServerException If the API returns a server error response
*/
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun putContainerArchive(id: String, path: String, inputStream: InputStream, noOverwriteDirNonDir: String?, copyUIDGID: String?) {
val localVariableConfig = putContainerArchiveRequestConfig(id = id, path = path, inputStream = inputStream, noOverwriteDirNonDir = noOverwriteDirNonDir, copyUIDGID = copyUIDGID)
val localVarResponse = request(
localVariableConfig
)
return when (localVarResponse.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> {
val localVarError = localVarResponse as ClientError<*>
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
ResponseType.ServerError -> {
val localVarError = localVarResponse as ServerError<*>
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
}
}
}
/**
* To obtain the request config of the operation putContainerArchive
*
* @param id ID or name of the container
* @param path Path to a directory in the container to extract the archive’s contents into.
* @param inputStream The input stream must be a tar archive compressed with one of the following algorithms: `identity` (no compression), `gzip`, `bzip2`, or `xz`.
* @param noOverwriteDirNonDir If `1`, `true`, or `True` then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa. (optional)
* @param copyUIDGID If `1`, `true`, then it will copy UID/GID maps to the dest file or dir (optional)
* @return RequestConfig
*/
fun putContainerArchiveRequestConfig(id: String, path: String, inputStream: InputStream, noOverwriteDirNonDir: String?, copyUIDGID: String?): RequestConfig {
val localVariableBody: Source = inputStream.source()
val localVariableQuery: MultiValueMap = mutableMapOf>()
.apply {
put("path", listOf(path))
if (noOverwriteDirNonDir != null) {
put("noOverwriteDirNonDir", listOf(noOverwriteDirNonDir.toString()))
}
if (copyUIDGID != null) {
put("copyUIDGID", listOf(copyUIDGID.toString()))
}
}
val localVariableHeaders: MutableMap = mutableMapOf()
return RequestConfig(
method = PUT,
path = "/containers/{id}/archive".replace("{" + "id" + "}", id),
query = localVariableQuery,
headers = localVariableHeaders,
body = localVariableBody
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy