public function GetServerRealStatus(DBServer $DBServer)
{
$region = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION);
$iid = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
$cacheKey = sprintf('%s:%s', $DBServer->GetEnvironmentObject()->id, $region);
if (!$iid || !$region) {
$status = 'not-found';
} elseif (empty($this->instancesListCache[$cacheKey][$iid])) {
$aws = $DBServer->GetEnvironmentObject()->aws($region);
try {
$reservations = $aws->ec2->instance->describe($iid);
if ($reservations && count($reservations) > 0 && $reservations->get(0)->instancesSet && count($reservations->get(0)->instancesSet) > 0) {
$instance = $reservations->get(0)->instancesSet->get(0);
$status = $instance->instanceState->name;
$this->instancesListCache[$cacheKey][$instance->instanceId] = ['localIp' => $instance->privateIpAddress, 'remoteIp' => $instance->ipAddress, 'status' => $instance->instanceState->name, 'type' => $instance->instanceType];
} else {
$status = 'not-found';
}
} catch (InstanceNotFoundException $e) {
$status = 'not-found';
}
} else {
$status = $this->instancesListCache[$cacheKey][$iid]['status'];
}
return StatusAdapter::load($status);
}