Class: VagrantPlugins::ProviderZone::QGA::Dispatcher

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

Overview

Picks the right backend for the guest OS and orchestrates apply + verify with a fall-through chain for Linux variants.

Constant Summary collapse

LINUX_CHAIN =

Order matters: Linux chain is tried sequentially; first to apply+verify wins.

[
  QGA::NetplanBackend,
  QGA::NetworkManagerBackend,
  QGA::SystemdNetworkdBackend,
  QGA::IfupdownBackend
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(qga, config) ⇒ Dispatcher

Returns a new instance of Dispatcher.



17
18
19
20
# File 'lib/vagrant-zones/qga/dispatcher.rb', line 17

def initialize(qga, config)
  @qga = qga
  @config = config
end

Instance Method Details

#dispatch(uii, nics) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-zones/qga/dispatcher.rb', line 22

def dispatch(uii, nics)
  if @config.qga_network_script && !@config.qga_network_script.to_s.empty?
    run_user_script(uii, nics)
    return
  end

  os = @qga.osinfo
  uii.info("#{I18n.t('vagrant_zones.qga_osinfo_detected')} #{os['id']} (#{os['pretty-name']})")
  case os_family(os)
  when :windows  then run_single(uii, QGA::WindowsBackend.new, nics)
  when :illumos  then run_single(uii, QGA::IllumosBackend.new, nics)
  when :pfsense  then run_single(uii, QGA::PfsenseBackend.new, nics)
  when :opnsense then run_single(uii, QGA::OpnsenseBackend.new, nics)
  when :freebsd  then run_single(uii, QGA::FreebsdBackend.new, nics)
  when :linux    then run_chain(uii, nics)
  else
    raise Errors::QGABackendNotImplemented, backend: os['id'].to_s,
                                            details: "no qga backend registered for guest OS #{os.inspect}"
  end
end