enablePlatform() public method

public enablePlatform ( $platform, $enabled = true )
Example #1
0
 private function saveRackspace()
 {
     $pars = array();
     $locations = array('rs-ORD1', 'rs-LONx');
     $enabled = false;
     /* @var $currentCloudCredentials Entity\CloudCredentials[] */
     $currentCloudCredentials = $this->env->cloudCredentialsList(array_map(function ($location) {
         return "{$location}." . SERVER_PLATFORMS::RACKSPACE;
     }, $locations));
     foreach ($currentCloudCredentials as $cloudCredential) {
         if ($cloudCredential->isEnabled()) {
             $enabled = true;
             break;
         }
     }
     if (!$enabled) {
         throw new Scalr_Exception_Core('Rackspace cloud has been deprecated. Please use Rackspace Open Cloud instead.');
     } else {
         $enabled = false;
     }
     foreach ($locations as $location) {
         if ($this->getParam("rackspace_is_enabled_{$location}")) {
             $enabled = true;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_USERNAME] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_USERNAME, 'string', "Username required", $location . SERVER_PLATFORMS::RACKSPACE);
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_API_KEY, 'string', "API Key required", $location . SERVER_PLATFORMS::RACKSPACE);
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED] = $this->checkVar(Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED, 'bool', "", $location . SERVER_PLATFORMS::RACKSPACE);
         } else {
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_USERNAME] = false;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_API_KEY] = false;
             $pars[$location][Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED] = false;
         }
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         $this->db->BeginTrans();
         try {
             foreach ($pars as $location => $prs) {
                 $this->env->enablePlatform("{$location}." . SERVER_PLATFORMS::RACKSPACE, $enabled);
                 $this->makeCloudCredentials("{$location}." . SERVER_PLATFORMS::RACKSPACE, $prs);
                 $this->env->setPlatformConfig([Entity\Account\EnvironmentProperty::RACKSPACE_LOCATIONS => 'enabled'], true, $location);
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success('Cloud credentials have been ' . ($enabled ? 'saved' : 'removed from Scalr'));
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(_('Failed to save Rackspace settings'));
         }
         $this->db->CommitTrans();
     }
 }
Example #2
0
 public function xSaveCloudstackAction()
 {
     $pars = array();
     $enabled = false;
     $platform = $this->getParam('platform');
     if ($this->getParam("{$platform}_is_enabled")) {
         $enabled = true;
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL, 'string', 'API URL required', $platform);
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY, 'string', 'API key required', $platform);
         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY, 'string', 'Secret key required', $platform);
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         if ($this->getParam("{$platform}_is_enabled")) {
             $cs = new CloudStack($pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY], $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY], $platform);
             $accounts = $cs->listAccounts();
             foreach ($accounts as $account) {
                 foreach ($account->user as $user) {
                     if ($user->apikey == $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY]) {
                         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME] = $user->account;
                         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_NAME] = $user->domain;
                         $pars[Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_ID] = $user->domainid;
                     }
                 }
             }
             if (empty($pars[Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME])) {
                 throw new Exception("Cannot determine account name for provided keys");
             }
         }
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform($platform, $enabled);
             if ($enabled) {
                 $this->makeCloudCredentials($platform, $pars);
             } else {
                 $this->env->cloudCredentials($platform)->properties->saveSettings([Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME => false, Entity\CloudCredentialsProperty::CLOUDSTACK_API_KEY => false, Entity\CloudCredentialsProperty::CLOUDSTACK_API_URL => false, Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_ID => false, Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_NAME => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP_ID => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP_INFO => false, Entity\CloudCredentialsProperty::CLOUDSTACK_SZR_PORT_COUNTER => false]);
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success('Environment saved');
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(_('Failed to save ' . ucfirst($platform) . ' settings'));
         }
         $this->db->CommitTrans();
     }
 }
