Skip to content

Commit

Permalink
@ teracyhq#277 | add new extension mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
hoatle committed Jul 19, 2018
1 parent e49e262 commit 61cd774
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
36 changes: 25 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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
7 changes: 3 additions & 4 deletions config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions lib/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 61cd774

Please sign in to comment.