lib/nomad_client/api/nodes.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.Nodes do
  @moduledoc """
  API calls for all endpoints tagged `Nodes`.
  """

  alias NomadClient.Connection
  import NomadClient.RequestBuilder

  @doc """
  creates a new evaluation for the given node. This can be used to force a run of the scheduling logic

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node_id (String.t): Specifies the ID of the node. This must be the full UUID, not the short 8-character one. 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.NodeEvalResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec evaluate_node(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.NodeEvalResponse.t()} | {:error, Tesla.Env.t()}
  def evaluate_node(connection, node_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/node/#{node_id}/evaluate")
    |> add_optional_params(optional_params, opts)
    |> ensure_body()
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.NodeEvalResponse{}}
    ])
  end

  @doc """
  lists all of the allocations for the given node
  This can be used to determine what allocations have been scheduled on the node, their current status, and the values of dynamically assigned resources, like ports

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node_id (String.t): Specifies the ID of the node. This must be the full UUID, not the short 8-character one. 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, [%AllocationListStub{}, ...]} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_allocations_for_node(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, list(NomadClient.Model.AllocationListStub.t())} | {:error, Tesla.Env.t()}
  def get_allocations_for_node(connection, node_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

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

  @doc """
  queries the status of a client node

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node_id (String.t): Specifies the ID of the node. This must be the full UUID, not the short 8-character one. 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.Node.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec get_node(Tesla.Env.client(), String.t(), keyword()) ::
          {:ok, NomadClient.Model.Node.t()} | {:error, Tesla.Env.t()}
  def get_node(connection, node_id, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

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

  @doc """
  lists all nodes registered with Nomad

  ## 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
    - :prefix (String.t): Specifies a string to filter jobs on based on an index prefix. This is specified as a query string parameter
  ## Returns

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

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

  @doc """
  returns matches for a given prefix and context, where a context can be jobs, allocations, evaluations, nodes, or deployments
  When using Nomad Enterprise, the allowed contexts include quotas and namespaces. Additionally, a prefix can be searched for within every context

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - search_request (SearchRequest): 
  - 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.SearchResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec search(Tesla.Env.client(), NomadClient.Model.SearchRequest.t(), keyword()) ::
          {:ok, NomadClient.Model.SearchResponse.t()} | {:error, Tesla.Env.t()}
  def search(connection, search_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/search")
    |> add_param(:body, :body, search_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.SearchResponse{}}
    ])
  end

  @doc """
  toggles the drain mode of the node
  When draining is enabled, no further allocations will be assigned to this node, and existing allocations will be migrated to new nodes

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node_id (String.t): Specifies the ID of the node. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - node_update_drain_request (NodeUpdateDrainRequest): 
  - 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.NodeDrainUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec update_drain_mode_for_node(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.NodeUpdateDrainRequest.t(),
          keyword()
        ) :: {:ok, NomadClient.Model.NodeDrainUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def update_drain_mode_for_node(connection, node_id, node_update_drain_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/node/#{node_id}/drain")
    |> add_param(:body, :body, node_update_drain_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.NodeDrainUpdateResponse{}}
    ])
  end

  @doc """
  toggles the scheduling eligibility of the node

  ## Parameters

  - connection (NomadClient.Connection): Connection to server
  - node_id (String.t): Specifies the ID of the node. This must be the full UUID, not the short 8-character one. This is specified as part of the path
  - node_update_eligibility_request (NodeUpdateEligibilityRequest): 
  - 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.NodeEligibilityUpdateResponse.t} on success
  {:error, Tesla.Env.t} on failure
  """
  @spec update_node_eligibility(
          Tesla.Env.client(),
          String.t(),
          NomadClient.Model.NodeUpdateEligibilityRequest.t(),
          keyword()
        ) :: {:ok, NomadClient.Model.NodeEligibilityUpdateResponse.t()} | {:error, Tesla.Env.t()}
  def update_node_eligibility(connection, node_id, node_update_eligibility_request, opts \\ []) do
    optional_params = %{
      :namespace => :query,
      :region => :query,
      :index => :query,
      :wait => :query
    }

    %{}
    |> method(:post)
    |> url("/node/#{node_id}/eligibility")
    |> add_param(:body, :body, node_update_eligibility_request)
    |> add_optional_params(optional_params, opts)
    |> Enum.into([])
    |> (&Connection.request(connection, &1)).()
    |> evaluate_response([
      {200, %NomadClient.Model.NodeEligibilityUpdateResponse{}}
    ])
  end
end