Class: VagrantPlugins::ProviderZone::QGA::BaseBackend

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

Overview

Shared scaffolding for QGA network backends. Subclasses configure guest networking using a specific backend (netplan, NetworkManager, etc.) and implement #detect? and #apply via duck typing. #verify and #cleanup have working defaults that subclasses may override.

Instance Method Summary collapse

Instance Method Details

#cleanupObject

Default no-op cleanup; backends that write files override this.



36
37
38
# File 'lib/vagrant-zones/qga/base_backend.rb', line 36

def cleanup(*)
  nil
end

#nameObject

Human-readable name used in logs and error chains.



12
13
14
# File 'lib/vagrant-zones/qga/base_backend.rb', line 12

def name
  self.class.name.split('::').last
end

#verify(qga, nics) ⇒ Object

Re-fetch guest interfaces and confirm expected IPs are present on expected MACs. Returns true when every NIC’s expected IP appears on the matched MAC.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-zones/qga/base_backend.rb', line 18

def verify(qga, nics)
  ifs = qga.network_interfaces
  nics.all? do |entry|
    mac = entry[:mac]
    expected_ip = entry[:ip]
    next true if expected_ip.nil? || expected_ip.empty?

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

    addrs = iface['ip-addresses'] || []
    addrs.any? { |a| a['ip-address-type'] == 'ipv4' && a['ip-address'] == expected_ip }
  end
rescue StandardError
  false
end