Class: VagrantPlugins::ProviderZone::SetupStrategies::QGA

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

Overview

QGA strategy: waits on the QEMU Guest Agent UNIX socket, then dispatches per-guest-OS network configuration through QGA::Dispatcher. Replaces the zlogin PTY login dance and brittle expect-based shell scraping.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from VagrantPlugins::ProviderZone::SetupStrategies::Base

Instance Method Details

#control(uii, action) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vagrant-zones/setup_strategies/qga.rb', line 61

def control(uii, action)
  case action
  when /restart/
    uii.info("#{I18n.t('vagrant_zones.qga_shutdown')} (reboot)")
    client.shutdown('reboot')
  when 'shutdown'
    uii.info("#{I18n.t('vagrant_zones.qga_shutdown')} (powerdown)")
    client.shutdown('powerdown')
  else
    uii.info(I18n.t('vagrant_zones.control_no_cmd'))
  end
end

#get_ip_address(uii) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-zones/setup_strategies/qga.rb', line 32

def get_ip_address(uii)
  ifs = client.network_interfaces
  @machine.config.vm.networks.each do |(_adaptertype, opts)|
    mac = @driver.vnic_mac_for(uii, opts)
    next if mac.nil? || mac.empty?

    iface = ifs.find { |i| ProviderZone::QGA.normalize_mac(i['hardware-address'].to_s) == mac }
    next unless iface

    v4 = (iface['ip-addresses'] || []).find do |a|
      a['ip-address-type'] == 'ipv4' && !a['ip-address'].to_s.start_with?('127.')
    end
    return v4['ip-address'] if v4
  end
  nil
rescue StandardError => e
  @logger.warn("qga get_ip_address: #{e.message}")
  nil
end

#setup_network(uii) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/vagrant-zones/setup_strategies/qga.rb', line 52

def setup_network(uii)
  config = @machine.provider_config
  return if config.cloud_init_enabled

  nics = build_nics(uii)
  dispatcher = ProviderZone::QGA::Dispatcher.new(client, config)
  dispatcher.dispatch(uii, nics)
end

#wait_for_boot(uii, metrics, interrupted) ⇒ Object

TODO(ipv6): qga get_ip_address returns IPv4 only; matches existing v4-only behavior.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-zones/setup_strategies/qga.rb', line 14

def wait_for_boot(uii, metrics, interrupted)
  config = @machine.provider_config
  return if config.cloud_init_enabled || interrupted

  metrics ||= {}
  metrics['instance_qga_socket_time'] = Util::Timer.time do
    uii.info("#{I18n.t('vagrant_zones.qga_wait_socket')} #{client.socket_path}")
    client.wait_for_socket(config.setup_wait)
  end
  return if interrupted

  metrics['instance_qga_ping_time'] = Util::Timer.time do
    uii.info(I18n.t('vagrant_zones.qga_wait_ping'))
    client.wait_for_ready(config.setup_wait)
  end
  uii.info(I18n.t('vagrant_zones.qga_ready'))
end