lib/nomad_client/api/volumes.ex

# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.

defmodule NomadClient.Api.Volumes do
  @moduledoc """
  API calls for all endpoints tagged `Volumes`.
  """

  alias NomadClient.Connection
  import NomadClient.RequestBuilder

  @doc """
  deregisters an external volume with Nomad. It is an error to deregister a volume that is in use

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - volume_id (String.t): Specifies the ID of the volume. This must be the full ID. This is specified as part of the path
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, nil} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec deregister_volume(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, nil} | {:error, Tesla.Env.t()}
  def deregister_volume(connection, volume_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:delete)
    |> url("/volume/csi/#{volume_id}")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, false}
    ])
  end

  @doc """
  reads information about a specific volume

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - volume_id (String.t): Specifies the ID of the volume. This must be the full ID. This is specified as part of the path
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, NomadClient.Model.CsiVolume.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_volume(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.CsiVolume.t()} | {:error, Tesla.Env.t()}
  def get_volume(connection, volume_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:get)
    |> url("/volume/csi/#{volume_id}")
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.CsiVolume{}}
    ])
  end

  @doc """
  lists all volumes

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
    - :type (String.t): Specifies the type of volume to query. Currently only supports csi. This is specified as a query string parameter. Returns an empty list if omitted
    - :node_id (String.t): node id
    - :plugin_id (String.t): Specifies a string to filter volumes based on a plugin ID prefix
  ## Returns

  {:ok, [%CsiVolumeListStub{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_volumes(Tesla.Env.client(), keyword()) ::
          {:ok, list(NomadClient.Model.CsiVolumeListStub.t())} | {:error, Tesla.Env.t()}
  def get_volumes(connection, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query,
      :type => :query,
      :node_id => :query,
      :plugin_id => :query
    }

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

  @doc """
  registers an external volume with Nomad. It is an error to register an existing volume

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - volume_id (String.t): Specifies the ID of the volume. This must be the full ID. This is specified as part of the path
  - csi_volume_register_request (CsiVolumeRegisterRequest): 
  - opts (KeywordList): [optional] Optional parameters
    - :namespace (String.t): 
    - :region (String.t): Make a request across regions to the given region
    - :index (integer()): index used for blocking requests
    - :wait (String.t): wait time used for blocking requests
  ## Returns

  {:ok, nil} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec register_volume(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.CsiVolumeRegisterRequest.t(),
          keyword()
        ) :: {:ok, nil} | {:error, Tesla.Env.t()}
  def register_volume(connection, volume_id, csi_volume_register_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:put)
    |> url("/volume/csi/#{volume_id}")
    |> add_param(:body, :body, csi_volume_register_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, false}
    ])
  end
end