Class: Specinfra::Backend::Lxc
- Defined in:
- lib/specinfra/backend/lxc.rb
Instance Method Summary collapse
- #add_pre_command(cmd) ⇒ Object
- #build_command(cmd) ⇒ Object
- #ct ⇒ Object
-
#initialize ⇒ Lxc
constructor
A new instance of Lxc.
- #run_command(cmd, opts = {}) ⇒ Object
- #send_file(from, to) ⇒ Object
Methods inherited from Exec
Methods inherited from Base
Constructor Details
#initialize ⇒ Lxc
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
29 30 31 |
# File 'lib/specinfra/backend/lxc.rb', line 29 def add_pre_command(cmd) cmd end |
#build_command(cmd) ⇒ Object
25 26 27 |
# File 'lib/specinfra/backend/lxc.rb', line 25 def build_command(cmd) cmd end |
#ct ⇒ Object
37 38 39 |
# File 'lib/specinfra/backend/lxc.rb', line 37 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
33 34 35 |
# File 'lib/specinfra/backend/lxc.rb', line 33 def send_file(from, to) FileUtils.cp(from, File.join(ct.config_item('lxc.rootfs'), to)) end |