Scalr\Modules\Platforms\Azure\AzurePlatformModule::getInstanceTypes PHP Method

getInstanceTypes() public method

See also: Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
public getInstanceTypes ( Scalr_Environment $env = null, $cloudLocation = null, $details = false )
$env Scalr_Environment
    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__));
        }
        $collection = $this->getCachedInstanceTypes(\SERVER_PLATFORMS::AZURE, '', $cloudLocation);
        if ($collection === false || $collection->count() == 0) {
            $instanceTypesResult = $env->azure()->compute->location->getInstanceTypesList($env->keychain(SERVER_PLATFORMS::AZURE)->properties[CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $cloudLocation);
            $ret = [];
            foreach ($instanceTypesResult as $instanceType) {
                $detailed[$instanceType->name] = ['name' => $instanceType->name, 'ram' => $instanceType->memoryInMB, 'vcpus' => $instanceType->numberOfCores, 'disk' => $instanceType->resourceDiskSizeInMB / 1024, 'type' => '', 'maxdatadiskcount' => $instanceType->maxDataDiskCount, 'rootdevicesize' => $instanceType->osDiskSizeInMB / 1024];
                if (!$details) {
                    $ret[$instanceType->name] = array($instanceType->name => $instanceType->name);
                } else {
                    $ret[$instanceType->name] = $detailed[$instanceType->name];
                }
            }
            CloudLocation::updateInstanceTypes(\SERVER_PLATFORMS::AZURE, '', $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;
    }