Class: Nomad::Node

Inherits:
Request show all
Defined in:
lib/nomad/api/node.rb

Instance Attribute Summary

Attributes inherited from Request

#client

Instance Method Summary collapse

Methods inherited from Request

#initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Nomad::Request

Instance Method Details

#drain(node_id, enable = true, **options) ⇒ NodeEvaluation

Toggle drain mode for the node.

Examples:

Nomad.node.drain("abcd1234", true) #=> #<NodeEvaluation ...>
Nomad.node.drain("abcd1234", false)

Parameters:

  • node_id (String)

    The node ID to drain

  • enable (Boolean) (defaults to: true)

    whether to enable or disable drain mode

Returns:



72
73
74
75
76
# File 'lib/nomad/api/node.rb', line 72

def drain(node_id, enable = true, **options)
  url = "/v1/node/#{CGI.escape(node_id)}/drain?enable=#{enable}"
  json = client.post(url, options)
  return NodeEvaluation.decode(json)
end

#evaluate(node_id, **options) ⇒ NodeEvaluation

Create a new evaluation for the given node.

Examples:

Nomad.node.evaluate("abcd1234")

Parameters:

  • node_id (String)

    The ID of the node

Returns:



57
58
59
60
# File 'lib/nomad/api/node.rb', line 57

def evaluate(node_id, **options)
  json = client.post("/v1/node/#{CGI.escape(node_id)}/evaluate", options)
  return NodeEvaluation.decode(json)
end

#list(**options) ⇒ String

Get the address and port of the current leader for this region

Examples:

Nomad.node.list #=> [#<Node ...>]

Parameters:

  • [String] (Hash)

    a customizable set of options

Returns:

  • (String)


23
24
25
26
# File 'lib/nomad/api/node.rb', line 23

def list(**options)
  json = client.get("/v1/nodes", options)
  return json.map { |item| NodeItem.decode(item) }
end

#read(node_id, **options) ⇒ NodeItem?

Get detailed information about the node.

Examples:

Nomad.node.read("abcd1234") #=> #<Node ...>

Parameters:

  • node_id (String)

    The ID of the ndoe

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nomad/api/node.rb', line 36

def read(node_id, **options)
  json = client.get("/v1/node/#{CGI.escape(node_id)}", options)
  return NodeItem.decode(json)
rescue Nomad::HTTPError => e
  # This is really jank, but Nomad doesn't return a 404 and returns a 500
  # instead, so we have to inspect the output.
  if e.errors.any? { |err| err.include?("node lookup failed") }
    return nil
  else
    raise
  end
end