Skip to content

Commit

Permalink
@ teracyhq#277 | add configure_plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hoatle committed Jul 20, 2018
1 parent 61cd774 commit fdb6efc
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 10 deletions.
11 changes: 6 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,32 @@ end


# for example, extension can register hooks
=begin

=begin
my_before_configure = Proc.new do |node_config, node|
$logger.debug("my_before_configure")
$logger.debug("my_before_configure: #{node_config}: #{node}")
end
my_after_configure = Proc.new do |node_config, node|
$logger.debug("my_after_configure")
$logger.debug("my_after_configure: #{node_config}: #{node}")
end
register_before_configure_hook(&my_before_configure)
register_after_configure_hook(&my_after_configure)
=end


Vagrant.configure("2") do |config|

configure_plugins(settings['vagrant']['plugins'], config)

settings["nodes"].each do |node_config|
primary = node_config["primary"] ||= false
autostart = node_config["autostart"] === false ? false : true
# NOTE: the next line is async
config.vm.define node_config["name"], primary: primary, autostart: autostart do |node|
$logger.debug("node_config: #{node_config}")
configure(node_config, node)
configure_node(node_config, node)
end
end

Expand Down
8 changes: 4 additions & 4 deletions config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ nodes:
is_primary: true
vm:
hostname: "#{NODE_HOSTNAME_PREFIX}-01.local"
- name: "#{node_name_prefix}-02"
autostart: false
vm:
hostname: "#{NODE_HOSTNAME_PREFIX}-02.local"
# - name: "#{node_name_prefix}-02"
# autostart: false
# vm:
# hostname: "#{NODE_HOSTNAME_PREFIX}-02.local"

94 changes: 93 additions & 1 deletion lib/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def register_after_configure_hook(&block)



def configure(node_config, node)
def configure_node(node_config, node)
# hooks callback
_run_before_configure_hooks(node_config, node)

Expand All @@ -110,3 +110,95 @@ def configure(node_config, node)
# hooks calback
_run_after_configure_hooks(node_config, node)
end


def configure_plugins(plugins_config, config)
$logger.debug("configure_plugins: #{plugins_config}")
plugins_config.each do |plugin|
if plugin['enabled'] == false
$logger.debug("#{plugin['name']} is configured but not enabled")
next
end

plugin_name = plugin['name']
if plugin['required'] == true && !Vagrant.has_plugin?(plugin_name) && ARGV[0] != 'plugin'
$logger.info("vagrant plugin install #{plugin_name} && vagrant #{ARGV.join(" ")}")
# thanks to http://matthewcooper.net/2015/01/15/automatically-installing-vagrant-plugin-dependencies/
exec "vagrant plugin install #{plugin_name} && vagrant #{ARGV.join(" ")}"

# unless Vagrant.has_plugin?(plugin_name)
# puts red("required: '$ vagrant plugin install #{plugin_name}'")
# exit!
# end
end

# this is current fixed config, not dynamic plugins config
# FIXME(hoatle): #186 should fix this
if Vagrant.has_plugin?(plugin_name) and plugin['enabled'] == true and plugin.key?('config_key')
config_key = plugin['config_key']
options = plugin['options']
if 'gatling' == config_key

unless options['latency'].nil?
config.gatling.latency = options['latency']
end

unless options['time_format'].nil? or options['time_format'].empty?
config.gatling.time_format = options['time_format']
end

unless options['rsync_on_startup'].nil?
config.gatling.rsync_on_startup = options['rsync_on_startup']
end

elsif 'hostmanager' == config_key
# conflicts
if Vagrant.has_plugin?('vagrant-hostsupdater')
puts red('recommended: $ vagrant plugin uninstall vagrant-hostsupdater')
end

unless options['enabled'].nil?
config.hostmanager.enabled = options['enabled']
end

unless options['manage_host'].nil?
config.hostmanager.manage_host = options['manage_host']
end

unless options['manage_guest'].nil?
config.hostmanager.manage_guest = options['manage_guest']
end

unless options['ignore_private_ip'].nil?
config.hostmanager.ignore_private_ip = options['ignore_private_ip']
end

unless options['include_offline'].nil?
config.hostmanager.include_offline = options['include_offline']
end

unless options['aliases'].nil?
config.hostmanager.aliases = options['aliases']
end

# workaround for :public_network
# maybe this will not work with :private_network
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
read_ip_address(vm)
end
end
end
# if plugin.key?('config_key')
# config_key = plugin['config_key']
# if Vagrant.has_plugin?(plugin_name) and !config_key.nil? and !config_key.empty?
# puts red(config[config_key.to_sym])
# # TODO(hoatle): remove config_key and required keys?
# #config.instance_variable_set("@#{config_key}", plugin)
# # new_config = Vagrant::Config::V2::Root.new({
# # config_key => plugin
# # })
# # config.merge(config, new_config)
# end
# end
end
end

0 comments on commit fdb6efc

Please sign in to comment.