public function getInstanceTypes(Scalr_Environment $env = null, $cloudLocation = null, $details = false)
{
if (!$env instanceof Scalr_Environment) {
throw new InvalidArgumentException(sprintf("Method %s requires environment to be specified.", __METHOD__));
}
$ret = [];
$detailed = [];
//Trying to retrieve instance types from the cache
$url = $env->keychain($this->platform)->properties[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL];
$collection = $this->getCachedInstanceTypes($this->platform, $url, $cloudLocation ?: '');
if ($collection === false || $collection->count() == 0) {
//No cache. Fetching data from the cloud
$client = $env->cloudstack($this->platform);
foreach ($client->listServiceOfferings() as $offering) {
$detailed[(string) $offering->id] = array('name' => (string) $offering->name, 'ram' => (string) $offering->memory, 'vcpus' => (string) $offering->cpunumber, 'disk' => "", 'type' => strtoupper((string) $offering->storagetype));
if (!$details) {
$ret[(string) $offering->id] = (string) $offering->name;
} else {
$ret[(string) $offering->id] = $detailed[(string) $offering->id];
}
}
//Refreshes/creates a cache
CloudLocation::updateInstanceTypes($this->platform, $url, $cloudLocation ?: '', $detailed);
} else {
//Takes data from cache
foreach ($collection as $cloudInstanceType) {
/* @var $cloudInstanceType \Scalr\Model\Entity\CloudInstanceType */
if (!$details) {
$ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->name;
} else {
$ret[$cloudInstanceType->instanceTypeId] = $cloudInstanceType->getProperties();
}
}
}
return $ret;
}