mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
improve nfs
This commit is contained in:
parent
e1d4225644
commit
36b71b78a7
@ -164,6 +164,8 @@ to the remote machine over SSH.
|
|||||||
This is good enough for all built-in Vagrant provisioners (shell,
|
This is good enough for all built-in Vagrant provisioners (shell,
|
||||||
chef, and puppet) to work!
|
chef, and puppet) to work!
|
||||||
|
|
||||||
|
if used options :nfs => true, folder will exported by nfs.
|
||||||
|
|
||||||
## Box Format
|
## Box Format
|
||||||
|
|
||||||
You can view an example box in the [example_box/directory](https://github.com/pradels/vagrant-libvirt/tree/master/example_box). That directory also contains instructions on how to build a box.
|
You can view an example box in the [example_box/directory](https://github.com/pradels/vagrant-libvirt/tree/master/example_box). That directory also contains instructions on how to build a box.
|
||||||
|
@ -25,7 +25,6 @@ module VagrantPlugins
|
|||||||
b2.use CreateNetworks
|
b2.use CreateNetworks
|
||||||
b2.use CreateNetworkInterfaces
|
b2.use CreateNetworkInterfaces
|
||||||
|
|
||||||
b2.use PruneNFSExports
|
|
||||||
b2.use NFS
|
b2.use NFS
|
||||||
b2.use PrepareNFSSettings
|
b2.use PrepareNFSSettings
|
||||||
b2.use ShareFolders
|
b2.use ShareFolders
|
||||||
@ -105,8 +104,8 @@ module VagrantPlugins
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use PruneNFSExports
|
|
||||||
b2.use ConnectLibvirt
|
b2.use ConnectLibvirt
|
||||||
|
b2.use PruneNFSExports
|
||||||
b2.use DestroyDomain
|
b2.use DestroyDomain
|
||||||
b2.use DestroyNetworks
|
b2.use DestroyNetworks
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
require 'nokogiri'
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module Libvirt
|
module Libvirt
|
||||||
module Action
|
module Action
|
||||||
@ -20,7 +21,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
if using_nfs
|
if using_nfs
|
||||||
@logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
|
@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_host_ip] = read_host_ip(env[:machine],env)
|
||||||
env[:nfs_machine_ip] = env[:machine].ssh_info[:host]
|
env[:nfs_machine_ip] = env[:machine].ssh_info[:host]
|
||||||
|
|
||||||
raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip]
|
raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip]
|
||||||
@ -31,8 +32,19 @@ module VagrantPlugins
|
|||||||
#
|
#
|
||||||
# @param [Machine] machine
|
# @param [Machine] machine
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def read_host_ip(machine)
|
def read_host_ip(machine,env)
|
||||||
`ip addr show | grep -A 2 virbr0 | grep -i 'inet ' | tr -s ' ' | cut -d' ' -f3 | cut -d'/' -f 1`.chomp
|
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.map {|netw| netw if netw[:name] == networkname}.first
|
||||||
|
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
|
end
|
||||||
|
|
||||||
# Returns the IP address of the guest by looking at the first
|
# Returns the IP address of the guest by looking at the first
|
||||||
|
@ -3,6 +3,7 @@ module VagrantPlugins
|
|||||||
module Libvirt
|
module Libvirt
|
||||||
module Action
|
module Action
|
||||||
class PruneNFSExports
|
class PruneNFSExports
|
||||||
|
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
@ -10,7 +11,11 @@ module VagrantPlugins
|
|||||||
def call(env)
|
def call(env)
|
||||||
if env[:host]
|
if env[:host]
|
||||||
uuid = env[:machine].id
|
uuid = env[:machine].id
|
||||||
env[:host].nfs_prune(uuid)
|
# get all uuids
|
||||||
|
uuids = env[:libvirt_compute].servers.all.map(&:id)
|
||||||
|
# not exiisted in array will removed from nfs
|
||||||
|
uuids.delete(uuid)
|
||||||
|
env[:host].nfs_prune(uuids)
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
@ -26,10 +26,10 @@ module VagrantPlugins
|
|||||||
{}.tap do |result|
|
{}.tap do |result|
|
||||||
@env[:machine].config.vm.synced_folders.each do |id, data|
|
@env[:machine].config.vm.synced_folders.each do |id, data|
|
||||||
# Ignore NFS shared folders
|
# Ignore NFS shared folders
|
||||||
#next if data[:nfs]
|
next if !data[:nfs]
|
||||||
|
|
||||||
# convert to NFS share
|
# convert to NFS share
|
||||||
data[:nfs] = true
|
#data[:nfs] = true
|
||||||
|
|
||||||
# This to prevent overwriting the actual shared folders data
|
# This to prevent overwriting the actual shared folders data
|
||||||
result[id] = data.dup
|
result[id] = data.dup
|
||||||
|
@ -18,6 +18,7 @@ module VagrantPlugins
|
|||||||
ssh_info = env[:machine].ssh_info
|
ssh_info = env[:machine].ssh_info
|
||||||
|
|
||||||
env[:machine].config.vm.synced_folders.each do |id, data|
|
env[:machine].config.vm.synced_folders.each do |id, data|
|
||||||
|
next if data[:nfs]
|
||||||
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
||||||
guestpath = data[:guestpath]
|
guestpath = data[:guestpath]
|
||||||
|
|
||||||
|
@ -27,10 +27,7 @@ module VagrantPlugins
|
|||||||
attr_accessor :cpus
|
attr_accessor :cpus
|
||||||
attr_accessor :nested
|
attr_accessor :nested
|
||||||
|
|
||||||
attr_reader :shared_folders
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@shared_folders = {}
|
|
||||||
@driver = UNSET_VALUE
|
@driver = UNSET_VALUE
|
||||||
@host = UNSET_VALUE
|
@host = UNSET_VALUE
|
||||||
@connect_via_ssh = UNSET_VALUE
|
@connect_via_ssh = UNSET_VALUE
|
||||||
@ -58,19 +55,6 @@ module VagrantPlugins
|
|||||||
@nested = false if @nested == UNSET_VALUE
|
@nested = false if @nested == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def share_folder(name, guestpath, hostpath, opts=nil)
|
|
||||||
@shared_folders[name] = {
|
|
||||||
:guestpath => guestpath.to_s,
|
|
||||||
:hostpath => hostpath.to_s,
|
|
||||||
:create => false,
|
|
||||||
:owner => nil,
|
|
||||||
:group => nil,
|
|
||||||
:nfs => false,
|
|
||||||
:transient => false,
|
|
||||||
:extra => nil
|
|
||||||
}.merge(opts || {})
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate(machine)
|
def validate(machine)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user