Class: VagrantPlugins::QEMU::Action::CloudInitNetwork

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-qemu/action/cloud_init_network.rb

Overview

Carries the cloud-init network-config for the advanced-network private NIC into a NoCloud cidata seed. The ISO build is delegated to the :create_iso host capability and the attach goes through the provider disk capability (cap/disk.rb).

NoCloud reads user-data, meta-data and network-config from a single filesystem labelled “cidata”; two cidata volumes are ambiguous. So when core CloudInitSetup (which runs earlier in the chain) has already built a user-data seed, we rebuild that same ISO in place with network-config added instead of attaching a second seed.

Constant Summary collapse

CORE_SEED_DISK_NAME =

Disk name core Vagrant::Action::Builtin::CloudInitSetup gives its user-data seed.

"vagrant-cloud_init-disk".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ CloudInitNetwork

Returns a new instance of CloudInitNetwork.



27
28
29
30
# File 'lib/vagrant-qemu/action/cloud_init_network.rb', line 27

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant_qemu::action::cloud_init_network")
end

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vagrant-qemu/action/cloud_init_network.rb', line 32

def call(env)
  machine = env[:machine]

  pn = machine.config.vm.networks
    .select { |t, _| t == :private_network }
    .map { |_, opts| opts }
    .first

  if machine.provider_config.advanced_network && pn && pn[:ip]
    existing = machine.config.vm.disks.find do |d|
      d.type == :dvd && d.name == CORE_SEED_DISK_NAME
    end

    if existing
      merge_into_seed(machine, env, pn, existing.file)
    else
      attach_network_seed(machine, env, pn)
    end
  end

  @app.call(env)
end