Guest User

Untitled

a guest
Jan 6th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.93 KB | None | 0 0
  1. <%
  2. require 'ipaddr'
  3. # it's a bit confusing where values are coming from, so we are doing lookup to clarify
  4. ilo_hostname = scope.lookupvar("::hostname")
  5. ilo_netmask  = scope.lookupvar("hpilo::netmask")
  6. ilo_domain   = scope.lookupvar("::domain")
  7.  
  8. # caculate ipaddress automatically or use manual settings.
  9. if mapping == 'automatic'
  10.   ip     = IPAddr.new(ipaddress)
  11.   mask   = IPAddr.new(netmask)
  12.   ilo    = IPAddr.new(ilo_network)
  13.   gwhost = IPAddr.new(ilo_gwhost)
  14.   if ilo_host
  15.     host  = (ip.to_i & mask.to_i).to_i + IPAddr.new(ilo_host).to_i
  16.     ilogw = (ip.to_i & mask.to_i).to_i + gwhost.to_i
  17.   else
  18.     host  = ilo.to_i + (ip.to_i & (~mask).to_i).to_i
  19.     ilogw = ilo.to_i + gwhost.to_i
  20.   end
  21.   ilo_ipaddress = IPAddr.new(host, Socket::AF_INET).to_s
  22.   ilo_gateway   = IPAddr.new(ilogw, Socket::AF_INET).to_s
  23. else
  24.   ilo_ipaddress = scope.lookupvar("hpilo::ip")
  25.   ilo_gateway   = scope.lookupvar("hpilo::gateway")
  26. end
  27. -%>
Add Comment
Please, Sign In to add comment