Module: TestLab::Container::Clone
- Included in:
- TestLab::Container
- Defined in:
- lib/testlab/container/clone.rb
Instance Method Summary collapse
-
#ephemeral ⇒ Boolean
Put the container into an ephemeral state.
-
#is_ephemeral? ⇒ Boolean
Is Container Ephemeral?.
-
#is_persistent? ⇒ Boolean
Is Container Persistent?.
-
#lxc_clone ⇒ LXC
LXC::Container object.
-
#persistent ⇒ Boolean
Put the container into a persistent state.
-
#persistent_operation_check(action) ⇒ Boolean
Persistent Operation Check.
-
#to_ephemeral ⇒ Boolean
Convert to Ephemeral Container.
-
#to_persistent ⇒ Boolean
Convert to Static Container.
Instance Method Details
#ephemeral ⇒ Boolean
Put the container into an ephemeral state.
Prepares the container, if needed, for ephemeral cloning.
11 12 13 14 15 16 17 |
# 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_ephemeral? ⇒ Boolean
Is Container Ephemeral?
Returns true if the container is in ephemeral mode, false otherwise.
55 56 57 |
# File 'lib/testlab/container/clone.rb', line 55 def is_ephemeral? self.lxc_clone.exists? end |
#is_persistent? ⇒ Boolean
Is Container Persistent?
Returns true if the container is in persistent mode, false otherwise.
65 66 67 |
# File 'lib/testlab/container/clone.rb', line 65 def is_persistent? !is_ephemeral? end |
#lxc_clone ⇒ LXC
LXC::Container object
Returns a LXC::Container class instance configured for the clone of this container.
76 77 78 |
# File 'lib/testlab/container/clone.rb', line 76 def lxc_clone @lxc_clone ||= self.node.lxc.container("#{self.id}-master") end |
#persistent ⇒ Boolean
Put the container into a persistent state.
Prepares the container, if needed, for persistance.
24 25 26 27 28 29 30 |
# 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(action) ⇒ Boolean
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.
41 42 43 44 45 46 47 |
# 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 |
#to_ephemeral ⇒ Boolean
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.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# 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 |
#to_persistent ⇒ Boolean
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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |