Exemplo n.º 1
0
 /**
  * xGetPlatformEndpointsAction
  *
  * @param    string    $platform  The cloud platform
  */
 public function xGetPlatformEndpointsAction($platform)
 {
     if (PlatformFactory::isOpenstack($platform)) {
         $key = Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL;
     } else {
         if (PlatformFactory::isCloudstack($platform)) {
             $key = Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL;
         }
     }
     if (isset($key)) {
         $pm = PlatformFactory::NewPlatform($platform);
         $rs = $this->db->Execute("\n                SELECT DISTINCT ce.`id`, cecc.`cloud_credentials_id`\n                FROM client_environments ce\n                JOIN clients c ON c.id = ce.client_id\n                JOIN environment_cloud_credentials cecc ON ce.`id` = cecc.`env_id` AND cecc.`cloud` = ?\n                JOIN cloud_credentials_properties ccp ON cecc.`cloud_credentials_id` = ccp.`cloud_credentials_id`\n                LEFT JOIN client_environment_properties cep ON ce.`id` = cep.`env_id` AND cep.`name` = ?\n                WHERE c.status = ? AND ccp.name = ? AND ce.status = ? AND cep.`value` IS NULL OR cep.`value` = ''\n                GROUP BY ccp.`value`\n            ", [$platform, "{$platform}.suspended", Scalr_Account::STATUS_ACTIVE, $key, Scalr_Environment::STATUS_ACTIVE]);
         $endpoints = [];
         $cloudCredsIds = [];
         $envs = [];
         while ($rec = $rs->FetchRow()) {
             $cloudCredsId = $rec['cloud_credentials_id'];
             $envs[$cloudCredsId] = $rec['id'];
             $cloudCredsIds[] = $cloudCredsId;
         }
         $cloudCredentialsEntity = new Entity\CloudCredentials();
         $idFieldType = $cloudCredentialsEntity->getIterator()->getField('id')->getType();
         foreach (array_chunk($cloudCredsIds, 128) as $chunk) {
             /* @var $cloudCredentials Entity\CloudCredentials */
             foreach (Entity\CloudCredentials::find([['id' => ['$in' => $chunk]]]) as $cloudCredentials) {
                 $url = $this->getContainer()->analytics->prices->normalizeUrl($cloudCredentials->properties[$key]);
                 if (!array_key_exists($url, $endpoints)) {
                     $endpoints[$url] = array('envId' => $envs[$cloudCredentials->id], 'url' => $url);
                 }
             }
         }
     } else {
         $endpoints[0] = $platform;
     }
     $this->response->data(['data' => array_values($endpoints)]);
 }