Class: Diplomat::Maintenance
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Maintenance
- Defined in:
- lib/diplomat/maintenance.rb
Overview
Methods to interact with the Consul maintenance API endpoint
Instance Method Summary collapse
-
#enable(enable = true, reason = nil, options = nil) ⇒ Object
Enable or disable maintenance mode.
-
#enabled(n, options = nil) ⇒ Hash
Get the maintenance state of a host.
Methods inherited from RestClient
access_method?, #concat_url, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter
Constructor Details
This class inherits a constructor from Diplomat::RestClient
Instance Method Details
#enable(enable = true, reason = nil, options = nil) ⇒ Object
Enable or disable maintenance mode. This endpoint only works on the local agent. rubocop:disable AbcSize
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/diplomat/maintenance.rb', line 29 def enable(enable = true, reason = nil, = nil) raw = @conn.put do |req| url = ['/v1/agent/maintenance'] url << use_named_parameter('enable', enable.to_s) url << use_named_parameter('reason', reason) if reason url << use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end return_status = raw.status == 200 raise Diplomat::UnknownStatus, "status #{raw.status}: #{raw.body}" unless return_status return_status end |
#enabled(n, options = nil) ⇒ Hash
Get the maintenance state of a host
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/diplomat/maintenance.rb', line 10 def enabled(n, = nil) health = Diplomat::Health.new(@conn) result = health.node(n, ) .select { |check| check['CheckID'] == '_node_maintenance' } if result.empty? { enabled: false, reason: nil } else { enabled: true, reason: result.first['Notes'] } end end |