Class: VagrantPlugins::ProviderZone::QGA::NetplanBackend
- Inherits:
-
BaseBackend
- Object
- BaseBackend
- VagrantPlugins::ProviderZone::QGA::NetplanBackend
- Defined in:
- lib/vagrant-zones/qga/netplan_backend.rb
Overview
Writes /etc/netplan/<vnic>.yaml per NIC and runs ‘netplan apply`.
Constant Summary collapse
- NETPLAN_BIN =
'/usr/sbin/netplan'
Instance Method Summary collapse
Methods inherited from BaseBackend
Instance Method Details
#apply(uii, qga, nics, _ctx) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant-zones/qga/netplan_backend.rb', line 18 def apply(uii, qga, nics, _ctx) nics.each do |entry| yaml = render_yaml(entry) path = "/etc/netplan/#{entry[:vnic_name]}.yaml" write_result = qga.exec('/bin/sh', args: ['-c', "cat > #{path} && chmod 600 #{path}"], input_data: yaml, timeout: 30) raise Errors::QGAError, message: "netplan write failed for #{path}: #{write_result[:stderr]}" if write_result[:exitcode] != 0 uii.info("#{I18n.t('vagrant_zones.qga_backend_apply')} netplan #{path}") end result = qga.exec(NETPLAN_BIN, args: ['apply'], timeout: 60) raise Errors::QGAError, message: "netplan apply failed: #{result[:stderr]}" if result[:exitcode] != 0 end |
#cleanup(uii, qga, nics) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/vagrant-zones/qga/netplan_backend.rb', line 34 def cleanup(uii, qga, nics) nics.each do |entry| qga.exec('/bin/rm', args: ['-f', "/etc/netplan/#{entry[:vnic_name]}.yaml"], timeout: 10) end uii.info("#{I18n.t('vagrant_zones.qga_backend_cleanup')} netplan") end |
#detect?(qga) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/vagrant-zones/qga/netplan_backend.rb', line 12 def detect?(qga) qga.exec('/usr/bin/test', args: ['-x', NETPLAN_BIN], timeout: 10)[:exitcode].zero? rescue StandardError false end |