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

- old
+ new

@@ -99,22 +99,35 @@ # Copy the container # # Duplicates this container under another container definition. # # @return [Boolean] True if successful. - def copy(to_name) + def copy(target_name) @ui.logger.debug { "Container Copy: #{self.id}" } - to_container = self.node.containers.select{ |c| c.id.to_sym == to_name.to_sym }.first - to_container.nil? and raise ContainerError, "We could not locate the target container!" + target_name.nil? and raise ContainerError, "You must supply a destination container!" - to_container.demolish - to_container.create + target_container = self.node.containers.select{ |c| c.id.to_sym == target_name.to_sym }.first + target_container.nil? and raise ContainerError, "We could not locate the target container!" + source_state = self.state + target_state = target_container.state + + target_container.demolish + target_container.create + + self.down please_wait(:ui => @ui, :message => format_object_action(self, 'Copy', :yellow)) do - self.node.ssh.exec(%(sudo rm -rf #{to_container.lxc.fs_root})) - self.node.ssh.exec(%(sudo rsync -a #{self.lxc.fs_root} #{to_container.lxc.container_root})) + self.node.ssh.exec(%(sudo rm -rf #{target_container.lxc.fs_root})) + self.node.ssh.exec(%(sudo rsync -a #{self.lxc.fs_root} #{target_container.lxc.container_root})) + self.node.ssh.exec(%(sudo rm -fv #{File.join(self.lxc.fs_root, '.*provision')})) end + + # bring the source container back online if it was running before the copy operation + (source_state == :running) and self.up + + # bring the target container back online if it was running before the copy operation + (target_state == :running) and target_container.up true end end