Class: Vmreverter::ConfigTester
- Inherits:
-
Object
- Object
- Vmreverter::ConfigTester
- Defined in:
- lib/vmreverter/config_tester.rb
Overview
Config was taken by Ruby.
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#dump ⇒ Object
Print out test configuration.
-
#initialize(config_file, options) ⇒ ConfigTester
constructor
A new instance of ConfigTester.
- #load_file(config_file) ⇒ Object
Constructor Details
#initialize(config_file, options) ⇒ ConfigTester
Returns a new instance of ConfigTester.
8 9 10 11 12 |
# File 'lib/vmreverter/config_tester.rb', line 8 def initialize(config_file, ) @options = @logger = [:logger] @config = load_file(config_file) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/vmreverter/config_tester.rb', line 7 def logger @logger end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 |
# File 'lib/vmreverter/config_tester.rb', line 14 def [](key) @config[key] end |
#dump ⇒ Object
Print out test configuration
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vmreverter/config_tester.rb', line 48 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vmreverter/config_tester.rb', line 18 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})"), "ConfigTester::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})"), "ConfigTester::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})"), "ConfigTester::load_file") unless config['HOSTS'][host].include? "snapshot" end end # Merge some useful date into the config hash config['CONFIG'] ||= {} config end |