Skip to content

Commit

Permalink
Support computed args for shell provider
Browse files Browse the repository at this point in the history
Fix #205
  • Loading branch information
ggiamarchi committed Feb 6, 2015
1 parent 48e5558 commit 455460e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/lib/vagrant-openstack-provider/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.action_provision
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t('vagrant_openstack.not_created')
else
b2.use Provision
b2.use ProvisionWrapper
b2.use SyncFolders
end
end
Expand Down Expand Up @@ -212,6 +212,7 @@ def self.action_reload
autoload :SyncFolders, action_root.join('sync_folders')
autoload :Suspend, action_root.join('suspend')
autoload :Resume, action_root.join('resume')
autoload :ProvisionWrapper, action_root.join('provision')
autoload :WaitForServerToStop, action_root.join('wait_stop')
autoload :WaitForServerToBeActive, action_root.join('wait_active')
autoload :WaitForServerToBeAccessible, action_root.join('wait_accessible')
Expand Down
52 changes: 52 additions & 0 deletions source/lib/vagrant-openstack-provider/action/provision.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'log4r'

require 'vagrant/action/builder'

require 'vagrant-openstack-provider/action/abstract_action'
require 'vagrant-openstack-provider/action/read_ssh_info'

module VagrantPlugins
module Openstack
module Action
include Vagrant::Action::Builtin

class ProvisionWrapper < AbstractAction
def initialize(app, env)
@app = app
@env = env
@logger = Log4r::Logger.new('vagrant_openstack::action::provision_wrapper')
end

def execute(env)
@logger.info 'Run provisioning'
InternalProvisionWrapper.new(@app, @env).call(@env)
@app.call(env)
end
end

class InternalProvisionWrapper < Vagrant::Action::Builtin::Provision
def initialize(app, env)
@logger = Log4r::Logger.new('vagrant_openstack::action::internal_provision_wrapper')
super app, env
end

def run_provisioner(env)
if env[:provisioner].class == VagrantPlugins::Shell::Provisioner
config = env[:provisioner].config
args = [config.args].flatten
config.args = []
args.each do |arg|
if arg == '@@ssh_ip@@'
ssh_info = VagrantPlugins::Openstack::Action.get_ssh_info(env)
config.args << ssh_info[:host]
else
config.args << arg
end
end
end
env[:provisioner].provision
end
end
end
end
end
4 changes: 4 additions & 0 deletions source/lib/vagrant-openstack-provider/action/read_ssh_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def initialize
@ssh_info = {}
end
end

def self.get_ssh_info(env)
SSHInfoHolder.instance.ssh_info[env[:machine].id.to_sym]
end
end
end
end

0 comments on commit 455460e

Please sign in to comment.