lib/gogetit/util.rb in gogetit-0.2.1 vs lib/gogetit/util.rb in gogetit-0.3.0

- old
+ new

@@ -89,11 +89,11 @@ thing end end def wait_until_available(fqdn, logger) - until ping_available?(fqdn) + until ping_available?(fqdn, logger) logger.info("Calling <#{__method__.to_s}> for ping to be ready..") sleep 3 end logger.info("#{fqdn} is now available to ping..") @@ -102,19 +102,35 @@ sleep 3 end logger.info("#{fqdn} is now available to ssh..") end - def ping_available?(fqdn) - `ping -c 1 -W 1 #{fqdn}` + def ping_available?(host, logger) + # host can be both IP and FQDN. + logger.info("Calling <#{__method__.to_s}> for #{host}") + `ping -c 1 -W 1 #{host}` $?.exitstatus == 0 end def ssh_available?(fqdn, user) begin Net::SSH.start(fqdn, user).class rescue Exception => e puts e end end + + def check_ip_available(addresses, maas, logger) + logger.info("Calling <#{__method__.to_s}>") + # to do a ping test + addresses.each do |ip| + abort("#{ip} is already being used.") if ping_available?(ip, logger) + end + # to check with MAAS + ifaces = maas.ip_reserved?(addresses) + abort("one of #{addresses.join(', ')} is already being used.") \ + unless ifaces + return ifaces + end + end end