Class: EY::Stonith::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_stonith/config.rb

Defined Under Namespace

Classes: Error, FileNotFound, RequiredSetting

Constant Summary collapse

DEFAULT =
{
  'log'             => '/var/log/stonith.log',
  'state_dir'       => '/var/run/stonith',
  'heartbeat'       => 10,
  'endpoint_uri'    => nil,
  'endpoint_token'  => nil,
  'endpoint_id'     => nil,
  'monitor_host'    => nil,
  'monitor_path'    => '/haproxy/monitor',
  'monitor_timeout' => 5,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Config

Returns a new instance of Config.

Raises:



37
38
39
40
41
42
43
44
# File 'lib/ey_stonith/config.rb', line 37

def initialize(config_path)
  path = Pathname.new(config_path)
  raise FileNotFound.new(path) unless path.readable?

  realpath = path.realpath
  @data = DEFAULT.merge(YAML.load_file(realpath))
  @path = realpath
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (private)



105
106
107
108
109
110
111
112
# File 'lib/ey_stonith/config.rb', line 105

def method_missing(meth, *args)
  meth_s = meth.to_s
  if respond_to?(meth_s)
    @data[meth_s] || raise(RequiredSetting.new(path, meth_s))
  else
    super
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



46
47
48
# File 'lib/ey_stonith/config.rb', line 46

def path
  @path
end

Instance Method Details

#endpoint_uriObject



77
# File 'lib/ey_stonith/config.rb', line 77

def endpoint_uri()  URI.parse(method_missing('endpoint_uri')) end

#history_pathObject



75
# File 'lib/ey_stonith/config.rb', line 75

def history_path()  state_path + 'history' end

#log_pathObject



72
# File 'lib/ey_stonith/config.rb', line 72

def log_path()      pathname(log) end

#notify_uriObject



78
79
80
81
82
# File 'lib/ey_stonith/config.rb', line 78

def notify_uri
  result = endpoint_uri
  result.path << NOTIFY_PATH
  result
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/ey_stonith/config.rb', line 84

def respond_to?(meth)
  @data.key?(meth) || super
end

#state_pathObject



73
# File 'lib/ey_stonith/config.rb', line 73

def state_path()    ensure_exists(pathname(state_dir)) end

#stop_pathObject



74
# File 'lib/ey_stonith/config.rb', line 74

def stop_path()     state_path + 'stop' end

#success_pathObject



76
# File 'lib/ey_stonith/config.rb', line 76

def success_path()  state_path + 'success' end

#to_sObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ey_stonith/config.rb', line 48

def to_s()
  return <<-STRING
Config:
  config file: #{@path}

  log_path: #{log_path}
  heartbeat: #{heartbeat}

  state_path:    #{state_path}
  stop_path:     #{stop_path}
  history_path:  #{history_path}
  success_path:  #{success_path}

  endpoint_uri:   #{endpoint_uri}
  endpoint_token: #{endpoint_token}
  endpoint_id:    #{endpoint_id}
  notify_uri:     #{notify_uri}

  monitor_host:    #{monitor_host}
  monitor_path:    #{monitor_path}
  monitor_timeout: #{monitor_timeout}
  STRING
end