lib/testlab/container/actions.rb in testlab-1.1.0 vs lib/testlab/container/actions.rb in testlab-1.2.0

- old
+ new

@@ -13,10 +13,13 @@ @ui.logger.debug { "Container Create: #{self.id}" } (self.node.state != :running) and return false (self.lxc.state != :not_created) and return false + # If we are in ephemeral mode do not attempt to create the container. + self.lxc_clone.exists? and return false + please_wait(:ui => @ui, :message => format_object_action(self, 'Create', :green)) do configure self.lxc.create(*create_args) @@ -35,13 +38,15 @@ @ui.logger.debug { "Container Destroy: #{self.id}" } (self.node.state != :running) and return false (self.lxc.state == :not_created) and return false + # If we are in ephemeral mode do not attempt to destroy the container. + self.lxc_clone.exists? and return false + please_wait(:ui => @ui, :message => format_object_action(self, 'Destroy', :red)) do self.lxc.destroy(%(-f)) - self.lxc_clone.destroy(%(-f)) do_provisioner_callbacks(self, :destroy, @ui) end true @@ -59,21 +64,32 @@ (self.lxc.state == :running) and return false please_wait(:ui => @ui, :message => format_object_action(self, 'Up', :green)) do configure - # ensure our container is in "static" mode - self.to_static + # Remove any existing ARP entries for our container from the node. + self.interfaces.each do |interface| + self.node.exec(%(sudo arp --verbose --delete #{interface.ip}), :ignore_exit_status => true) + end - self.lxc.start(%(--daemon)) + if self.lxc_clone.exists? + self.lxc_clone.start_ephemeral(clone_args) + else + self.lxc.start(%(--daemon)) + end (self.lxc.state != :running) and raise ContainerError, "The container failed to online!" - self.users.each do |user| - user.provision + # If we are not in ephemeral mode we should attempt to provision our + # defined users. + if !self.lxc_clone.exists? + self.users.each do |user| + user.provision + end end + # Ensure the hostname is set self.exec(%(sudo hostname #{self.fqdn})) do_provisioner_callbacks(self, :up, @ui) end @@ -90,10 +106,25 @@ (self.node.state != :running) and return false (self.lxc.state != :running) and return false please_wait(:ui => @ui, :message => format_object_action(self, 'Down', :red)) do + self.lxc.stop + + # If we are in ephemeral mode... + if self.lxc_clone.exists? + + # IMPORTANT NOTE: + # + # If we are using a non-memory backed COW filesystem for the + # ephemeral clones we should destroy the container. + # + # If we are using a memory backed COW filesystem for the ephemeral + # clones then it will be released when the container is stopped. + + self.persist and self.lxc.destroy(%(-f)) + end (self.lxc.state == :running) and raise ContainerError, "The container failed to offline!" do_provisioner_callbacks(self, :down, @ui) end