Example #1
0
 /**
  * xGetPlatformLocationsAction
  *
  * @param    string    $platform  Platform name
  * @param    string    $url       optional The endpoint url
  * @param    string    $envId     optional The identifier of the environment
  */
 public function xGetPlatformLocationsAction($platform, $url = '', $envId = null)
 {
     $result = [];
     $existingLocations = [];
     $locations = $this->getContainer()->analytics->prices->getCloudLocations($platform);
     foreach ($locations as $key => $value) {
         if ($key == $url) {
             foreach ($value as $cloudLocation) {
                 $result[] = ['url' => $key, 'cloudLocation' => $cloudLocation];
                 $existingLocations[] = $key . ';' . $cloudLocation;
             }
         }
     }
     $pm = PlatformFactory::NewPlatform($platform);
     $env = null;
     if ($envId) {
         $env = Scalr_Environment::init()->loadById($envId);
     } else {
         if ($platform == SERVER_PLATFORMS::GCE) {
             $gcenvid = $this->getEnvIdByPlatform($platform);
             if ($gcenvid) {
                 $gcenv = Scalr_Environment::init()->loadById($gcenvid);
                 $aLocations = $pm->getLocations($gcenv);
             }
         } else {
             if ($platform == SERVER_PLATFORMS::EC2) {
                 //All locations including gov & china clouds
                 $aLocations = $pm->getLocations();
             }
         }
     }
     $pmlocations = [];
     if ($envId || $platform != SERVER_PLATFORMS::EC2 && $platform != SERVER_PLATFORMS::GCE) {
         try {
             $pmlocations = $pm->getLocations($env);
         } catch (Exception $e) {
             $pmlocations = [];
         }
         if (empty($pmlocations)) {
             foreach (CloudLocation::find([['platform' => $platform], ['url' => $url]], null, ['updated' => false]) as $clEntity) {
                 /* @var $clEntity CloudLocation */
                 $pmlocations[$clEntity->cloudLocation] = $clEntity->cloudLocation;
             }
         }
     }
     foreach (array_merge(!empty($aLocations) ? $aLocations : [], (array) $pmlocations) as $location => $name) {
         if (!in_array($url . ';' . $location, $existingLocations)) {
             $result[] = ['url' => $url, 'cloudLocation' => $location];
         }
     }
     if (!empty($result[0])) {
         $result[0] = $this->getTypesWithPrices($result[0]['cloudLocation'], $result[0]['url'], $pm, $platform, null, empty($env) && $platform == SERVER_PLATFORMS::GCE ? $gcenv : $env);
     }
     $response = ['data' => $result];
     $this->response->data($response);
 }