public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
{
if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) {
throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__));
}
$ret = [];
$detailed = [];
//Trying to retrieve instance types from the cache
$url = $env->keychain($this->platform)->properties[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL];
$collection = $this->getCachedInstanceTypes($this->platform, $url, $cloudLocation);
if ($collection === false || $collection->count() == 0) {
//No cache. Fetching data from the cloud
$client = $env->openstack($this->platform, $cloudLocation);
$flavors = $client->servers->listFlavors();
foreach ($flavors as $flavor) {
$detailed[(string) $flavor->id] = array('name' => (string) $flavor->name, 'ram' => (string) $flavor->ram, 'vcpus' => (string) $flavor->vcpus, 'disk' => (string) $flavor->disk, 'type' => 'HDD');
if (!$details) {
$ret[(string) $flavor->id] = (string) $flavor->name;
} else {
$ret[(string) $flavor->id] = $detailed[(string) $flavor->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;
}