From 5864310e2232a132f3f13a796b4269109a9f9d51 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 30 Mar 2018 17:05:33 -0500 Subject: [PATCH] Fixing aws name issue and adding check for plugin --- lib/vagrant-hostsupdater/HostsUpdater.rb | 23 ++++++++++++----------- lib/vagrant-hostsupdater/version.rb | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/vagrant-hostsupdater/HostsUpdater.rb b/lib/vagrant-hostsupdater/HostsUpdater.rb index 8ce74e7..59a046f 100644 --- a/lib/vagrant-hostsupdater/HostsUpdater.rb +++ b/lib/vagrant-hostsupdater/HostsUpdater.rb @@ -17,12 +17,13 @@ def getIps if ip = getAwsPublicIp ips.push(ip) else - @machine.config.vm.networks.each do |network| - key, options = network[0], network[1] - ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip" - ips.push(ip) if ip - if options[:hostsupdater] == 'skip' - @ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)' + @machine.config.vm.networks.each do |network| + key, options = network[0], network[1] + ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip" + ips.push(ip) if ip + if options[:hostsupdater] == 'skip' + @ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)' + end end end @@ -42,7 +43,7 @@ def getIps ips.push( '127.0.0.1' ) end return ips - end + end # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] } def getHostnames(ips) @@ -182,7 +183,8 @@ def removeFromHosts(options = {}) def removeFromSshKnownHosts if !@isWindowsHost - hostnames = getHostnames + ips = getIps + hostnames = getHostnames(ips) hostnames.each do |hostname| command = %Q(sed -i -e '/#{hostname}/ d' #@@ssh_known_hosts_path) if system(command) @@ -214,11 +216,11 @@ def adviseOnSudo @ui.error "[vagrant-hostsupdater] Consider adding the following to your sudoers file:" @ui.error "[vagrant-hostsupdater] https://github.com/cogitatio/vagrant-hostsupdater#suppressing-prompts-for-elevating-privileges" end - private def getAwsPublicIp + return nil if ! Vagrant.has_plugin?("vagrant-aws") aws_conf = @machine.config.vm.get_provider_config(:aws) - return nil if ! aws_conf.is_a?(VagrantPlugins::AWS::Config) + return nil if ! aws_conf.is_a?(VagrantPlugins::Aws::Config) filters = ( aws_conf.tags || [] ).map {|k,v| sprintf('"Name=tag:%s,Values=%s"', k, v) }.join(' ') return nil if filters == '' cmd = 'aws ec2 describe-instances --filter '+filters @@ -232,7 +234,6 @@ def getAwsPublicIp return nil end end - end end end end diff --git a/lib/vagrant-hostsupdater/version.rb b/lib/vagrant-hostsupdater/version.rb index f30e3de..648a671 100644 --- a/lib/vagrant-hostsupdater/version.rb +++ b/lib/vagrant-hostsupdater/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module HostsUpdater - VERSION = '1.1.0' + VERSION = '1.1.1' end end