public function determineIpAddress($hostDetails, SupportedHost $host)
{
// what are we doing?
$log = usingLog()->startAction("query " . basename(__CLASS__) . " for IP address");
if (empty($hostDetails->ifaces)) {
// set default network interfaces
$hostDetails->ifaces = array('eth1', 'eth0');
}
// how do we do this?
foreach ($hostDetails->ifaces as $iface) {
$command = "/sbin/ifconfig {$iface}";
$result = $host->runCommandViaHostManager($hostDetails, $command);
if ($result->didCommandFail() || strpos($result->output, 'error fetching') !== false) {
// no interface found
//
// move on to the next interface to check
continue;
}
// reduce the output down to an IP address
$lines = explode("\n", $result->output);
$lines = FilterForMatchingString::against($lines, 'inet addr');
$lines = FilterColumns::from($lines, '1', ':');
$lines = FilterColumns::from($lines, '0', ' ');
// do we have an IP address?
if (!isset($lines[0]) || empty(trim(rtrim($lines[0])))) {
// no, we do not
continue;
}
// if we get here, then we've found an IP address!
$ipAddress = trim($lines[0]);
$log->endAction("IP address is '{$ipAddress}'");
return $ipAddress;
}
// if we get here, we do not know what the IP address is
$msg = "could not determine IP address";
$log->endAction($msg);
throw new E5xx_ActionFailed(__METHOD__, $msg);
}