lib/docker_engine_api/api/volume.ex

# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.

defmodule DockerEngineAPI.Api.Volume do
  @moduledoc """
  API calls for all endpoints tagged `Volume`.
  """

  alias DockerEngineAPI.Connection
  import DockerEngineAPI.RequestBuilder

  @doc """
  Create a volume

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - volume_config (VolumeCreateOptions): Volume configuration
  - opts (KeywordList): [optional] Optional parameters

  ## Returns

  {:ok, %DockerEngineAPI.Model.Volume{}} on success
  {:error, info} on failure
  """
  def volume_create(connection, volume_config, _opts \\ []) do
    %{}
    |> method(:post)
    |> url("/volumes/create")
    |> add_param(:body, :volumeConfig, volume_config)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(%DockerEngineAPI.Model.Volume{})
  end

  @doc """
  Remove a volume
  Instruct the driver to remove the volume.

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - name (String.t): Volume name or ID
  - opts (KeywordList): [optional] Optional parameters
    - :force (boolean()): Force the removal of the volume

  ## Returns

  {:ok, %{}} on success
  {:error, info} on failure
  """
  def volume_delete(connection, name, opts \\ []) do
    optional_params = %{
      :force => :query
    }

    %{}
    |> method(:delete)
    |> url("/volumes/#{name}")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(false)
  end

  @doc """
  Inspect a volume

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - name (String.t): Volume name or ID
  - opts (KeywordList): [optional] Optional parameters

  ## Returns

  {:ok, %DockerEngineAPI.Model.Volume{}} on success
  {:error, info} on failure
  """
  def volume_inspect(connection, name, _opts \\ []) do
    %{}
    |> method(:get)
    |> url("/volumes/#{name}")
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(%DockerEngineAPI.Model.Volume{})
  end

  @doc """
  List volumes

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :filters (String.t): JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. Available filters:  - `dangling=<boolean>` When set to `true` (or `1`), returns all    volumes that are not in use by a container. When set to `false`    (or `0`), only volumes that are in use by one or more    containers are returned. - `driver=<volume-driver-name>` Matches volumes based on their driver. - `label=<key>` or `label=<key>:<value>` Matches volumes based on    the presence of a `label` alone or a `label` and a value. - `name=<volume-name>` Matches all or part of a volume name. 

  ## Returns

  {:ok, %DockerEngineAPI.Model.VolumeListResponse{}} on success
  {:error, info} on failure
  """
  def volume_list(connection, opts \\ []) do
    optional_params = %{
      :filters => :query
    }

    %{}
    |> method(:get)
    |> url("/volumes")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(%DockerEngineAPI.Model.VolumeListResponse{})
  end

  @doc """
  Delete unused volumes

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :filters (String.t): Filters to process on the prune list, encoded as JSON (a `map[string][]string`).  Available filters: - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune volumes with (or without, in case `label!=...` is used) the specified labels. - `all` (`all=true`) - Consider all (local) volumes for pruning and not just anonymous volumes. 

  ## Returns

  {:ok, %DockerEngineAPI.Model.VolumePruneResponse{}} on success
  {:error, info} on failure
  """
  def volume_prune(connection, opts \\ []) do
    optional_params = %{
      :filters => :query
    }

    %{}
    |> method(:post)
    |> url("/volumes/prune")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(%DockerEngineAPI.Model.VolumePruneResponse{})
  end

  @doc """
  \"Update a volume. Valid only for Swarm cluster volumes\" 

  ## Parameters

  - connection (DockerEngineAPI.Connection): Connection to server
  - name (String.t): The name or ID of the volume
  - version (integer()): The version number of the volume being updated. This is required to avoid conflicting writes. Found in the volume's `ClusterVolume` field. 
  - opts (KeywordList): [optional] Optional parameters
    - :body (Body): The spec of the volume to update. Currently, only Availability may change. All other fields must remain unchanged. 

  ## Returns

  {:ok, %{}} on success
  {:error, info} on failure
  """
  def volume_update(connection, name, version, opts \\ []) do
    optional_params = %{
      :body => :body
    }

    %{}
    |> method(:put)
    |> url("/volumes/#{name}")
    |> add_param(:query, :version, version)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> decode(false)
  end
end