Class: VagrantPlugins::QEMU::Action::MountVirtioFS

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ MountVirtioFS

Returns a new instance of MountVirtioFS.



7
8
9
10
# File 'lib/vagrant-qemu/action/mount_virtiofs.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-qemu/action/mount_virtiofs.rb', line 12

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

  # Find virtiofs synced folders from config
  virtiofs_folders = machine.config.vm.synced_folders.select do |_id, data|
    data[:type].to_s == "virtiofs" && !data[:disabled]
  end

  if virtiofs_folders.any?
    sorted = virtiofs_folders.sort_by { |_id, data| data[:guestpath] }
    sorted.each_with_index do |(_id, data), i|
      guestpath = data[:guestpath]
      tag = "virtiofs#{i}"

      machine.communicate.sudo("mkdir -p #{guestpath}")
      machine.communicate.sudo("mount -t virtiofs #{tag} #{guestpath}")
      machine.ui.info("Mounted virtiofs #{tag} at #{guestpath}")
    end
  end

  @app.call(env)
end