lib/testlab/container/lifecycle.rb in testlab-0.9.1 vs lib/testlab/container/lifecycle.rb in testlab-1.0.0

- old
+ new

@@ -1,82 +1,65 @@ class TestLab class Container module Lifecycle - # Setup the container + # Provision the container # - # Attempts to setup the container. We first create the container, then - # attempt to bring it online. Afterwards the containers provisioner is - # called. + # Attempts to provision the container. We first create the container, + # then attempt to bring it online. Afterwards the containers provisioner + # is called. # # @return [Boolean] True if successful. - def setup - @ui.logger.debug { "Container Setup: #{self.id} " } + def provision + @ui.logger.debug { "Container Provision: #{self.id} " } (self.node.state != :running) and return false - (self.lxc.state == :not_created) and return false + (self.state != :running) and return false - please_wait(:ui => @ui, :message => format_object_action(self, 'Setup', :green)) do - - self.container_provisioners.each do |provisioner| - @ui.logger.info { ">>>>> CONTAINER PROVISIONER SETUP: #{provisioner} (#{self.id}) <<<<<" } - p = provisioner.new(self.config, @ui) - p.respond_to?(:on_container_setup) and p.on_container_setup(self) - end - + please_wait(:ui => @ui, :message => format_object_action(self, :provision, :green)) do + do_provisioner_callbacks(self, :provision, @ui) end true end - # Teardown the container + # Deprovision the container # - # Attempts to teardown the container. We first call the provisioner - # teardown method defined for the container, if any. Next we attempt to - # offline the container. Afterwards the container is destroy. + # Attempts to deprovision the container. We first call the provisioner + # deprovision method defined for the container, if any. Next we attempt + # to offline the container. Afterwards the container is destroy. # # @return [Boolean] True if successful. - def teardown - @ui.logger.debug { "Container Teardown: #{self.id} " } + def deprovision + @ui.logger.debug { "Container Deprovision: #{self.id} " } (self.node.state != :running) and return false - (self.lxc.state == :not_created) and return false + (self.state != :running) and return false - please_wait(:ui => @ui, :message => format_object_action(self, 'Teardown', :red)) do - - self.container_provisioners.each do |provisioner| - @ui.logger.info { ">>>>> CONTAINER PROVISIONER TEARDOWN: #{provisioner} (#{self.id}) <<<<<" } - p = provisioner.new(self.config, @ui) - p.respond_to?(:on_container_teardown) and p.on_container_teardown(self) - end - + please_wait(:ui => @ui, :message => format_object_action(self, :deprovision, :red)) do + do_provisioner_callbacks(self, :deprovision, @ui) end true end # Build the container def build self.create self.up - self.setup + self.provision true end # Demolish the container def demolish - self.teardown + self.deprovision self.down self.destroy true - end - - # Returns all defined provisioners for this container's networks and the container iteself. - def container_provisioners - [self.interfaces.map(&:network).map(&:provisioners), self.provisioners].flatten.compact.uniq end end end