Class: Lxc::Clone

Inherits:
Object
  • Object
show all
Includes:
Helpers, Helpers::Copies, Helpers::Options
Defined in:
lib/elecksee/clone.rb

Overview

Clone existing containers

Constant Summary

Constants included from Helpers::Copies

Helpers::Copies::HOSTNAME_FILES, Helpers::Copies::NAME_FILES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Copies

#apply_custom_networking, #el_platform?, #update_naming, #update_net_hwaddr, #update_rootfs, #write_file

Methods included from Helpers::Options

included

Methods included from Helpers

#child_process_command, #detect_home, #log, #mixlib_shellout_command, #run_command, #sudo

Constructor Details

#initialize(args = {}) ⇒ Clone

Create new instance

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :original (String)

    existing container name

  • :new (String)

    new container name



31
32
33
34
35
36
37
38
# File 'lib/elecksee/clone.rb', line 31

def initialize(args={})
  configure!(args)
  @lxcs = {}
  @lxcs[:original] = Lxc.new(original)
  @lxcs[:new] = Lxc.new(new_name)
  @created = []
  validate!
end

Instance Attribute Details

#lxcsHash (readonly)

Returns original and new container instances.

Returns:

  • (Hash)

    original and new container instances



24
25
26
# File 'lib/elecksee/clone.rb', line 24

def lxcs
  @lxcs
end

Instance Method Details

#clone!Lxc

Create the clone

Returns:

  • (Lxc)

    new clone



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elecksee/clone.rb', line 43

def clone!
  begin
    copy_original
    update_naming(:no_config)
    apply_custom_addressing if ipaddress
    lxc
  rescue Exception
    @created.map(&:destroy)
    raise
  end
end