Class: VagrantPlugins::ProviderKvm::Action::PrepareNFSSettings
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderKvm::Action::PrepareNFSSettings
- Defined in:
- lib/vagrant-kvm/action/prepare_nfs_settings.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ PrepareNFSSettings
constructor
A new instance of PrepareNFSSettings.
-
#read_host_ip(machine) ⇒ String
Returns the IP address of the first host only network adapter.
-
#read_machine_ip(machine) ⇒ String
Returns the IP address of the guest by looking at the first enabled host only network.
Constructor Details
#initialize(app, env) ⇒ PrepareNFSSettings
Returns a new instance of PrepareNFSSettings.
5 6 7 8 |
# File 'lib/vagrant-kvm/action/prepare_nfs_settings.rb', line 5 def initialize(app,env) @app = app @logger = Log4r::Logger.new("vagrant::action::vm::nfs") end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vagrant-kvm/action/prepare_nfs_settings.rb', line 10 def call(env) @app.call(env) using_nfs = false env[:machine].config.vm.synced_folders.each do |id, opts| if opts[:nfs] using_nfs = true break end end if using_nfs @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP") env[:nfs_host_ip] = read_host_ip(env[:machine]) env[:nfs_machine_ip] = read_machine_ip(env[:machine]) raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] end end |
#read_host_ip(machine) ⇒ String
Returns the IP address of the first host only network adapter
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vagrant-kvm/action/prepare_nfs_settings.rb', line 34 def read_host_ip(machine) ip = read_machine_ip(machine) if ip base_ip = ip.split(".") base_ip[3] = "1" return base_ip.join(".") end nil end |
#read_machine_ip(machine) ⇒ String
Returns the IP address of the guest by looking at the first enabled host only network.
49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-kvm/action/prepare_nfs_settings.rb', line 49 def read_machine_ip(machine) machine.config.vm.networks.each do |type, | if type == :private_network && [:ip].is_a?(String) return [:ip] end end nil end |