Class: Vmreverter::Configuration
- Inherits:
-
Object
- Object
- Vmreverter::Configuration
- Includes:
- Singleton
- Defined in:
- lib/vmreverter/configuration.rb
Overview
Config was taken by Ruby.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#dump ⇒ Object
Print out test configuration.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_file(config_file) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
15 16 17 18 19 20 |
# File 'lib/vmreverter/configuration.rb', line 15 def initialize @options = @@options @logger = @@logger config_file = @options[:config] @config = load_file(config_file) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/vmreverter/configuration.rb', line 8 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/vmreverter/configuration.rb', line 8 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/vmreverter/configuration.rb', line 8 def @options end |
Class Method Details
.build(options, logger) ⇒ Object
10 11 12 13 |
# File 'lib/vmreverter/configuration.rb', line 10 def self.build(, logger) @@options = @@logger = logger end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/vmreverter/configuration.rb', line 22 def [](key) @config[key] end |
#dump ⇒ Object
Print out test configuration
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vmreverter/configuration.rb', line 56 def dump # Access "tags" for each host @config["HOSTS"].each_key do|host| @config["HOSTS"][host]['tags'].each do |tag| @logger.notify "Tags for #{host} #{tag}" end end # Access @config keys/values @config["CONFIG"].each_key do|cfg| @logger.notify "Config Key|Val: #{cfg} #{@config["CONFIG"][cfg].inspect}" end end |
#load_file(config_file) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vmreverter/configuration.rb', line 26 def load_file(config_file) if config_file.is_a? Hash config = config_file else config = YAML.load_file(config_file) # Make sure the tag array is present for all hosts config['HOSTS'].each_key do |host| config['HOSTS'][host]['tags'] ||= [] report_and_raise(@logger, RuntimeError.new("Missing hypervisor: (#{host})"), "Configuration::load_file") unless config['HOSTS'][host].include? "hypervisor" hypervisor = config['HOSTS'][host]['hypervisor'].downcase #check to see if this host has a hypervisor report_and_raise(@logger, RuntimeError.new("Invalid hypervisor: #{hypervisor} (#{host})"), "Configuration::load_file") unless Vmreverter::HYPERVISOR_TYPES.include? hypervisor #check to see if this host has a hypervisor report_and_raise(@logger, RuntimeError.new("Missing snapshot: (#{host})"), "Configuration::load_file") unless config['HOSTS'][host].include? "snapshot" end end # Merge some useful date into the config hash config['CONFIG'] ||= {} config end |