Skip to content

Commit

Permalink
Issue #12 - Add sync_method config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Mar 17, 2014
1 parent 1b854c6 commit d93029d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/vagrant-openstack/action/sync_folders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,39 @@
module VagrantPlugins
module Openstack
module Action

class SyncFolders
def initialize(app, env)
@app = app
end

def call(env)
sync_method = env[:machine].provider_config.sync_method
if sync_method == "rsync"
RsyncFolders.new(@app, env).call(env)
elsif sync_method == "none"
NoSyncFolders.new(@app, env).call(env)
else
raise Errors::SyncMethodError, :sync_method_value => sync_method
end
end

end

class NoSyncFolders
def initialize(app, env)
@app = app
end

def call(env)
@app.call(env)
env[:ui].info("Sync folders are disabled")
end
end

# This middleware uses `rsync` to sync the folders over to the
# remote instance.
class SyncFolders
class RsyncFolders
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::sync_folders")
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-openstack/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class Config < Vagrant.plugin("2", :config)
# @return [String]
attr_accessor :floating_ip

# Sync folder method. Can be either "rsync" or "none"
#
# @return [String]
attr_accessor :sync_method

def initialize
@api_key = UNSET_VALUE
@openstack_region = UNSET_VALUE
Expand All @@ -138,6 +143,7 @@ def initialize
@keypair_name = UNSET_VALUE
@ssh_username = UNSET_VALUE
@floating_ip = UNSET_VALUE
@sync_method = UNSET_VALUE
end

def finalize!
Expand All @@ -157,6 +163,7 @@ def finalize!
@disk_config = nil if @disk_config == UNSET_VALUE
@rsync_includes = nil if @rsync_includes.empty?
@floating_ip = nil if @floating_ip == UNSET_VALUE
@sync_method = "rsync" if @sync_method == UNSET_VALUE

# Keypair defaults to nil
@keypair_name = nil if @keypair_name == UNSET_VALUE
Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant-openstack/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class NoMatchingImage < VagrantOpenstackError
error_key(:no_matching_image)
end

class SyncMethodError < VagrantOpenstackError
error_key(:sync_method_error)
end

class RsyncError < VagrantOpenstackError
error_key(:rsync_error)
end
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ en:
no_matching_image: |-
No matching image was found! Please check your image setting to
make sure you have a valid image chosen.
sync_method_error: |-
Value '%{sync_method_value}' is not allowed for 'sync_method' configuration parameter. Valid values are 'rsync' and 'none'
rsync_error: |-
There was an error when attemping to rsync a share folder.
Please inspect the error message below for more info.
Expand Down

0 comments on commit d93029d

Please sign in to comment.