Class: Nomad::Agent

Inherits:
Request show all
Defined in:
lib/nomad/api/agent.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

#force_leave(node, ...) ⇒ Boolean

Force a node to leave the gossip pool.

Examples:

Nomad.agent.force_leave("client-ab2e23dc")

Parameters:

  • node (String)

    A node ID to remove

  • ... (String)

    Additional nodes to remove

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/nomad/api/agent.rb', line 40

def force_leave(*nodes, **options)
  raise "Missing node(s)!" if nodes.empty?
  qs = nodes.map { |v| "node=#{CGI.escape(v)}" }.join("&")[/.+/]
  client.post("/v1/agent/force-leave?#{qs}", options)
  return true
end

#join(*addresses, **options) ⇒ AgentJoin

Join a new member to the gossip pool.

Examples:

Nomad.agent.join("1.2.3.4", "5.6.7.8") #=> #<AgentJoin...>

Parameters:

  • address (String)

    the addresses of the agents to join - this may be specified multiple times.

Returns:



24
25
26
27
28
29
# File 'lib/nomad/api/agent.rb', line 24

def join(*addresses, **options)
  raise "Missing address(es)!" if addresses.empty?
  qs = addresses.map { |v| "address=#{CGI.escape(v)}" }.join("&")[/.+/]
  json = client.post("/v1/agent/join?#{qs}", options)
  return AgentJoin.decode(json)
end

#members(options = {}) ⇒ AgentMembers

Get the list of known agent names.

Examples:

Nomad.agent.members #=> ["region1", "region2"]

Returns:



53
54
55
56
# File 'lib/nomad/api/agent.rb', line 53

def members(options = {})
  json = client.get("/v1/agent/members", options)
  return AgentMembers.decode(json)
end

#self(options = {}) ⇒ AgentSelf

Get information about the current agent (self).

Examples:

Nomad.agent.self #=> #<AgentSelf ...>

Returns:



64
65
66
67
# File 'lib/nomad/api/agent.rb', line 64

def self(options = {})
  json = client.get("/v1/agent/self", options)
  return AgentSelf.decode(json)
end

#servers(options = {}) ⇒ Object

Get the list of servers.

Examples:

Nomad.agent.servers #=> ["127.0.0.1:4647", "..."]


73
74
75
# File 'lib/nomad/api/agent.rb', line 73

def servers(options = {})
  return client.get("/v1/agent/servers", options)
end

#update_servers(*addresses, **options) ⇒ Boolean

Updates the list of servers.

Examples:

Nomad.agent.update_servers(addresses: ["1.2.3.4:4647"])

Returns:

  • (Boolean)


83
84
85
86
87
88
# File 'lib/nomad/api/agent.rb', line 83

def update_servers(*addresses, **options)
  raise "Missing address(es)!" if addresses.empty?
  qs = addresses.map { |v| "address=#{CGI.escape(v)}" }.join("&")[/.+/]
  client.post("/v1/agent/servers?#{qs}", options)
  return true
end