Class: InstructureRegistrar::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/instructure_registrar/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
# File 'lib/instructure_registrar/client.rb', line 8

def initialize
  @server_available = healthcheck
end

Instance Attribute Details

#server_availableObject (readonly)

Returns the value of attribute server_available.



6
7
8
# File 'lib/instructure_registrar/client.rb', line 6

def server_available
  @server_available
end

Instance Method Details

#healthcheckObject



12
13
14
15
16
17
18
19
# File 'lib/instructure_registrar/client.rb', line 12

def healthcheck
#      begin
    client.version
#      rescue
  #   p "WARNING: etcd server unavailable"
  #   false
  # end
end

#lookup(service_name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/instructure_registrar/client.rb', line 21

def lookup(service_name)
  begin
    client.get("/#{service_name}").value
  rescue Etcd::KeyNotFound
    "unknown"
  end
end

#registerObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/instructure_registrar/client.rb', line 29

def register
  return unless server_available
  InstructureRegistrar.config.service_config.keys.each do |key|
    p "InstructureRegistrar setting #{InstructureRegistrar.config.service_name}/#{key} on #{InstructureRegistrar.config.registry_host}..."
    client.set(
      "/#{InstructureRegistrar.config.service_name}/#{key}",
      value: InstructureRegistrar.config.service_config[key]
    )
  end
end

#unregisterObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/instructure_registrar/client.rb', line 40

def unregister
  return unless server_available
  begin
    InstructureRegistrar.config.service_config.keys.each do |key|
      client.delete(
        "/#{InstructureRegistrar.config.service_name}/#{key}",
        value: InstructureRegistrar.config.service_config[key]
      )
    end
  rescue Etcd::KeyNotFound
    false
  end
end