From f9aa5a8e7655064c94f9777f34cf81400e1afc83 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 16 Mar 2014 01:47:29 +0100 Subject: [PATCH 1/3] Updated gemfile to let vagrant load plugin in the 1.5 fashion --- Gemfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index ebd9fc4..1c69fb4 100644 --- a/Gemfile +++ b/Gemfile @@ -10,3 +10,7 @@ group :development do gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" end +group :plugins do + gem "vagrant-libvirt", :path => '.' +end + From aad1bd438d83f8a7a29490bf9181e91c5d59f630 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 16 Mar 2014 02:13:52 +0100 Subject: [PATCH 2/3] 9p support for vagrant 1.5 --- lib/vagrant-libvirt/action.rb | 40 ++++++---- lib/vagrant-libvirt/action/sync_folders.rb | 66 ---------------- lib/vagrant-libvirt/cap/mount_p9.rb | 38 ++++++++++ lib/vagrant-libvirt/cap/synced_folder.rb | 75 +++++++++++++++++++ lib/vagrant-libvirt/plugin.rb | 13 +++- .../templates/filesystem.xml.erb | 8 ++ lib/vagrant-libvirt/util/erb_template.rb | 12 ++- 7 files changed, 165 insertions(+), 87 deletions(-) delete mode 100644 lib/vagrant-libvirt/action/sync_folders.rb create mode 100644 lib/vagrant-libvirt/cap/mount_p9.rb create mode 100644 lib/vagrant-libvirt/cap/synced_folder.rb create mode 100644 lib/vagrant-libvirt/templates/filesystem.xml.erb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index f263faa..8ac6682 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -27,19 +27,21 @@ module VagrantPlugins b2.use CreateNetworks b2.use CreateNetworkInterfaces - b2.use StartDomain - b2.use WaitTillUp - - b2.use PrepareNFSValidIds b2.use SyncedFolderCleanup b2.use SyncedFolders + b2.use StartDomain + b2.use WaitTillUp + + # b2.use PrepareNFSValidIds + + b2.use ForwardPorts - b2.use PrepareNFSSettings + # b2.use PrepareNFSSettings b2.use ShareFolders b2.use SetHostname - b2.use SyncFolders + # b2.use SyncFolders else b2.use action_start end @@ -70,6 +72,12 @@ module VagrantPlugins # Ensure networks are created and active b3.use CreateNetworks + + # b3.use PrepareNFSValidIds + b3.use SyncedFolderCleanup + b3.use SyncedFolders + + # Start it.. b3.use StartDomain @@ -77,12 +85,9 @@ module VagrantPlugins # so wait for dhcp lease and store IP into machines data_dir. b3.use WaitTillUp - b3.use PrepareNFSValidIds - b3.use SyncedFolderCleanup - b3.use SyncedFolders b3.use ForwardPorts - b3.use PrepareNFSSettings + # b3.use PrepareNFSSettings b3.use ShareFolders end @@ -147,7 +152,7 @@ module VagrantPlugins b2.use ConnectLibvirt b2.use ClearForwardedPorts - b2.use PruneNFSExports + # b2.use PruneNFSExports b2.use DestroyDomain b2.use DestroyNetworks end @@ -195,7 +200,7 @@ module VagrantPlugins end b3.use Provision - b3.use SyncFolders + # b3.use SyncFolders end end end @@ -312,17 +317,20 @@ module VagrantPlugins autoload :MessageNotCreated, action_root.join('message_not_created') autoload :MessageNotRunning, action_root.join('message_not_running') autoload :MessageNotSuspended, action_root.join('message_not_suspended') - autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings') - autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids') - autoload :PruneNFSExports, action_root.join('prune_nfs_exports') + # autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings') + # autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids') + # autoload :PruneNFSExports, action_root.join('prune_nfs_exports') autoload :ReadSSHInfo, action_root.join('read_ssh_info') autoload :ReadState, action_root.join('read_state') autoload :ResumeDomain, action_root.join('resume_domain') autoload :SetNameOfDomain, action_root.join('set_name_of_domain') + + # I don't think we need it anymore autoload :ShareFolders, action_root.join('share_folders') autoload :StartDomain, action_root.join('start_domain') autoload :SuspendDomain, action_root.join('suspend_domain') - autoload :SyncFolders, action_root.join('sync_folders') + # autoload :SyncFolders, action_root.join('sync_folders') + autoload :TimedProvision, action_root.join('timed_provision') autoload :WaitTillUp, action_root.join('wait_till_up') autoload :SSHRun, 'vagrant/action/builtin/ssh_run' autoload :HandleBoxUrl, 'vagrant/action/builtin/handle_box_url' diff --git a/lib/vagrant-libvirt/action/sync_folders.rb b/lib/vagrant-libvirt/action/sync_folders.rb deleted file mode 100644 index c2815aa..0000000 --- a/lib/vagrant-libvirt/action/sync_folders.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "log4r" -require "vagrant/util/subprocess" - -module VagrantPlugins - module ProviderLibvirt - module Action - # This middleware uses `rsync` to sync the folders over to the - # libvirt domain. - class SyncFolders - def initialize(app, env) - @app = app - @logger = Log4r::Logger.new("vagrant_libvirt::action::sync_folders") - end - - def call(env) - @app.call(env) - - ssh_info = env[:machine].ssh_info - - env[:machine].config.vm.synced_folders.each do |id, data| - next unless data[:type] == :rsync - proxycommand = "-o ProxyCommand='#{ssh_info[:proxy_command]}'" if ssh_info[:proxy_command] - hostpath = File.expand_path(data[:hostpath], env[:root_path]) - guestpath = data[:guestpath] - - # Make sure there is a trailing slash on the host path to - # avoid creating an additional directory with rsync - hostpath = "#{hostpath}/" if hostpath !~ /\/$/ - - env[:ui].info(I18n.t('vagrant_libvirt.rsync_folder', - :hostpath => hostpath, - :guestpath => guestpath)) - - # Create the guest path - env[:machine].communicate.sudo("mkdir -p '#{guestpath}'") - env[:machine].communicate.sudo( - "chown #{ssh_info[:username]} '#{guestpath}'") - - # Rsync over to the guest path using the SSH info - command = [ - 'rsync', '--del', '--verbose', '--archive', '-z', - '--exclude', '.vagrant/', - '-e', "ssh -p #{ssh_info[:port]} #{proxycommand} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}", - hostpath, - "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"] - - r = Vagrant::Util::Subprocess.execute(*command) - if r.exit_code != 0 - raise Errors::RsyncError, - :guestpath => guestpath, - :hostpath => hostpath, - :stderr => r.stderr - end - end - end - private - - def ssh_key_options(ssh_info) - # Ensure that `private_key_path` is an Array (for Vagrant < 1.4) - Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join - end - end - end - end -end - diff --git a/lib/vagrant-libvirt/cap/mount_p9.rb b/lib/vagrant-libvirt/cap/mount_p9.rb new file mode 100644 index 0000000..468efd3 --- /dev/null +++ b/lib/vagrant-libvirt/cap/mount_p9.rb @@ -0,0 +1,38 @@ +require "vagrant/util/retryable" + +module VagrantPlugins + module ProviderLibvirt + module Cap + class MountP9 + extend Vagrant::Util::Retryable + + def self.mount_p9_shared_folder(machine, folders, options) + folders.each do |name, opts| + # Expand the guest path so we can handle things like "~/vagrant" + expanded_guest_path = machine.guest.capability( + :shell_expand_guest_path, opts[:guestpath]) + + # Do the actual creating and mounting + machine.communicate.sudo("mkdir -p #{expanded_guest_path}") + + # Mount + mount_tag = name.dup + + mount_opts="-o trans=virtio" + mount_opts += ",access=#{options[:owner]}" if options[:owner] + mount_opts += ",version=#{options[:version]}" if options[:version] + mount_opts += ",#{opts[:mount_options]}" if opts[:mount_options] + + mount_command = "mount -t 9p #{mount_opts} '#{mount_tag}' #{expanded_guest_path}" + retryable(:on => Vagrant::Errors::LinuxMountFailed, + :tries => 5, + :sleep => 3) do + machine.communicate.sudo(mount_command, + :error_class => Vagrant::Errors::LinuxMountFailed) + end + end + end + end + end + end +end diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb new file mode 100644 index 0000000..17ccb93 --- /dev/null +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -0,0 +1,75 @@ +require "log4r" +require 'ostruct' + + +require "vagrant/util/subprocess" +require "vagrant/errors" +require "vagrant-libvirt/errors" +# require_relative "helper" + +module VagrantPlugins + module SyncedFolder9p + class SyncedFolder < Vagrant.plugin("2", :synced_folder) + include Vagrant::Util + include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate + + def initialize(*args) + super + + @logger = Log4r::Logger.new("vagrant_libvirt::synced_folders::9p") + end + + def usable?(machine, raise_error=false) + # TODO check for host support (eg in linux is 9p compiled ?) + # and support in Qemu for instance ? + machine.provider_name == :libvirt + end + + def prepare(machine, folders, opts) + + raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil? + + @conn = ProviderLibvirt.libvirt_connection.client + + begin + # loop through folders + folders.each do |id, folder_opts| + folder_opts.merge!({ :accessmode => "passthrough", + :readonly => true }) + # machine.ui.info "================\nMachine id: #{machine.id}Should be mounting folders\n #{id}, opts: #{folder_opts}" + + xml = to_xml('filesystem', folder_opts ) + # puts "<<<<< XML:\n #{xml}\n >>>>>" + @conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0) + + end + rescue => e + # machine.ui.error("could not attach device because: #{e}") + raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,:error_message => e.message + end + end + + + # TODO once up, mount folders + def enable(machine, folders, _opts) + # Go through each folder and mount + machine.ui.info("mounting p9 share in guest") + # Only mount folders that have a guest path specified. + mount_folders = {} + folders.each do |id, opts| + mount_folders[id] = opts.dup if opts[:guestpath] + end + common_opts = { + :version => '9p2000.L', + } + # Mount the actual folder + machine.guest.capability( + :mount_p9_shared_folder, mount_folders, common_opts) + end + + def cleanup(machine, opts) + # driver(machine).clear_shared_folders if machine.id && machine.id != "" + end + end + end +end diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 0f275ee..0d98213 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -6,7 +6,7 @@ end # This is a sanity check to make sure no one is attempting to install # this into an early Vagrant version. -if Vagrant::VERSION < '1.4.0' +if Vagrant::VERSION < '1.5.0' raise 'The Vagrant Libvirt plugin is only compatible with Vagrant 1.4+' end @@ -31,6 +31,17 @@ module VagrantPlugins require_relative 'provider' Provider end + + guest_capability("linux", "mount_p9_shared_folder") do + require_relative "cap/mount_p9" + Cap::MountP9 + end + + # We set p9 as high priority (default 10) + synced_folder("9p", 20) do + require_relative "cap/synced_folder" + VagrantPlugins::SyncedFolder9p::SyncedFolder + end # This initializes the internationalization strings. def self.setup_i18n diff --git a/lib/vagrant-libvirt/templates/filesystem.xml.erb b/lib/vagrant-libvirt/templates/filesystem.xml.erb new file mode 100644 index 0000000..469cae6 --- /dev/null +++ b/lib/vagrant-libvirt/templates/filesystem.xml.erb @@ -0,0 +1,8 @@ + + + + + <% unless readonly.nil? %> + + <% end %> + \ No newline at end of file diff --git a/lib/vagrant-libvirt/util/erb_template.rb b/lib/vagrant-libvirt/util/erb_template.rb index 2191fc6..a3d4203 100644 --- a/lib/vagrant-libvirt/util/erb_template.rb +++ b/lib/vagrant-libvirt/util/erb_template.rb @@ -1,17 +1,21 @@ -require 'erb' +require 'erubis' module VagrantPlugins module ProviderLibvirt module Util module ErbTemplate - # Taken from fog source. - def to_xml template_name = nil + + # TODO might be a chance to use vagrant template system according to https://github.com/mitchellh/vagrant/issues/3231 + def to_xml template_name = nil, data = binding erb = template_name || self.class.to_s.split("::").last.downcase path = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb") template = File.read(path) - ERB.new(template, nil, '-').result(binding) + + # TODO according to erubis documentation, we should rather use evaluate and forget about + # binding since the template may then change variables values + Erubis::Eruby.new(template, :trim => true).result(data) end end From 7ae9e03c5dee45ab194da4bca4802613878d5850 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 16 Mar 2014 02:13:52 +0100 Subject: [PATCH 3/3] 9p support for vagrant 1.5 --- lib/vagrant-libvirt/action.rb | 29 ++++--- lib/vagrant-libvirt/action/sync_folders.rb | 66 ---------------- lib/vagrant-libvirt/cap/mount_p9.rb | 38 ++++++++++ lib/vagrant-libvirt/cap/synced_folder.rb | 75 +++++++++++++++++++ lib/vagrant-libvirt/plugin.rb | 13 +++- .../templates/filesystem.xml.erb | 8 ++ lib/vagrant-libvirt/util/erb_template.rb | 12 ++- 7 files changed, 160 insertions(+), 81 deletions(-) delete mode 100644 lib/vagrant-libvirt/action/sync_folders.rb create mode 100644 lib/vagrant-libvirt/cap/mount_p9.rb create mode 100644 lib/vagrant-libvirt/cap/synced_folder.rb create mode 100644 lib/vagrant-libvirt/templates/filesystem.xml.erb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index f263faa..b254fa4 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -27,19 +27,22 @@ module VagrantPlugins b2.use CreateNetworks b2.use CreateNetworkInterfaces - b2.use StartDomain - b2.use WaitTillUp - b2.use PrepareNFSValidIds b2.use SyncedFolderCleanup b2.use SyncedFolders + b2.use StartDomain + b2.use WaitTillUp + + + + b2.use ForwardPorts b2.use PrepareNFSSettings b2.use ShareFolders b2.use SetHostname - b2.use SyncFolders + # b2.use SyncFolders else b2.use action_start end @@ -70,6 +73,12 @@ module VagrantPlugins # Ensure networks are created and active b3.use CreateNetworks + + b3.use PrepareNFSValidIds + b3.use SyncedFolderCleanup + b3.use SyncedFolders + + # Start it.. b3.use StartDomain @@ -77,9 +86,6 @@ module VagrantPlugins # so wait for dhcp lease and store IP into machines data_dir. b3.use WaitTillUp - b3.use PrepareNFSValidIds - b3.use SyncedFolderCleanup - b3.use SyncedFolders b3.use ForwardPorts b3.use PrepareNFSSettings @@ -195,7 +201,7 @@ module VagrantPlugins end b3.use Provision - b3.use SyncFolders + # b3.use SyncFolders end end end @@ -313,17 +319,20 @@ module VagrantPlugins autoload :MessageNotRunning, action_root.join('message_not_running') autoload :MessageNotSuspended, action_root.join('message_not_suspended') autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings') - autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids') autoload :PruneNFSExports, action_root.join('prune_nfs_exports') autoload :ReadSSHInfo, action_root.join('read_ssh_info') autoload :ReadState, action_root.join('read_state') autoload :ResumeDomain, action_root.join('resume_domain') autoload :SetNameOfDomain, action_root.join('set_name_of_domain') + + # I don't think we need it anymore autoload :ShareFolders, action_root.join('share_folders') autoload :StartDomain, action_root.join('start_domain') autoload :SuspendDomain, action_root.join('suspend_domain') - autoload :SyncFolders, action_root.join('sync_folders') + autoload :TimedProvision, action_root.join('timed_provision') autoload :WaitTillUp, action_root.join('wait_till_up') + autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids') + autoload :SSHRun, 'vagrant/action/builtin/ssh_run' autoload :HandleBoxUrl, 'vagrant/action/builtin/handle_box_url' autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders' diff --git a/lib/vagrant-libvirt/action/sync_folders.rb b/lib/vagrant-libvirt/action/sync_folders.rb deleted file mode 100644 index c2815aa..0000000 --- a/lib/vagrant-libvirt/action/sync_folders.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "log4r" -require "vagrant/util/subprocess" - -module VagrantPlugins - module ProviderLibvirt - module Action - # This middleware uses `rsync` to sync the folders over to the - # libvirt domain. - class SyncFolders - def initialize(app, env) - @app = app - @logger = Log4r::Logger.new("vagrant_libvirt::action::sync_folders") - end - - def call(env) - @app.call(env) - - ssh_info = env[:machine].ssh_info - - env[:machine].config.vm.synced_folders.each do |id, data| - next unless data[:type] == :rsync - proxycommand = "-o ProxyCommand='#{ssh_info[:proxy_command]}'" if ssh_info[:proxy_command] - hostpath = File.expand_path(data[:hostpath], env[:root_path]) - guestpath = data[:guestpath] - - # Make sure there is a trailing slash on the host path to - # avoid creating an additional directory with rsync - hostpath = "#{hostpath}/" if hostpath !~ /\/$/ - - env[:ui].info(I18n.t('vagrant_libvirt.rsync_folder', - :hostpath => hostpath, - :guestpath => guestpath)) - - # Create the guest path - env[:machine].communicate.sudo("mkdir -p '#{guestpath}'") - env[:machine].communicate.sudo( - "chown #{ssh_info[:username]} '#{guestpath}'") - - # Rsync over to the guest path using the SSH info - command = [ - 'rsync', '--del', '--verbose', '--archive', '-z', - '--exclude', '.vagrant/', - '-e', "ssh -p #{ssh_info[:port]} #{proxycommand} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}", - hostpath, - "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"] - - r = Vagrant::Util::Subprocess.execute(*command) - if r.exit_code != 0 - raise Errors::RsyncError, - :guestpath => guestpath, - :hostpath => hostpath, - :stderr => r.stderr - end - end - end - private - - def ssh_key_options(ssh_info) - # Ensure that `private_key_path` is an Array (for Vagrant < 1.4) - Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join - end - end - end - end -end - diff --git a/lib/vagrant-libvirt/cap/mount_p9.rb b/lib/vagrant-libvirt/cap/mount_p9.rb new file mode 100644 index 0000000..468efd3 --- /dev/null +++ b/lib/vagrant-libvirt/cap/mount_p9.rb @@ -0,0 +1,38 @@ +require "vagrant/util/retryable" + +module VagrantPlugins + module ProviderLibvirt + module Cap + class MountP9 + extend Vagrant::Util::Retryable + + def self.mount_p9_shared_folder(machine, folders, options) + folders.each do |name, opts| + # Expand the guest path so we can handle things like "~/vagrant" + expanded_guest_path = machine.guest.capability( + :shell_expand_guest_path, opts[:guestpath]) + + # Do the actual creating and mounting + machine.communicate.sudo("mkdir -p #{expanded_guest_path}") + + # Mount + mount_tag = name.dup + + mount_opts="-o trans=virtio" + mount_opts += ",access=#{options[:owner]}" if options[:owner] + mount_opts += ",version=#{options[:version]}" if options[:version] + mount_opts += ",#{opts[:mount_options]}" if opts[:mount_options] + + mount_command = "mount -t 9p #{mount_opts} '#{mount_tag}' #{expanded_guest_path}" + retryable(:on => Vagrant::Errors::LinuxMountFailed, + :tries => 5, + :sleep => 3) do + machine.communicate.sudo(mount_command, + :error_class => Vagrant::Errors::LinuxMountFailed) + end + end + end + end + end + end +end diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb new file mode 100644 index 0000000..17ccb93 --- /dev/null +++ b/lib/vagrant-libvirt/cap/synced_folder.rb @@ -0,0 +1,75 @@ +require "log4r" +require 'ostruct' + + +require "vagrant/util/subprocess" +require "vagrant/errors" +require "vagrant-libvirt/errors" +# require_relative "helper" + +module VagrantPlugins + module SyncedFolder9p + class SyncedFolder < Vagrant.plugin("2", :synced_folder) + include Vagrant::Util + include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate + + def initialize(*args) + super + + @logger = Log4r::Logger.new("vagrant_libvirt::synced_folders::9p") + end + + def usable?(machine, raise_error=false) + # TODO check for host support (eg in linux is 9p compiled ?) + # and support in Qemu for instance ? + machine.provider_name == :libvirt + end + + def prepare(machine, folders, opts) + + raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil? + + @conn = ProviderLibvirt.libvirt_connection.client + + begin + # loop through folders + folders.each do |id, folder_opts| + folder_opts.merge!({ :accessmode => "passthrough", + :readonly => true }) + # machine.ui.info "================\nMachine id: #{machine.id}Should be mounting folders\n #{id}, opts: #{folder_opts}" + + xml = to_xml('filesystem', folder_opts ) + # puts "<<<<< XML:\n #{xml}\n >>>>>" + @conn.lookup_domain_by_uuid(machine.id).attach_device(xml, 0) + + end + rescue => e + # machine.ui.error("could not attach device because: #{e}") + raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,:error_message => e.message + end + end + + + # TODO once up, mount folders + def enable(machine, folders, _opts) + # Go through each folder and mount + machine.ui.info("mounting p9 share in guest") + # Only mount folders that have a guest path specified. + mount_folders = {} + folders.each do |id, opts| + mount_folders[id] = opts.dup if opts[:guestpath] + end + common_opts = { + :version => '9p2000.L', + } + # Mount the actual folder + machine.guest.capability( + :mount_p9_shared_folder, mount_folders, common_opts) + end + + def cleanup(machine, opts) + # driver(machine).clear_shared_folders if machine.id && machine.id != "" + end + end + end +end diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 0f275ee..0d98213 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -6,7 +6,7 @@ end # This is a sanity check to make sure no one is attempting to install # this into an early Vagrant version. -if Vagrant::VERSION < '1.4.0' +if Vagrant::VERSION < '1.5.0' raise 'The Vagrant Libvirt plugin is only compatible with Vagrant 1.4+' end @@ -31,6 +31,17 @@ module VagrantPlugins require_relative 'provider' Provider end + + guest_capability("linux", "mount_p9_shared_folder") do + require_relative "cap/mount_p9" + Cap::MountP9 + end + + # We set p9 as high priority (default 10) + synced_folder("9p", 20) do + require_relative "cap/synced_folder" + VagrantPlugins::SyncedFolder9p::SyncedFolder + end # This initializes the internationalization strings. def self.setup_i18n diff --git a/lib/vagrant-libvirt/templates/filesystem.xml.erb b/lib/vagrant-libvirt/templates/filesystem.xml.erb new file mode 100644 index 0000000..469cae6 --- /dev/null +++ b/lib/vagrant-libvirt/templates/filesystem.xml.erb @@ -0,0 +1,8 @@ + + + + + <% unless readonly.nil? %> + + <% end %> + \ No newline at end of file diff --git a/lib/vagrant-libvirt/util/erb_template.rb b/lib/vagrant-libvirt/util/erb_template.rb index 2191fc6..a3d4203 100644 --- a/lib/vagrant-libvirt/util/erb_template.rb +++ b/lib/vagrant-libvirt/util/erb_template.rb @@ -1,17 +1,21 @@ -require 'erb' +require 'erubis' module VagrantPlugins module ProviderLibvirt module Util module ErbTemplate - # Taken from fog source. - def to_xml template_name = nil + + # TODO might be a chance to use vagrant template system according to https://github.com/mitchellh/vagrant/issues/3231 + def to_xml template_name = nil, data = binding erb = template_name || self.class.to_s.split("::").last.downcase path = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb") template = File.read(path) - ERB.new(template, nil, '-').result(binding) + + # TODO according to erubis documentation, we should rather use evaluate and forget about + # binding since the template may then change variables values + Erubis::Eruby.new(template, :trim => true).result(data) end end