Class: Snapshoter::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/snapshoter/config.rb', line 11

def initialize(config)
  @aws_public_key = config.delete('aws_public_key')
  @aws_private_key = config.delete('aws_private_key')
  @log_file  = config.delete('log_file')
  @log_level = config.delete('log_level')
  
  @volumes = []
  
  config.keys.each do |volume_id|
    volume_options = config[volume_id]
    if volume_options.is_a? Hash
      begin
        @volumes << Snapshoter::Volume.new(volume_id, config[volume_id])
      rescue Snapshoter::VolumeInvalid => e
        raise ConfigError.new(e.message)
      end
      config.delete(volume_id)
    end
  end
  
  if config.any?
    raise ConfigError.new("Invalid config option(s) #{config.keys.map{|k| "'#{k}'"}.join(',')}")
  end
end

Instance Attribute Details

#aws_private_keyObject (readonly)

Returns the value of attribute aws_private_key.



9
10
11
# File 'lib/snapshoter/config.rb', line 9

def aws_private_key
  @aws_private_key
end

#aws_public_keyObject (readonly)

Returns the value of attribute aws_public_key.



9
10
11
# File 'lib/snapshoter/config.rb', line 9

def aws_public_key
  @aws_public_key
end

#volumesObject (readonly)

Returns the value of attribute volumes.



9
10
11
# File 'lib/snapshoter/config.rb', line 9

def volumes
  @volumes
end

Class Method Details

.read(path = '/etc/snapshoter.yml') ⇒ Object



55
56
57
58
# File 'lib/snapshoter/config.rb', line 55

def Config.read(path='/etc/snapshoter.yml')
  config = YAML.load(File.read(path))
  Config.new(config)
end

Instance Method Details

#loggerObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/snapshoter/config.rb', line 36

def logger
  @logger ||= begin
    logger = Logger.new(@log_file || STDOUT)
    logger.level = case @log_level
      when 'warn'
        Logger::WARN
      when 'error'
        Logger::ERROR
      when 'FATAL'
        Logger::FATAL
      when 'debug'
        Logger::DEBUG
      else
        Logger::INFO
      end
    logger
  end
end