Skip to content

Commit

Permalink
change delay logic from sleep to backoff timer
Browse files Browse the repository at this point in the history
default gateway needs to be reachable.  sleeping 5 seconds fails
in some cases so an exponent backoff timer of 2^5 was implemented
  • Loading branch information
rismoney committed Mar 5, 2014
1 parent adf81b4 commit 7ae3e4a
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lib/puppet/provider/ipconfig/ipconfig.rb
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -222,4 +232,4 @@ def destroy
netconnectionid.enabledhcp()
end
end
end
end

0 comments on commit 7ae3e4a

Please sign in to comment.