本文整理汇总了PHP中Scalr_Environment::eucalyptus方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment::eucalyptus方法的具体用法?PHP Scalr_Environment::eucalyptus怎么用?PHP Scalr_Environment::eucalyptus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Environment
的用法示例。
在下文中一共展示了Scalr_Environment::eucalyptus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetServersList
/**
* 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();
}
示例2: getInstanceTypes
/**
* {@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;
}
示例3: xSaveEucalyptusAction
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();
}
}