Module: VagrantPlugins::ProviderZone::QGA::ClientExec

Included in:
Client
Defined in:
lib/vagrant-zones/qga/client_exec.rb

Overview

Mixin providing guest-exec orchestration on top of QGA::Client#request. Including classes must define #request(execute, arguments, read_timeout:).

Instance Method Summary collapse

Instance Method Details

#exec(path, args: nil, env: nil, input_data: nil, timeout: 120) ⇒ Object

Run a command, wait for completion, return exitcode + stdout/stderr (decoded).



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant-zones/qga/client_exec.rb', line 12

def exec(path, args: nil, env: nil, input_data: nil, timeout: 120)
  pid = exec_start(path, args: args, env: env, input_data: input_data)
  deadline = Time.now + timeout
  loop do
    status = request('guest-exec-status', { pid: pid })
    return decode_exec(status) if status['exited']
    raise Errors::QGATimeout, message: "guest-exec '#{path}' did not exit within #{timeout}s" if Time.now > deadline

    sleep 1
  end
end

#shell(script, timeout: 120) ⇒ Object

Convenience: run a shell pipeline via /bin/sh -c.



25
26
27
# File 'lib/vagrant-zones/qga/client_exec.rb', line 25

def shell(script, timeout: 120)
  exec('/bin/sh', args: ['-c', script], timeout: timeout)
end