Skip to content

Commit

Permalink
Merge pull request #249 from hoatle/features/#248-use-hostmanager-ins…
Browse files Browse the repository at this point in the history
…tead-of-hostsupdater-plugin_deps_#246

Features/#248 use hostmanager instead of hostsupdater plugin deps #246
  • Loading branch information
hoatle committed Feb 9, 2017
2 parents e2fed1a + fcd7d63 commit b6650ce
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 19 deletions.
52 changes: 39 additions & 13 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,56 @@ Vagrant.configure("2") do |config|

# this is current fixed config, not dynamic plugins config
# FIXME(hoatle): #186 should fix this

if Vagrant.has_plugin?(plugin_name) and plugin.key?('config_key')
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 plugin['latency'].nil?
config.gatling.latency = plugin['latency']
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
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 plugin['time_format'].nil? or plugin['time_format'].empty?
config.gatling.time_format = plugin['time_format']
unless options['ignore_private_ip'].nil?
config.hostmanager.ignore_private_ip = options['ignore_private_ip']
end

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

elsif 'hostsupdater' == config_key
unless plugin['aliases'].nil? or plugin['aliases'].empty?
config.hostsupdater.aliases = plugin['aliases']
unless options['aliases'].nil?
config.hostmanager.aliases = options['aliases']
end

unless plugin['remove_on_suspend'].nil? or plugin['remove_on_suspend'].empty?
config.hostsupdater.remove_on_suspend = plugin['remove_on_suspend']
# 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
Expand Down
23 changes: 23 additions & 0 deletions lib/utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,26 @@ def prompt(message)
print message
return STDIN.gets.chomp
end

# thanks to https://github.com/devopsgroup-io/vagrant-hostmanager/issues/121#issuecomment-69050265

def read_ip_address(machine)
command = "LANG=en ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'"
result = ""

# $logger.info "Processing #{ machine.name } ... "

begin
# sudo is needed for ifconfig
machine.communicate.sudo(command) do |type, data|
result << data if type == :stdout
end
# $logger.info "Processing #{ machine.name } ... success"
rescue
result = "# NOT-UP"
# $logger.info "Processing #{ machine.name } ... not running"
end

# the second inet is more accurate
result.chomp.split("\n").last
end
27 changes: 21 additions & 6 deletions vagrant_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,29 @@
"name": "vagrant-gatling-rsync",
"config_key": "gatling",
"required": true,
// auto rsync watch when up/ reload done
// should try to reduce rsync latency to 0.5s instead of 1s #173
"latency": 0.5, //0.5s
"time_format": "%H:%M:%S",
"rsync_on_startup": true
"enabled": true,
"options": {
// auto rsync watch when up/ reload done
// should try to reduce rsync latency to 0.5s instead of 1s #173
"latency": 0.5, //0.5s
"time_format": "%H:%M:%S",
"rsync_on_startup": true
}
}, {
"_id": "1",
"name": "vagrant-rsync-back",
"required": true
"required": true,
"enabled": true
}, {
"_id" : "2",
"name" : "vagrant-hostmanager",
"config_key" : "hostmanager",
"required" : true,
"enabled" : true,
"options" : {
"enabled" : true,
"manage_host" : true,
"manage_guest" : true
}
}]
}

0 comments on commit b6650ce

Please sign in to comment.