Class: VagrantPlugins::ProviderZone::QGA::UserScriptBackend

Inherits:
BaseBackend
  • Object
show all
Defined in:
lib/vagrant-zones/qga/user_script_backend.rb

Overview

Escape hatch: pipes a host-side script through ‘bash -c` per NIC, passing per-NIC network parameters as environment variables. Activated only when config.qga_network_script is set; bypasses all detection.

Instance Method Summary collapse

Methods inherited from BaseBackend

#cleanup, #name, #verify

Constructor Details

#initialize(script_path) ⇒ UserScriptBackend

Returns a new instance of UserScriptBackend.



10
11
12
13
# File 'lib/vagrant-zones/qga/user_script_backend.rb', line 10

def initialize(script_path)
  super()
  @script_path = script_path
end

Instance Method Details

#apply(uii, qga, nics, _ctx) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-zones/qga/user_script_backend.rb', line 19

def apply(uii, qga, nics, _ctx)
  contents = File.read(@script_path)
  nics.each do |entry|
    env = build_env(entry)
    uii.info(I18n.t('vagrant_zones.qga_user_script_run') + " #{entry[:vnic_name]}")
    result = qga.exec('/bin/bash', args: ['-s'], env: env, input_data: contents, timeout: 300)
    raise Errors::QGAError, message: "user script failed for #{entry[:vnic_name]} (exit #{result[:exitcode]}): #{result[:stderr]}" if result[:exitcode] != 0
  end
end

#detect?(_qga) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/vagrant-zones/qga/user_script_backend.rb', line 15

def detect?(_qga)
  File.exist?(@script_path)
end