Example #3
0
 public function xSaveEucalyptusAction()
 {
     $this->request->defineParams(array('clouds' => array('type' => 'json')));
     $pars = array();
     $enabled = false;
     $clouds = $this->getParam('clouds');
     $cloudsDeleted = array();
     if (count($clouds)) {
         $enabled = true;
         foreach ($clouds as $cloud) {
             $pars[$cloud][EucalyptusPlatformModule::ACCOUNT_ID] = $this->checkVar(EucalyptusPlatformModule::ACCOUNT_ID, 'string', "Account ID required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::ACCESS_KEY] = $this->checkVar(EucalyptusPlatformModule::ACCESS_KEY, 'string', "Access Key required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::EC2_URL] = $this->checkVar(EucalyptusPlatformModule::EC2_URL, 'string', "EC2 URL required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::S3_URL] = $this->checkVar(EucalyptusPlatformModule::S3_URL, 'string', "S3 URL required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::SECRET_KEY] = $this->checkVar(EucalyptusPlatformModule::SECRET_KEY, 'password', "Secret Key required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::PRIVATE_KEY] = $this->checkVar(EucalyptusPlatformModule::PRIVATE_KEY, 'file', "x.509 Private Key required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::CERTIFICATE] = $this->checkVar(EucalyptusPlatformModule::CERTIFICATE, 'file', "x.509 Certificate required", $cloud);
             $pars[$cloud][EucalyptusPlatformModule::CLOUD_CERTIFICATE] = $this->checkVar(EucalyptusPlatformModule::CLOUD_CERTIFICATE, 'file', "x.509 Cloud Certificate required", $cloud);
         }
     }
     // clear old cloud locations
     foreach ($this->db->GetAll('SELECT * FROM client_environment_properties WHERE env_id = ? AND name LIKE "eucalyptus.%" AND `group` != "" GROUP BY `group', $this->env->id) as $key => $value) {
         if (!in_array($value['group'], $clouds)) {
             $cloudsDeleted[] = $value['group'];
         }
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform(SERVER_PLATFORMS::EUCALYPTUS, $enabled);
             foreach ($cloudsDeleted as $key => $cloud) {
                 $this->db->Execute('DELETE FROM client_environment_properties WHERE env_id = ? AND `group` = ? AND name LIKE "eucalyptus.%"', array($this->env->id, $cloud));
             }
             foreach ($pars as $cloud => $prs) {
                 $this->env->setPlatformConfig($prs, true, $cloud);
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success(_('Environment saved'));
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(_('Failed to save Eucalyptus settings'));
         }
         $this->db->CommitTrans();
     }
 }
Example #4
0
 private function saveOpenstack()
 {
     $pars = array();
     $enabled = false;
     $platform = $this->getParam('platform');
     $currentCloudCredentials = $this->env->keychain($platform);
     $bNew = !$currentCloudCredentials->isEnabled();
     if (!$bNew) {
         $oldUrl = $currentCloudCredentials->properties[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL];
     }
     if ($this->getParam("{$platform}_is_enabled")) {
         $enabled = true;
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL] = trim($this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL, 'string', 'KeyStone URL required', $platform));
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_SSL_VERIFYPEER] = trim($this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_SSL_VERIFYPEER, 'bool', '', $platform));
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_USERNAME, 'string', 'Username required', $platform);
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD, 'password', '', $platform, false);
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_API_KEY, 'string', '', $platform);
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION] = OpenStackConfig::parseIdentityVersion($pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL]);
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME, 'string', '', $platform);
         $pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME] = $this->checkVar(Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME, 'string', '', $platform);
         if (empty($this->checkVarError) && empty($pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD]) && empty($pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY])) {
             $this->checkVarError['api_key'] = $this->checkVarError['password'] = '******';
         }
     }
     /* @var $config Yaml */
     $config = $this->env->getContainer()->config;
     if (isset($platform) && $config->defined("scalr.{$platform}.use_proxy") && $config("scalr.{$platform}.use_proxy") && in_array($config('scalr.connections.proxy.use_on'), ['both', 'scalr'])) {
         $proxySettings = $config('scalr.connections.proxy');
     } else {
         $proxySettings = null;
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         if ($this->getParam($platform . "_is_enabled")) {
             $os = new OpenStack(new OpenStackConfig($pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL], 'fake-region', $pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY], null, null, $pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD], $pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION], $proxySettings));
             //It throws an exception on failure
             $zones = $os->listZones();
             $zone = array_shift($zones);
             $os = new OpenStack(new OpenStackConfig($pars[Entity\CloudCredentialsProperty::OPENSTACK_USERNAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL], $zone->name, $pars[Entity\CloudCredentialsProperty::OPENSTACK_API_KEY], null, null, $pars[Entity\CloudCredentialsProperty::OPENSTACK_PASSWORD], $pars[Entity\CloudCredentialsProperty::OPENSTACK_TENANT_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_DOMAIN_NAME], $pars[Entity\CloudCredentialsProperty::OPENSTACK_IDENTITY_VERSION], $proxySettings));
             // Check SG Extension
             $pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_SECURITYGROUPS_ENABLED] = (int) $os->servers->isExtensionSupported(ServersExtension::securityGroups());
             // Check Floating Ips Extension
             $pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_FLOATING_IPS_ENABLED] = (int) $os->servers->isExtensionSupported(ServersExtension::floatingIps());
             // Check Cinder Extension
             $pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_CINDER_ENABLED] = (int) $os->hasService('volume');
             // Check Swift Extension
             $pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_SWIFT_ENABLED] = (int) $os->hasService('object-store');
             // Check LBaas Extension
             $pars[Entity\CloudCredentialsProperty::OPENSTACK_EXT_LBAAS_ENABLED] = !in_array($platform, array(SERVER_PLATFORMS::RACKSPACENG_US, SERVER_PLATFORMS::RACKSPACENG_UK)) && $os->hasService('network') ? (int) $os->network->isExtensionSupported('lbaas') : 0;
         }
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform($platform, $enabled);
             if ($enabled) {
                 $this->makeCloudCredentials($platform, $pars);
                 if ($this->getContainer()->analytics->enabled && ($bNew || $oldUrl !== $pars[Entity\CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL])) {
                     $this->getContainer()->analytics->notifications->onCloudAdd($platform, $this->env, $this->user);
                 }
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success('Cloud credentials have been ' . ($enabled ? 'saved' : 'removed from Scalr'));
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(_('Failed to save ' . ucfirst($platform) . ' settings'));
         }
         $this->db->CommitTrans();
     }
 }
