lib/testlab/node.rb in testlab-0.0.4 vs lib/testlab/node.rb in testlab-0.1.0
- old
+ new
@@ -7,10 +7,31 @@
#
# @author Zachary Patten <zachary@jovelabs.net>
class Node < ZTK::DSL::Base
STATUS_KEYS = %w(id instance_id state user ip port provider con net rtr).map(&:to_sym)
+ # Sub-Modules
+ autoload :Bind, 'testlab/node/bind'
+ autoload :ClassMethods, 'testlab/node/class_methods'
+ autoload :Lifecycle, 'testlab/node/lifecycle'
+ autoload :LXC, 'testlab/node/lxc'
+ autoload :MethodMissing, 'testlab/node/method_missing'
+ autoload :Resolv, 'testlab/node/resolv'
+ autoload :SSH, 'testlab/node/ssh'
+ autoload :Status, 'testlab/node/status'
+
+ include TestLab::Node::Bind
+ include TestLab::Node::Lifecycle
+ include TestLab::Node::LXC
+ include TestLab::Node::MethodMissing
+ include TestLab::Node::Resolv
+ include TestLab::Node::SSH
+ include TestLab::Node::Status
+
+ extend TestLab::Node::ClassMethods
+
+ # Associations and Attributes
belongs_to :labfile, :class_name => 'TestLab::Lab'
has_many :routers, :class_name => 'TestLab::Router'
has_many :containers, :class_name => 'TestLab::Container'
has_many :networks, :class_name => 'TestLab::Network'
@@ -18,77 +39,14 @@
attribute :provider
attribute :config
attribute :components
- autoload :Bind, 'testlab/node/bind'
- autoload :Lifecycle, 'testlab/node/lifecycle'
- autoload :LXC, 'testlab/node/lxc'
- autoload :Resolv, 'testlab/node/resolv'
- autoload :SSH, 'testlab/node/ssh'
- autoload :Status, 'testlab/node/status'
-
- include TestLab::Node::Bind
- include TestLab::Node::Lifecycle
- include TestLab::Node::LXC
- include TestLab::Node::Resolv
- include TestLab::Node::SSH
- include TestLab::Node::Status
-
-
def initialize(*args)
super(*args)
@ui = TestLab.ui
@provider = self.provider.new(self.config)
- end
-
-################################################################################
-
- # Iterates an array of arrays calling the specified method on all the
- # collections of objects
- def call_collections(collections, method_name)
- collections.each do |collection|
- call_methods(collection, method_name)
- end
- end
-
- # Calls the specified method on all the objects supplied
- def call_methods(objects, method_name)
- objects.each do |object|
- if object.respond_to?(method_name)
- object.send(method_name)
- end
- end
- end
-
- # Method missing handler
- def method_missing(method_name, *method_args)
- @ui.logger.debug { "NODE METHOD MISSING: #{method_name.inspect}(#{method_args.inspect})" }
-
- if TestLab::Provider::PROXY_METHODS.include?(method_name)
- result = nil
-
- if @provider.respond_to?(method_name)
- @ui.logger.debug { "@provider.send(#{method_name.inspect}, #{method_args.inspect})" }
- result = @provider.send(method_name, *method_args)
- else
- raise TestLab::ProviderError, "Your provider does not respond to the method '#{method_name}'!"
- end
-
- result
- else
- super(method_name, *method_args)
- end
- end
-
- class << self
-
- # Returns the path to the gems provider templates
- def template_dir
- File.join(TestLab.gem_dir, "lib", "testlab", "node", "templates")
- end
-
end
end
end