/** * xGetPlatformInstanceTypesAction * * @param string $platform The name of the cloud platform * @param string $cloudLocation The cloud location * @param string $envId optional The identifier of the environment * @param string $effectiveDate optional The date on which prices should be applied YYYY-MM-DD * @throws \Exception */ public function xGetPlatformInstanceTypesAction($platform, $cloudLocation, $envId = null, $effectiveDate = null) { list($curDate, $effectiveDate) = $this->handleEffectiveDate($effectiveDate); $pm = PlatformFactory::NewPlatform($platform); $env = null; $url = ''; try { if (!empty($envId)) { $env = Scalr_Environment::init()->loadById($envId); if (PlatformFactory::isOpenstack($platform)) { $key = Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL; } else { if (PlatformFactory::isCloudstack($platform)) { $key = Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL; } else { throw new Exception('This action is not yet supported for the specified cloud platform.'); } } if (empty($url)) { $url = $env->keychain($platform)->properties[$key]; } } else { if ($platform == SERVER_PLATFORMS::EC2 || $platform == SERVER_PLATFORMS::GCE) { $gcenvid = $this->getEnvIdByPlatform($platform); $env = Scalr_Environment::init()->loadById($gcenvid); } } } catch (Exception $e) { if (stristr($e->getMessage(), 'not found')) { //Tries to find url from the cloud_locations table if (empty($url) && (PlatformFactory::isOpenstack($platform) || PlatformFactory::isCloudstack($platform))) { $clEntity = CloudLocation::findOne([['platform' => $platform], ['cloudLocation' => $cloudLocation]], null, ['updated' => false]); if ($clEntity instanceof CloudLocation) { $url = $clEntity->url; } } } else { throw $e; } } $result = $this->getTypesWithPrices($cloudLocation, $url, $pm, $platform, $effectiveDate, $env); $this->response->data(['data' => $result]); }
/** * xGetPlatformInstanceTypesAction * * @param string $platform The name of the cloud platform * @param string $cloudLocation The cloud location * @param string $envId optional The identifier of the environment * @param string $effectiveDate optional The date on which prices should be applied YYYY-MM-DD * @throws \Exception */ public function xGetPlatformInstanceTypesAction($platform, $cloudLocation, $envId = null, $effectiveDate = null) { list($curDate, $effectiveDate) = $this->handleEffectiveDate($effectiveDate); $pm = PlatformFactory::NewPlatform($platform); $env = null; $url = ''; try { if (!empty($envId)) { $env = Scalr_Environment::init()->loadById($envId); if (PlatformFactory::isOpenstack($platform)) { $key = $platform . '.' . OpenstackPlatformModule::KEYSTONE_URL; } else { if (PlatformFactory::isCloudstack($platform)) { $key = $platform . '.' . CloudstackPlatformModule::API_URL; } else { if ($platform == SERVER_PLATFORMS::EUCALYPTUS) { $key = EucalyptusPlatformModule::EC2_URL; $url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key, false, $cloudLocation)); } else { throw new Exception('This action is not yet supported for the specified cloud platform.'); } } } if (empty($url)) { $url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key)); } } else { if ($platform == SERVER_PLATFORMS::EC2 || $platform == SERVER_PLATFORMS::GCE) { $gcenvid = $this->getPlatformEnvId($platform); $env = Scalr_Environment::init()->loadById($gcenvid); } } } catch (Exception $e) { if (stristr($e->getMessage(), 'not found')) { //Tries to find url from the cloud_locations table if (empty($url) && (PlatformFactory::isOpenstack($platform) || PlatformFactory::isCloudstack($platform))) { $clEntity = CloudLocation::findOne([['platform' => $platform], ['cloudLocation' => $cloudLocation]], ['updated' => false]); if ($clEntity instanceof CloudLocation) { $url = $clEntity->url; } } } else { throw $e; } } $result = $this->getTypesWithPrices($cloudLocation, $url, $pm, $platform, $effectiveDate, $env); $this->response->data(['data' => $result]); }