Example #5
0
 public function xSaveEucalyptusAction()
 {
     $this->request->defineParams(array('clouds' => array('type' => 'json')));
     $pars = array();
     $enabled = false;
     $clouds = $this->getParam('clouds');
     $cloudsDeleted = array();
     if (count($clouds)) {
         $enabled = true;
         foreach ($clouds as $cloud) {
             $pars[$cloud][Modules_Platforms_Eucalyptus::ACCOUNT_ID] = $this->checkVar(Modules_Platforms_Eucalyptus::ACCOUNT_ID, 'string', "Account ID required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::ACCESS_KEY] = $this->checkVar(Modules_Platforms_Eucalyptus::ACCESS_KEY, 'string', "Access Key required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::EC2_URL] = $this->checkVar(Modules_Platforms_Eucalyptus::EC2_URL, 'string', "EC2 URL required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::S3_URL] = $this->checkVar(Modules_Platforms_Eucalyptus::S3_URL, 'string', "S3 URL required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::SECRET_KEY] = $this->checkVar(Modules_Platforms_Eucalyptus::SECRET_KEY, 'password', "Secret Key required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::PRIVATE_KEY] = $this->checkVar(Modules_Platforms_Eucalyptus::PRIVATE_KEY, 'file', "x.509 Private Key required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::CERTIFICATE] = $this->checkVar(Modules_Platforms_Eucalyptus::CERTIFICATE, 'file', "x.509 Certificate required", $cloud);
             $pars[$cloud][Modules_Platforms_Eucalyptus::CLOUD_CERTIFICATE] = $this->checkVar(Modules_Platforms_Eucalyptus::CLOUD_CERTIFICATE, 'file', "x.509 Cloud Certificate required", $cloud);
         }
     }
     // clear old cloud locations
     foreach ($this->db->GetAll("\n                SELECT * FROM client_environment_properties\n                WHERE env_id = ? AND name LIKE 'eucalyptus.%' AND `group` != ''\n                GROUP BY `group`\n            ", $this->env->id) as $key => $value) {
         if (!in_array($value['group'], $clouds)) {
             $cloudsDeleted[] = $value['group'];
         }
     }
     if (count($this->checkVarError)) {
         $this->response->failure();
         $this->response->data(array('errors' => $this->checkVarError));
     } else {
         $this->db->BeginTrans();
         try {
             $this->env->enablePlatform(SERVER_PLATFORMS::EUCALYPTUS, $enabled);
             foreach ($cloudsDeleted as $key => $cloud) {
                 $this->db->Execute('
                     DELETE FROM client_environment_properties
                     WHERE env_id = ? AND `group` = ? AND name LIKE "eucalyptus.%"
                 ', array($this->env->id, $cloud));
             }
             foreach ($pars as $cloud => $prs) {
                 //Saves options to database
                 $this->env->setPlatformConfig($prs, true, $cloud);
                 //Verifies cloud credentials
                 $client = $this->env->eucalyptus($cloud);
                 try {
                     //Checks ec2url
                     $client->ec2->availabilityZone->describe();
                 } catch (ClientException $e) {
                     throw new Exception(sprintf("Failed to verify your access key and secret key against ec2 service for location %s: (%s)", $cloud, $e->getMessage()));
                 }
                 try {
                     //Verifies s3url
                     $client->s3->bucket->getList();
                 } catch (ClientException $e) {
                     throw new Exception(sprintf("Failed to verify your access key and secret key against s3 service for location %s: (%s)", $cloud, $e->getMessage()));
                 }
             }
             if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                 $this->user->getAccount()->setSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED, time());
             }
             $this->response->success(_('Environment saved'));
             $this->response->data(array('enabled' => $enabled));
         } catch (Exception $e) {
             $this->db->RollbackTrans();
             throw new Exception(sprintf("Failed to save Eucalyptus settings. %s", $e->getMessage()));
         }
         $this->db->CommitTrans();
     }
 }