module TestLab::Container::Clone
Public Instance Methods
Put the container into an ephemeral state.
Prepares the container, if needed, for ephemeral cloning.
@return [Boolean] True if successful.
# File lib/testlab/container/clone.rb, line 11 def ephemeral @ui.logger.debug { "Container Ephemeral: #{self.id}" } is_persistent? and self.to_ephemeral true end
Is Container
Ephemeral?
Returns true if the container is in ephemeral mode, false otherwise.
@return [Boolean] Returns true if the container is ephemeral, false
otherwise.
# File lib/testlab/container/clone.rb, line 55 def is_ephemeral? self.lxc_clone.exists? end
Is Container
Persistent?
Returns true if the container is in persistent mode, false otherwise.
@return [Boolean] Returns true if the container is persistent, false
otherwise.
# File lib/testlab/container/clone.rb, line 65 def is_persistent? !is_ephemeral? end
LXC::Container object
Returns a LXC::Container class instance configured for the clone of this container.
@return [LXC] An instance of LXC::Container configured for the clone of
this container.
# File lib/testlab/container/clone.rb, line 76 def lxc_clone @lxc_clone ||= self.node.lxc.container("#{self.id}-master") end
Put the container into a persistent state.
Prepares the container, if needed, for persistance.
@return [Boolean] True if successful.
# File lib/testlab/container/clone.rb, line 24 def persistent @ui.logger.debug { "Container Persistent: #{self.id}" } is_ephemeral? and self.to_persistent true end
Persistent Operation Check
Checks if the container is operating in ephemeral mode, and if it is raises an exception indicating the operation can not proceed.
If the container is operating in persistent mode, no output is generated and true is returned indicating the operation can continue.
@return [Boolean] True if the operation can continue; false otherwise.
# File lib/testlab/container/clone.rb, line 41 def persistent_operation_check(action) if is_ephemeral? raise ContainerError, "You can not #{action} #{self.id} because it is currently in ephemeral mode!" end true end
Convert to Ephemeral Container
If the current container is operating as a static container, this will convert it to a ephemeral container, otherwise no changes will occur.
@return [Boolean] Returns true if successful.
# File lib/testlab/container/clone.rb, line 115 def to_ephemeral if self.is_persistent? self_state = self.state please_wait(:ui => @ui, :message => format_object_action(self, 'Ephemeral', :yellow)) do configure self.lxc_clone.stop self.lxc_clone.destroy(%(-f)) self.lxc.stop self.lxc.clone(%W(-o #{self.lxc.name} -n #{self.lxc_clone.name})) self.lxc.destroy(%(-f)) end # bring our container back online if it was running before the operation (self_state == :running) and self.up end true end
Convert to Static Container
If the current container is operating as an ephemeral container, this will convert it back to a static container, otherwise no changes will occur.
@return [Boolean] Returns true if successful.
# File lib/testlab/container/clone.rb, line 87 def to_persistent if self.is_ephemeral? self_state = self.state please_wait(:ui => @ui, :message => format_object_action(self, 'Persistent', :yellow)) do configure self.lxc.stop self.lxc.destroy(%(-f)) self.lxc_clone.stop self.lxc_clone.clone(%W(-o #{self.lxc_clone.name} -n #{self.lxc.name})) self.lxc_clone.destroy(%(-f)) end # bring our container back online if it was running before the operation (self_state == :running) and self.up end true end