lib/testlab.rb in testlab-0.6.17 vs lib/testlab.rb in testlab-0.7.0

- old
+ new

@@ -23,11 +23,11 @@ # apt-get -y install dnsutils # EOF # # config Hash[ # :domain => "default.zone", -# :repo => File.join(ENV['HOME'], "code", "personal", "testlab-repo") +# :repo => File.join(Dir.home, "code", "personal", "testlab-repo") # ] # # node :localhost do # components %w(resolv bind) # route true @@ -82,10 +82,12 @@ # testlab.teardown # teardown the lab, destroy all networks and containers # # @author Zachary Patten <zachary AT jovelabs DOT com> class TestLab + HOSTNAME ||= Socket.gethostname.split('.').first.strip + # TestLab Error Class class TestLabError < StandardError; end # Main Classes autoload :Container, 'testlab/container' @@ -98,17 +100,22 @@ autoload :User, 'testlab/user' autoload :Utility, 'testlab/utility' include TestLab::Utility::Misc + attr_accessor :config_dir + def initialize(options={}) - self.ui = (options[:ui] || ZTK::UI.new) + self.ui = (options[:ui] || ZTK::UI.new) + self.class.ui = self.ui - labfile = (options[:labfile] || File.join(Dir.pwd, 'Labfile')) - labfile_path = ZTK::Locator.find(labfile) - @labfile = TestLab::Labfile.load(labfile_path) - @labfile.config.merge!(:testlab => self) + @config_dir = (options[:config_dir] || File.join(Dir.pwd, ".testlab-#{HOSTNAME}")) + + labfile = (options[:labfile] || File.join(Dir.pwd, 'Labfile')) + labfile_path = ZTK::Locator.find(labfile) + @labfile = TestLab::Labfile.load(labfile_path) + @labfile.testlab = self end # Test Lab Nodes # # Returns an array of our defined nodes. @@ -134,10 +141,19 @@ # @return [Array<TestLab::Network>] An array of all defined networks. def networks TestLab::Network.all end + # Test Lab Labfile + # + # Returns our top-level Labfile instance. + # + # @return [TestLab::Labfile] The top-level Labfile instance. + def labfile + @labfile + end + # Test Lab Configuration # # The hash defined in our *Labfile* DSL object which represents any high-level # lab configuration options. # @@ -270,21 +286,9 @@ node.networks.reverse.each do |network| network.send(method_name, *method_args) end node.send(method_name, *method_args) end - end - - # TestLab Configuration Directory - # - # Returns the path to the test lab configuration directory which is located - # off the repo directory under '.testlab'. - # - # @return [String] The path to the TestLab configuration directory. - def config_dir - @hostname ||= Socket.gethostname.split('.').first.strip - directory = File.join(self.config[:repo], ".testlab-#{@hostname}") - File.expand_path(directory, File.dirname(__FILE__)) end # Provider Method Handler # # Proxies missing provider method calls to all nodes.