From 7ae3e4ab7f6abd774602175a6c1b8271e33204b3 Mon Sep 17 00:00:00 2001 From: Rich Siegel Date: Wed, 5 Mar 2014 12:29:23 -0500 Subject: [PATCH] change delay logic from sleep to backoff timer default gateway needs to be reachable. sleeping 5 seconds fails in some cases so an exponent backoff timer of 2^5 was implemented --- lib/puppet/provider/ipconfig/ipconfig.rb | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/puppet/provider/ipconfig/ipconfig.rb b/lib/puppet/provider/ipconfig/ipconfig.rb index d19fdd4..5a03b11 100644 --- a/lib/puppet/provider/ipconfig/ipconfig.rb +++ b/lib/puppet/provider/ipconfig/ipconfig.rb @@ -1,4 +1,5 @@ require File.join(File.dirname(__FILE__), '..', 'winnetwork') +require 'ping' WOW64_64 = 0x100 unless defined?(WOW64_64) WOW64_32 = 0x200 unless defined?(WOW64_32) @@ -36,19 +37,24 @@ def enum_netconn end + def backoff(upto) + result = [ ] + (1..upto).each do |iter| + result << ((2**iter)) + end + return result + end - -def getreg(guid,keyname) - require 'win32/registry' - keypath = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\" + guid - reg_type = Win32::Registry::KEY_READ | WOW64_64 - Win32::Registry::HKEY_LOCAL_MACHINE.open(keypath, reg_type) do |reg| - regkey = reg[keyname] - return regkey + def getreg(guid,keyname) + require 'win32/registry' + keypath = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\" + guid + reg_type = Win32::Registry::KEY_READ | WOW64_64 + Win32::Registry::HKEY_LOCAL_MACHINE.open(keypath, reg_type) do |reg| + regkey = reg[keyname] + return regkey + end end -end - - + def exists? rc=false enum_netconn do |netconnectionid| @@ -110,6 +116,11 @@ def defaultgateway= newvalue :defaultgateway => @resource[:defaultgateway], :gwcostmetric => @resource[:gwcostmetric]) end + + self.backoff(5).each do |sleeptime| + foo = Ping.pingecho(@resource[:defaultgateway].to_s, 10) + foo ? break : sleep(sleeptime) + end end def gwcostmetric @@ -204,7 +215,6 @@ def netbios=newvalue end end - def create self.dnsdomain = @resource[:dnsdomain] unless @resource[:dnsdomain].to_s.empty? self.ipaddress= @resource[:ipaddress] @@ -213,7 +223,7 @@ def create self.dnsregister = @resource[:dnsregister] unless @resource[:dnsregister].to_s.empty? self.netbios = @resource[:netbios] unless @resource[:netbios].to_s.empty? self.dnsdomainsuffixsearchorder = @resource[:dnsdomainsuffixsearchorder] unless @resource[:dnsdomainsuffixsearchorder].to_s.empty? - sleep 5 + true end @@ -222,4 +232,4 @@ def destroy netconnectionid.enabledhcp() end end -end +end \ No newline at end of file