lib/testlab/container.rb in testlab-1.5.1 vs lib/testlab/container.rb in testlab-1.6.0

- old
+ new

@@ -70,11 +70,11 @@ class Container < ZTK::DSL::Base # An array of symbols of the various keys in our status hash. # # @see TestLab::Container::Status - STATUS_KEYS = %w(id node_id mode fqdn state distro release interfaces provisioners).map(&:to_sym) + STATUS_KEYS = %w(id node_id mode fqdn state distro release interfaces provisioners inherited).map(&:to_sym) # Sub-Modules autoload :Actions, 'testlab/container/actions' autoload :ClassMethods, 'testlab/container/class_methods' autoload :Clone, 'testlab/container/clone' @@ -123,21 +123,56 @@ attribute :distro, :default => 'ubuntu' attribute :release, :default => 'precise' attribute :arch + attribute :tags, :default => Array.new + # Instructs ephemeral containers to persist; otherwise tmpfs will be used # as the backend store for ephemeral containers. # NOTE: tmpfs is very memory intensive and is disabled by default. attribute :persist, :default => true + # Is this a template? Never build it if so. + attribute :template, :default => false + # Should we inherit a container? + attribute :inherit + + def initialize(*args) @ui = TestLab.ui - @ui.logger.info { "Loading Container '#{self.id}'" } + @ui.logger.debug { "Loading Container" } super(*args) - @ui.logger.info { "Container '#{self.id}' Loaded" } + @ui.logger.debug { "Container '#{self.id}' Loaded" } + + self.tags ||= [ self.id ] + + if !self.inherit.nil? + @ui.logger.debug { "INHERIT: #{self.inherit}" } + + parent = TestLab::Container.first(self.inherit) + if parent.nil? + raise ContainerError, "Could not find the container you specified to inherit attributes from!" + end + + # Inherit the containers attributes + parent.attributes.reject{ |k,v| [:id, :node_id, :inherit, :template].include?(k) }.each do |key, value| + self.send("#{key}=", (value.dup rescue value)) + end + + # Inherit the containers users + parent.users.each do |user| + inherited_user = TestLab::User.new + inherited_user.container_id = self.id + + user.attributes.reject{ |k,v| [:id, :container_id].include?(k) }.each do |key, value| + inherited_user.send("#{key}=", (value.dup rescue value)) + end + end + + end end def config_dir self.node.config_dir end