Class: VagrantPlugins::ProviderLibvirt::Action::PrepareNFSSettings
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::PrepareNFSSettings
- Defined in:
- lib/vagrant-libvirt/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, env) ⇒ 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.
6 7 8 9 |
# File 'lib/vagrant-libvirt/action/prepare_nfs_settings.rb', line 6 def initialize(app,env) @app = app @logger = Log4r::Logger.new("vagrant::action::vm::nfs") end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vagrant-libvirt/action/prepare_nfs_settings.rb', line 11 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) env[:nfs_machine_ip] = env[:machine].ssh_info[:host] raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] end end |
#read_host_ip(machine, env) ⇒ String
Returns the IP address of the first host only network adapter
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-libvirt/action/prepare_nfs_settings.rb', line 35 def read_host_ip(machine,env) nets = env[:libvirt_compute].list_networks if nets.size == 1 net = nets.first else domain = env[:libvirt_compute].servers.get(machine.id.to_s) xml=Nokogiri::XML(domain.to_xml) networkname = xml.xpath('/domain/devices/interface/source').first.attributes['network'].value.to_s puts "network name = #{networkname}" net = env[:libvirt_compute].list_networks.find {|netw| netw[:name] == networkname} end # FIXME better implement by libvirt xml parsing `ip addr show | grep -A 2 #{net[:bridge_name]} | grep -i 'inet ' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1`.chomp end |
#read_machine_ip(machine) ⇒ String
Returns the IP address of the guest by looking at the first enabled host only network.
54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-libvirt/action/prepare_nfs_settings.rb', line 54 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 |