Class: Specinfra::Backend::Lxc

Inherits:
Exec
  • Object
show all
Defined in:
lib/specinfra/backend/lxc.rb

Instance Method Summary collapse

Methods inherited from Exec

#send_directory

Methods inherited from Base

clear, #command, #get_config, #host_inventory, instance, #os_info, #set_config, #set_example, #stderr_handler=, #stdout_handler=

Constructor Details

#initialize(config = {}) ⇒ Lxc

Returns a new instance of Lxc.



4
5
6
7
8
9
10
11
12
# File 'lib/specinfra/backend/lxc.rb', line 4

def initialize(config = {})
  super

  begin
    require 'lxc/extra' unless defined?(::LXC::Extra)
  rescue LoadError
    fail "LXC client library is not available. Try installing `lxc-extra' gem"
  end
end

Instance Method Details

#add_pre_command(cmd) ⇒ Object



32
33
34
# File 'lib/specinfra/backend/lxc.rb', line 32

def add_pre_command(cmd)
  cmd
end

#build_command(cmd) ⇒ Object



28
29
30
# File 'lib/specinfra/backend/lxc.rb', line 28

def build_command(cmd)
  cmd
end

#ctObject



40
41
42
# File 'lib/specinfra/backend/lxc.rb', line 40

def ct
  @ct ||= ::LXC::Container.new(get_config(:lxc))
end

#run_command(cmd, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/specinfra/backend/lxc.rb', line 14

def run_command(cmd, opts={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  out, ret = ct.execute do
    out = `#{cmd}  2>&1`
    [out, $?.dup]
  end
  if @example
    @example.[:command] = cmd
    @example.[:stdout]  = out
  end
  CommandResult.new :stdout => out, :exit_status => ret.exitstatus
end

#send_file(from, to) ⇒ Object



36
37
38
# File 'lib/specinfra/backend/lxc.rb', line 36

def send_file(from, to)
  FileUtils.cp(from, File.join(ct.config_item('lxc.rootfs'), to))
end