Class: VagrantPlugins::ProviderLibvirt::Action::ShareFolders

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ShareFolders

Returns a new instance of ShareFolders.


9
10
11
12
# File 'lib/vagrant-libvirt/action/share_folders.rb', line 9

def initialize(app, env)
  @logger = Log4r::Logger.new("vagrant::action::vm::share_folders")
  @app    = app
end

Instance Method Details

#call(env) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/vagrant-libvirt/action/share_folders.rb', line 14

def call(env)
  @env = env

  prepare_folders
  

  @app.call(env)
end

#create_metadataObject


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-libvirt/action/share_folders.rb', line 57

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

  folders = []
  shared_folders.each do |id, data|
    folders << {
      :name => id,
      :hostpath => File.expand_path(data[:hostpath], @env[:root_path]),
      :transient => data[:transient]
    }
  end
end

#prepare_foldersObject

Prepares the shared folders by verifying they exist and creating them if they don't.


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant-libvirt/action/share_folders.rb', line 39

def prepare_folders
  shared_folders.each do |id, options|
    hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])

    if !hostpath.directory? && options[:create]
      # Host path doesn't exist, so let's create it.
      @logger.debug("Host path doesn't exist, creating: #{hostpath}")

      begin
        hostpath.mkpath
      rescue Errno::EACCES
        raise Vagrant::Errors::SharedFolderCreateFailed,
          :path => hostpath.to_s
      end
    end
  end
end

#shared_foldersObject

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


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-libvirt/action/share_folders.rb', line 25

def shared_folders
  {}.tap do |result|
    @env[:machine].config.vm.synced_folders.each do |id, data|
      # Ignore NFS shared folders
      next if !data[:type] == :nfs

      # This to prevent overwriting the actual shared folders data
      result[id] = data.dup
    end
  end
end