public function GetServersList(\Scalr_Environment $environment, $region, $skipCache = false)
{
if (!$region) {
return [];
}
$aws = $environment->aws($region);
$cacheKey = sprintf('%s:%s', $environment->id, $region);
if (!isset($this->instancesListCache[$cacheKey]) || $skipCache) {
$cacheValue = array();
/* @var $results ReservationList */
$results = null;
do {
try {
$results = $aws->ec2->instance->describe(null, null, isset($results) ? $results->getNextToken() : null, 1000);
} catch (Exception $e) {
throw new Exception(sprintf("Cannot get list of servers for platform ec2: %s", $e->getMessage()));
}
if (count($results)) {
foreach ($results as $reservation) {
/* @var $reservation ReservationData */
foreach ($reservation->instancesSet as $instance) {
/* @var $instance InstanceData */
$cacheValue[$cacheKey][$instance->instanceId] = ['localIp' => $instance->privateIpAddress, 'remoteIp' => $instance->ipAddress, 'status' => $instance->instanceState->name, 'type' => $instance->instanceType, '_timestamp' => time()];
}
}
}
} while ($results->getNextToken());
foreach ($cacheValue as $offset => $value) {
$this->instancesListCache[$offset] = $value;
}
}
return isset($this->instancesListCache[$cacheKey]) ? $this->instancesListCache[$cacheKey] : [];
}