/** * Gets the list of the Eucalyptus instances * for the specified environment and Euca location * * @param Scalr_Environment $environment Environment Object * @param string $region Eucalyptus location name * @param bool $skipCache Whether it should skip the cache. * @return array Returns array looks like array(InstanceId => stateName) */ public function GetServersList(Scalr_Environment $environment, $region, $skipCache = false) { if (!$region) { return array(); } if (empty($this->instancesListCache[$environment->id][$region]) || $skipCache) { try { $results = $environment->eucalyptus($region)->ec2->instance->describe(); } catch (Exception $e) { throw new Exception(sprintf("Cannot get list of servers for platfrom euca: %s", $e->getMessage())); } if (count($results)) { foreach ($results as $reservation) { /* @var $reservation Scalr\Service\Aws\Ec2\DataType\ReservationData */ foreach ($reservation->instancesSet as $instance) { /* @var $instance Scalr\Service\Aws\Ec2\DataType\InstanceData */ $this->instancesListCache[$environment->id][$region][$instance->instanceId] = $instance->instanceState->name; } } } } return !empty($this->instancesListCache[$environment->id][$region]) ? $this->instancesListCache[$environment->id][$region] : array(); }
/** * {@inheritdoc} * @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes() */ public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false) { if (!$env instanceof \Scalr_Environment || empty($cloudLocation)) { throw new \InvalidArgumentException(sprintf("Method %s requires both environment object and cloudLocation to be specified.", __METHOD__)); } $client = $env->eucalyptus($cloudLocation); $ret = array(); foreach ($client->describeInstanceTypes() as $item) { if (!$details) { $ret[(string) $item->name] = sprintf("%s (CPUs: %d DISK: %d RAM: %d)", $item->name, $item->cpu, $item->disk, $item->memory); } else { $ret[(string) $item->name] = array('name' => (string) $item->name, 'ram' => (string) $item->memory, 'vcpus' => (string) $item->cpu, 'disk' => (string) $item->disk, 'type' => 'hdd'); } } return $ret; }
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(); } }