Class: Specinfra::Backend::Lxc

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

Instance Method Summary collapse

Methods inherited from Base

#set_example

Constructor Details

#initializeLxc

Returns a new instance of Lxc.



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

def initialize
  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



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

def add_pre_command(cmd)
  cmd
end

#build_command(cmd) ⇒ Object



24
25
26
# File 'lib/specinfra/backend/lxc.rb', line 24

def build_command(cmd)
  cmd
end

#ctObject



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

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

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



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/specinfra/backend/lxc.rb', line 11

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



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

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