Class: Vagrant::Action::VM::ShareFolders

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/share_folders.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ShareFolders

Returns a new instance of ShareFolders.



5
6
7
8
# File 'lib/vagrant/action/vm/share_folders.rb', line 5

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/vagrant/action/vm/share_folders.rb', line 10

def call(env)
  @env = env

  

  @app.call(env)

  mount_shared_folders
end

#create_metadataObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant/action/vm/share_folders.rb', line 35

def 
  @env.ui.info I18n.t("vagrant.actions.vm.share_folders.creating")

  shared_folders.each do |name, data|
    folder = VirtualBox::SharedFolder.new
    folder.name = name
    folder.host_path = File.expand_path(data[:hostpath], @env.env.root_path)
    @env["vm"].vm.shared_folders << folder
  end

  @env["vm"].vm.save
end

#mount_shared_foldersObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vagrant/action/vm/share_folders.rb', line 48

def mount_shared_folders
  @env.ui.info I18n.t("vagrant.actions.vm.share_folders.mounting")

  @env["vm"].ssh.execute do |ssh|
    shared_folders.each do |name, data|
      if data[:guestpath]
        # Guest path specified, so mount the folder to specified point
        @env.ui.info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
                            :name => name,
                            :guest_path => data[:guestpath]))
        @env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath])
      else
        # If no guest path is specified, then automounting is disabled
        @env.ui.info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
                            :name => name))
      end
    end
  end
end

#shared_foldersObject

This method returns an actual list of VirtualBox shared folders to create and their proper path.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant/action/vm/share_folders.rb', line 22

def shared_folders
  @env.env.config.vm.shared_folders.inject({}) do |acc, data|
    key, value = data

    next acc if value[:disabled]

    # This to prevent overwriting the actual shared folders data
    value = value.dup
    acc[key] = value
    acc
  end
end