getInstanceTypes() public method

Gets the list of all available flavors for the specified environment and cloud location
public getInstanceTypes ( Scalr_Environment $env = null, string $cloudLocation = null, boolean $details = false ) : array
$env Scalr_Environment optional The scalr environment object
$cloudLocation string optional The cloud location
$details boolean optional Return instance type with detalis (CPU, RAM, DISK, etc)
return array Returns array of the available flavors. It should look like array(flavor => name).
Exemplo n.º 1
0
 /**
  * Gets instance types with its prices
  *
  * @param   string                  $cloudLocation
  * @param   string                  $url
  * @param   PlatformModuleInterface $pm
  * @param   string                  $platformName
  * @param   DateTime                $effectiveDate  optional The date on which prices should be applied
  * @param   Scalr_Environment       $env            optional
  * @return  array
  */
 private function getTypesWithPrices($cloudLocation, $url, $pm, $platformName, $effectiveDate = null, Scalr_Environment $env = null)
 {
     $result = ['cloudLocation' => $cloudLocation, 'url' => $this->getContainer()->analytics->prices->normalizeUrl($url)];
     try {
         $typeNames = $pm->getInstanceTypes($env, $cloudLocation);
     } catch (Exception $e) {
         //Has no connection to cloud provider or invalid keys
         $typeNames = [];
         //Fetches cloud location entity from the cache
         $cl = CloudLocation::findPk(CloudLocation::calculateCloudLocationId($platformName, $result['cloudLocation'], $result['url']));
         //It is possible that it might have been already removed
         if ($cl instanceof CloudLocation) {
             foreach ($cl->getActiveInstanceTypes() as $instanceTypeEntity) {
                 /* @var $instanceTypeEntity CloudInstanceType */
                 $typeNames[$instanceTypeEntity->instanceTypeId] = $instanceTypeEntity->name;
             }
         }
     }
     $result['types'] = array_keys($typeNames);
     $pricing = $this->getPlatformPricing($platformName, $result['cloudLocation'], $result['url'], $effectiveDate);
     if (!empty($pricing["prices"])) {
         foreach ($pricing['prices'] as $price) {
             if (false !== ($pos = array_search($price['type'], $result['types']))) {
                 unset($result['types'][$pos]);
             }
         }
     } else {
         $pricing["prices"] = [];
     }
     foreach ($result['types'] as $type) {
         $pricing['prices'][] = ['type' => $type, 'name' => isset($typeNames[$type]) ? $typeNames[$type] : $type];
     }
     $result = array_merge($result, $pricing);
     unset($result['types']);
     //Prices should be ordered by name
     if (!empty($result['prices']) && is_array($result['prices'])) {
         usort($result['prices'], function ($a, $b) {
             if ($a['type'] == $b['type']) {
                 return 0;
             }
             return $a['type'] < $b['type'] ? -1 : 1;
         });
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Gets instance types with its prices
  *
  * @param   string                  $cloudLocation
  * @param   string                  $url
  * @param   PlatformModuleInterface $pm
  * @param   string                  $platformName
  * @param   DateTime                $effectiveDate  optional The date on which prices should be applied
  * @param   Scalr_Environment       $env            optional
  * @return  array
  */
 private function getTypesWithPrices($cloudLocation, $url, $pm, $platformName, $effectiveDate = null, Scalr_Environment $env = null)
 {
     $typeNames = $pm->getInstanceTypes($env, $cloudLocation);
     $result = ['cloudLocation' => $cloudLocation, 'types' => array_keys($typeNames), 'url' => $this->getContainer()->analytics->prices->normalizeUrl($url)];
     $pricing = $this->getPlatformPricing($platformName, $result['cloudLocation'], $result['url'], $effectiveDate);
     if ($pricing['prices']) {
         foreach ($pricing['prices'] as $price) {
             if (false !== ($pos = array_search($price['type'], $result['types']))) {
                 unset($result['types'][$pos]);
             }
         }
     }
     foreach ($result['types'] as $type) {
         $pricing['prices'][] = ['type' => $type, 'name' => isset($typeNames[$type]) ? $typeNames[$type] : $type];
     }
     $result = array_merge($result, $pricing);
     unset($result['types']);
     //Prices should be ordered by name
     if (!empty($result['prices']) && is_array($result['prices'])) {
         usort($result['prices'], function ($a, $b) {
             if ($a['type'] == $b['type']) {
                 return 0;
             }
             return $a['type'] < $b['type'] ? -1 : 1;
         });
     }
     return $result;
 }