diff --git a/Vagrantfile b/Vagrantfile index ee5fb04c..a1cb6bcb 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,9 +10,6 @@ require_relative 'lib/configurator' VERSION='0.6.0-a1-SNAPSHOT' -# load File.dirname(__FILE__) + '/lib/utility.rb' -# load File.dirname(__FILE__) + '/lib/settings_processor.rb' - $logger = get_logger() @@ -37,26 +34,43 @@ require_version(settings['teracy-dev']['require_version']) # preload-ext list here -preload_ext_paths = settings["vagrant"]["preload_extension_paths"] ||= [] +extension_paths = settings["vagrant"]["extension_paths"] ||= [] + +$logger.debug("load extensions") -preload_ext_paths.each do |path| +extension_paths.each do |path| load_file_path(path) end +# for example, extension can register hooks +=begin + +my_before_configure = Proc.new do |node_config, node| + $logger.debug("my_before_configure") +end + +my_after_configure = Proc.new do |node_config, node| + $logger.debug("my_after_configure") +end + +register_before_configure_hook(&my_before_configure) +register_after_configure_hook(&my_after_configure) + +=end + + Vagrant.configure("2") do |config| + settings["nodes"].each do |node_config| - $logger.debug("node_config: #{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) end end - # postload-ext list here - postload_ext_paths = settings["vagrant"]["postload_extension_paths"] ||= [] - postload_ext_paths.each do |path| - load_file_path(path) - end + end diff --git a/config_default.yaml b/config_default.yaml index efd22e1a..991c56ba 100644 --- a/config_default.yaml +++ b/config_default.yaml @@ -34,10 +34,9 @@ vagrant: options: manage_host: true manage_guest: true - # usually defined from workspace/dev-setup/ - preload_extension_paths: - postload_extension_paths: - config_paths: + # usually defined on workspace/dev-setup/config_default.yaml + extension_file_paths: + config_file_paths: # teracy-dev related settings diff --git a/lib/configurator.rb b/lib/configurator.rb index ff46d090..84b37d4c 100644 --- a/lib/configurator.rb +++ b/lib/configurator.rb @@ -61,7 +61,42 @@ def _configure_providers(providers_config, node) end +$before_hooks = [] +$after_hooks = [] + +def _run_before_configure_hooks(node_config, node) + $logger.debug("_run_before_configure_hooks") + $before_hooks.each do |block| + block.call(node_config, node) + end +end + + +def _run_after_configure_hooks(node_config, node) + $logger.debug("_run_after_configure_hooks") + $after_hooks.each do |block| + block.call(node_config, node) + end +end + + +def register_before_configure_hook(&block) + $before_hooks << block + $logger.debug("$before_hooks: #{$before_hooks}") +end + + +def register_after_configure_hook(&block) + $after_hooks << block + $logger.debug("$after_hooks: #{$after_hooks}") +end + + + def configure(node_config, node) + # hooks callback + _run_before_configure_hooks(node_config, node) + _configure_vm(node_config["vm"], node) _configure_ssh(node_config["ssh"], node) _configure_winrm(node_config["winrm"], node) @@ -71,4 +106,7 @@ def configure(node_config, node) _configure_networks(node_config["networks"], node) _configure_sync_folders(node_config["synced-folders"], node) _configure_provisioners(node_config["providers"], node) + + # hooks calback + _run_after_configure_hooks(node_config, node) end