Skip to content

Instantly share code, notes, and snippets.

@achanda
Created January 28, 2014 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achanda/8678327 to your computer and use it in GitHub Desktop.
Save achanda/8678327 to your computer and use it in GitHub Desktop.
def znode_bind_ip
#Needs to load on call so it gets recently written changes
site_conf = SC.load
result = nil
addrs = Socket.ip_address_list
mngmt_cidr = NetAddr::CIDR.create(site_conf.management_cidr)
addrs.each do |addr|
valid_ip = NetAddr.validate_ip_addr(addr.ip_address, :Version => 4) rescue false
if valid_ip
if mngmt_cidr.matches?(addr.ip_address)
result = addr.ip_address
end
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment