本文整理汇总了PHP中Scalr_Environment类的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment类的具体用法?PHP Scalr_Environment怎么用?PHP Scalr_Environment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scalr_Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetServersList
public function GetServersList(Scalr_Environment $environment, $region, $skipCache = false)
{
if (!$region) {
return array();
}
if (!$this->instancesListCache[$environment->id][$region] || $skipCache) {
$EC2Client = Scalr_Service_Cloud_Aws::newEc2($region, $environment->getPlatformConfigValue(self::PRIVATE_KEY), $environment->getPlatformConfigValue(self::CERTIFICATE));
try {
$results = $EC2Client->DescribeInstances();
$results = $results->reservationSet;
} catch (Exception $e) {
throw new Exception(sprintf("Cannot get list of servers for platfrom ec2: %s", $e->getMessage()));
}
if ($results->item) {
if ($results->item->reservationId) {
$this->instancesListCache[$environment->id][$region][(string) $results->item->instancesSet->item->instanceId] = (string) $results->item->instancesSet->item->instanceState->name;
} else {
foreach ($results->item as $item) {
$this->instancesListCache[$environment->id][$region][(string) $item->instancesSet->item->instanceId] = (string) $item->instancesSet->item->instanceState->name;
}
}
}
}
return $this->instancesListCache[$environment->id][$region];
}
示例2: getLocations
/**
* Gets the list of available locations
*
* @param \Scalr_Environment $environment
* @return \Scalr_Environment Returns the list of available locations looks like array(location => description)
*/
public function getLocations(\Scalr_Environment $environment = null)
{
$accountType = null;
if ($environment instanceof \Scalr_Environment) {
$accountType = $environment->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE];
}
return $this->getLocationsByAccountType($accountType);
}
示例3: setConfigVariable
/**
* Sets the values for the specified platform properties
*
* @deprecated by cloud credentials
* @param array $pars Associative array of the keys -> value
* @param \Scalr_Environment $env The environment object
* @param string $encrypted optional This parameter is already ignored
* @param string $cloudLocation The cloud location
*/
public function setConfigVariable($pars, \Scalr_Environment $env, $encrypted = true, $cloudLocation = '')
{
$config = array();
foreach ($pars as $key => $v) {
$index = $this->platform ? "{$this->platform}.{$key}" : $key;
$config[$index] = $v;
}
$env->setPlatformConfig($config, $encrypted, $cloudLocation);
}
示例4: getLocations
/**
* Gets the list of available locations
*
* @return array Returns the list of available locations looks like array(location => description)
*/
public function getLocations(\Scalr_Environment $environment = null)
{
if ($environment instanceof \Scalr_Environment && $this instanceof Ec2PlatformModule) {
if ($environment->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_TYPE) == Ec2PlatformModule::ACCOUNT_TYPE_GOV_CLOUD) {
return array(Aws::REGION_US_GOV_WEST_1 => 'AWS / us-gov-west-1 (GovCloud US)');
}
}
return array(Aws::REGION_US_EAST_1 => 'AWS / us-east-1 (N. Virginia)', Aws::REGION_US_WEST_1 => 'AWS / us-west-1 (N. California)', Aws::REGION_US_WEST_2 => 'AWS / us-west-2 (Oregon)', Aws::REGION_EU_WEST_1 => 'AWS / eu-west-1 (Ireland)', Aws::REGION_SA_EAST_1 => 'AWS / sa-east-1 (Sao Paulo)', Aws::REGION_AP_SOUTHEAST_1 => 'AWS / ap-southeast-1 (Singapore)', Aws::REGION_AP_SOUTHEAST_2 => 'AWS / ap-southeast-2 (Sydney)', Aws::REGION_AP_NORTHEAST_1 => 'AWS / ap-northeast-1 (Tokyo)');
}
示例5: setUp
/**
* {@inheritdoc}
* @see PHPUnit_Framework_TestCase::setUp()
*/
protected function setUp()
{
parent::setUp();
$this->container = \Scalr::getContainer();
$this->environment = new \Scalr_Environment();
if (!$this->isSkipFunctionalTests()) {
$this->environment->loadById(\Scalr::config('scalr.phpunit.envid'));
$this->container->environment = $this->environment;
}
}
示例6: hasCloudPrices
/**
* {@inheritdoc}
* @see \Scalr\Modules\PlatformModuleInterface::hasCloudPrices()
*/
public function hasCloudPrices(\Scalr_Environment $env)
{
if (!$this->container->analytics->enabled) {
return false;
}
$url = $env->getPlatformConfigValue(static::API_URL);
if (empty($url)) {
return false;
}
return $this->container->analytics->prices->hasPriceForUrl(\SERVER_PLATFORMS::NIMBULA, $url) ?: $url;
}
示例7: testEnvironment
public function testEnvironment()
{
if (!$this->getUser()->isAccountOwner()) {
$this->markTestSkipped('Specified user cannot create new environments.');
}
$createdEnvId = 0;
// remove previous test envs
$env = new \Scalr_Environment();
$result = $env->loadByFilter(array('clientId' => $this->getEnvironment()->clientId, 'name' => self::getTestName(self::ENV_NAME)));
if (count($result)) {
foreach ($result as $e) {
$obj = new \Scalr_Environment();
$obj->loadById($e['id']);
$obj->delete();
}
}
// create new
$content = $this->request('/environments/xCreate', array('name' => self::getTestName(self::ENV_NAME)));
$this->assertTrue($content['success']);
if ($content['env']) {
$createdEnvId = $content['env']['id'];
}
// create failure
$content = $this->request('/environments/xCreate', array('name' => ''));
$this->assertFalse($content['success']);
// get info about test env
$content = $this->request('/environments/' . $createdEnvId . '/xGetInfo');
$this->assertTrue($content['success']);
$this->assertArrayHasKey('environment', $content);
$this->assertArrayHasKey('id', $content['environment']);
$this->assertArrayHasKey('name', $content['environment']);
$this->assertArrayHasKey('params', $content['environment']);
$this->assertArrayHasKey('enabledPlatforms', $content['environment']);
// get info about env failure
$content = $this->request('/environments/' . '-3' . '/xGetInfo');
$this->assertFalse($content['success']);
// check new env in list
$content = $this->request('/environments/xListEnvironments');
$this->assertTrue($content['success']);
$this->assertArrayHasKey('data', $content);
$flag = false;
foreach ($content['data'] as $value) {
if ($value['name'] == self::getTestName(self::ENV_NAME)) {
$flag = true;
}
}
$this->assertTrue($flag, 'Created environment not found in list');
// test platforms save
$this->envTestEc2($createdEnvId);
$content = $this->request('/environments/xRemove', array('envId' => $createdEnvId));
$this->assertTrue($content['success']);
}
示例8: getInstanceTypes
/**
* {@inheritdoc}
* @see \Scalr\Modules\PlatformModuleInterface::getInstanceTypes()
*/
public function getInstanceTypes(\Scalr_Environment $env = null, $cloudLocation = null, $details = false)
{
if (!$env instanceof \Scalr_Environment) {
throw new \InvalidArgumentException(sprintf("Method %s requires environment to be specified.", __METHOD__));
}
$ret = array();
$cs = $env->cloudstack($this->platform);
$products = $cs->listAvailableProductTypes();
if (count($products) > 0) {
foreach ($products as $product) {
$ret[(string) $product->serviceofferingid] = (string) $product->serviceofferingdesc;
}
}
return $ret;
}
示例9: run1
protected function run1($stage)
{
$envs = [];
$platform = SERVER_PLATFORMS::GCE;
$platformModule = PlatformFactory::NewPlatform($platform);
/* @var $platformModule GoogleCEPlatformModule*/
$result = $this->db->Execute("\n SELECT s.`server_id`, s.`cloud_location`, s.`type`, s.`env_id`, sp.`value` AS vcpus\n FROM servers AS s\n LEFT JOIN server_properties sp ON sp.`server_id`= s.`server_id` AND sp.`name` = ?\n WHERE s.`status` NOT IN (?, ?)\n AND s.`type` IS NOT NULL\n AND s.`platform` = ?\n ", [Server::INFO_INSTANCE_VCPUS, Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED, $platform]);
while ($row = $result->FetchRow()) {
if (!empty($row["type"]) && empty($row['vcpus'])) {
if (!array_key_exists($row["env_id"], $envs)) {
$envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]);
}
try {
$instanceTypeInfo = $platformModule->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
if ($instanceTypeInfo instanceof CloudInstanceType) {
$vcpus = $instanceTypeInfo->vcpus;
} else {
trigger_error("Value of vcpus for instance type " . $row["type"] . " is missing for platform " . $platform, E_USER_WARNING);
$vcpus = 0;
}
if ((int) $vcpus > 0) {
$this->db->Execute("\n INSERT INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n ON DUPLICATE KEY UPDATE `value` = ?\n ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $vcpus, $vcpus]);
}
} catch (\Exception $e) {
$this->console->warning("Can't get access to %s, error: %s", $platform, $e->getMessage());
}
}
}
}
示例10: getEnvironmentsList
/**
* Gets a list of environments by key
*
* @param string $query Search query
* @return array Returns array of environments
*/
private function getEnvironmentsList($query = null)
{
$envs = [];
$environments = $this->user->getEnvironments($query);
if (count($environments) > 0) {
$iterator = ChartPeriodIterator::create('month', gmdate('Y-m-01'), null, 'UTC');
//It calculates usage for all provided enviroments
$usage = $this->getContainer()->analytics->usage->getFarmData($this->user->getAccountId(), [], $iterator->getStart(), $iterator->getEnd(), [TagEntity::TAG_ID_ENVIRONMENT, TagEntity::TAG_ID_FARM]);
//It calculates usage for previous period same days
$prevusage = $this->getContainer()->analytics->usage->getFarmData($this->user->getAccountId(), [], $iterator->getPreviousStart(), $iterator->getPreviousEnd(), [TagEntity::TAG_ID_ENVIRONMENT, TagEntity::TAG_ID_FARM]);
foreach ($environments as $env) {
if (isset($usage['data'][$env['id']]['data'])) {
$envs[$env['id']]['topSpender'] = $this->getFarmTopSpender($usage['data'][$env['id']]['data']);
} else {
$envs[$env['id']]['topSpender'] = null;
}
$envs[$env['id']]['name'] = $env['name'];
$envs[$env['id']]['envId'] = $env['id'];
$ccId = \Scalr_Environment::init()->loadById($env['id'])->getPlatformConfigValue(\Scalr_Environment::SETTING_CC_ID);
if (!empty($ccId)) {
$envs[$env['id']]['ccId'] = $ccId;
$envs[$env['id']]['ccName'] = CostCentreEntity::findPk($ccId)->name;
}
$totalCost = round(isset($usage['data'][$env['id']]) ? $usage['data'][$env['id']]['cost'] : 0, 2);
$prevCost = round(isset($prevusage['data'][$env['id']]) ? $prevusage['data'][$env['id']]['cost'] : 0, 2);
$envs[$env['id']] = $this->getWrappedUsageData(['iterator' => $iterator, 'usage' => $totalCost, 'prevusage' => $prevCost]) + $envs[$env['id']];
}
}
return array_values($envs);
}
示例11: run1
/**
* Performs upgrade literally for the stage ONE.
*
* Implementation of this method performs update steps needs to be taken
* to accomplish upgrade successfully.
*
* If there are any error during an execution of this scenario it must
* throw an exception.
*
* @param int $stage optional The stage number
* @throws \Exception
*/
protected function run1($stage)
{
$environments = $this->db->Execute("SELECT id FROM client_environments WHERE status='Active'");
while ($env = $environments->FetchRow()) {
$environment = \Scalr_Environment::init()->loadById($env['id']);
foreach (PlatformFactory::getOpenstackBasedPlatforms() as $platform) {
if ($platform == \SERVER_PLATFORMS::RACKSPACENG_UK || $platform == \SERVER_PLATFORMS::RACKSPACENG_US) {
continue;
}
try {
if ($environment->isPlatformEnabled($platform)) {
$os = $environment->openstack($platform);
//It throws an exception on failure
$zones = $os->listZones();
$zone = array_shift($zones);
$os = $environment->openstack($platform, $zone->name);
// Check SG Extension
$pars[$this->getOpenStackOption($platform, 'EXT_SECURITYGROUPS_ENABLED')] = (int) $os->servers->isExtensionSupported(ServersExtension::securityGroups());
// Check Floating Ips Extension
$pars[$this->getOpenStackOption($platform, 'EXT_FLOATING_IPS_ENABLED')] = (int) $os->servers->isExtensionSupported(ServersExtension::floatingIps());
// Check Cinder Extension
$pars[$this->getOpenStackOption($platform, 'EXT_CINDER_ENABLED')] = (int) $os->hasService('volume');
// Check Swift Extension
$pars[$this->getOpenStackOption($platform, 'EXT_SWIFT_ENABLED')] = (int) $os->hasService('object-store');
// Check LBaas Extension
$pars[$this->getOpenStackOption($platform, 'EXT_LBAAS_ENABLED')] = $os->hasService('network') ? (int) $os->network->isExtensionSupported('lbaas') : 0;
$environment->setPlatformConfig($pars);
}
} catch (\Exception $e) {
$this->console->out("Update settings for env: {$env['id']} failed: " . $e->getMessage());
}
}
}
}
示例12: getAccountEnvironmentsList
public function getAccountEnvironmentsList()
{
$environments = $this->user->getEnvironments();
$result = array();
foreach ($environments as &$row) {
$env = Scalr_Environment::init()->loadById($row['id']);
$row['platforms'] = $env->getEnabledPlatforms();
$row['teams'] = array();
if ($this->getContainer()->config->get('scalr.auth_mode') == 'ldap') {
$row['teamIds'] = array();
}
foreach ($env->getTeams() as $teamId) {
if ($this->getContainer()->config->get('scalr.auth_mode') == 'ldap') {
$team = new Scalr_Account_Team();
$team->loadById($teamId);
$row['teams'][] = $team->name;
$row['teamIds'][] = $teamId;
} else {
$row['teams'][] = $teamId;
}
}
$row['dtAdded'] = Scalr_Util_DateTime::convertTz($env->dtAdded);
$row['status'] = $env->status;
if ($this->getContainer()->analytics->enabled) {
$row['ccId'] = $env->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
}
$result[] =& $row;
}
return $result;
}
示例13: run2
protected function run2($stage)
{
$this->console->out("Populating new properties");
$platforms = $envs = [];
foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) {
$platforms[$platform] = PlatformFactory::NewPlatform($platform);
}
$result = $this->db->Execute("\n SELECT s.server_id, s.`platform`, s.`cloud_location`, s.env_id, s.`type`\n FROM servers AS s\n WHERE s.`status` NOT IN (?, ?) AND s.`type` IS NOT NULL\n ", [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED]);
while ($row = $result->FetchRow()) {
if (!empty($row["type"])) {
if (!array_key_exists($row["env_id"], $envs)) {
$envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]);
}
if ($this->isPlatformEnabled($envs[$row["env_id"]], $row["platform"])) {
try {
$instanceTypeEntity = $platforms[$row["platform"]]->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
/* @var $instanceTypeEntity CloudInstanceType */
if ($instanceTypeEntity && (int) $instanceTypeEntity->vcpus > 0) {
$this->db->Execute("\n INSERT IGNORE INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $instanceTypeEntity->vcpus]);
}
} catch (\Exception $e) {
$this->console->warning("Can't get access to %s, error: %s", $row["platform"], $e->getMessage());
}
}
}
}
}
示例14: setUp
/**
* Set test names for objects
*/
protected function setUp()
{
parent::setUp();
if ($this->isSkipFunctionalTests()) {
$this->markTestSkipped();
}
$testEnvId = \Scalr::config('scalr.phpunit.envid');
try {
$this->testEnv = \Scalr_Environment::init()->loadById($testEnvId);
} catch (Exception $e) {
$this->markTestSkipped('Test Environment does not exist.');
}
if (!$this->testEnv || !$this->testEnv->isPlatformEnabled(\SERVER_PLATFORMS::AZURE)) {
$this->markTestSkipped('Azure platform is not enabled.');
}
$this->azure = $this->testEnv->azure();
$this->subscriptionId = $this->azure->getEnvironment()->cloudCredentials(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID];
$this->resourceGroupName = 'test3-resource-group-' . $this->getInstallationId();
$this->availabilitySetName = 'test3-availability-set-' . $this->getInstallationId();
$this->vmName = 'test3-virtual-machine-' . $this->getInstallationId();
$this->vnName = 'test3-virtual-network-' . $this->getInstallationId();
$this->nicName = 'test3-network-interface' . $this->getInstallationId();
$this->publicIpName = 'myPublicIP3';
$this->storageName = 'teststorage3' . $this->getInstallationId();
$this->sgName = 'test3-security-group' . $this->getInstallationId();
}
示例15: getLocations
/**
* Gets the list of available locations
*
* @return array Returns the list of available locations looks like array(location => description)
*/
public function getLocations(\Scalr_Environment $environment = null)
{
$retval = array(Aws::REGION_US_EAST_1 => 'us-east-1 (N. Virginia)', Aws::REGION_US_WEST_1 => 'us-west-1 (N. California)', Aws::REGION_US_WEST_2 => 'us-west-2 (Oregon)', Aws::REGION_EU_WEST_1 => 'eu-west-1 (Ireland)', Aws::REGION_EU_CENTRAL_1 => 'eu-central-1 (Frankfurt)', Aws::REGION_SA_EAST_1 => 'sa-east-1 (Sao Paulo)', Aws::REGION_AP_SOUTHEAST_1 => 'ap-southeast-1 (Singapore)', Aws::REGION_AP_SOUTHEAST_2 => 'ap-southeast-2 (Sydney)', Aws::REGION_AP_NORTHEAST_1 => 'ap-northeast-1 (Tokyo)');
if ($environment instanceof \Scalr_Environment && $this instanceof Ec2PlatformModule) {
if ($environment->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_TYPE) == Ec2PlatformModule::ACCOUNT_TYPE_GOV_CLOUD) {
return [Aws::REGION_US_GOV_WEST_1 => 'us-gov-west-1 (GovCloud US)'];
}
if ($environment->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_TYPE) == Ec2PlatformModule::ACCOUNT_TYPE_CN_CLOUD) {
return [Aws::REGION_CN_NORTH_1 => 'cn-north-1 (China)'];
}
} else {
// For admin (when no environment defined) we need to show govcloud and chinacloud locations to be able to manage images.
$retval = array_merge($retval, [Aws::REGION_CN_NORTH_1 => 'cn-north-1 (China)', Aws::REGION_US_GOV_WEST_1 => 'us-gov-west-1 (GovCloud US)']);
}
return $retval;
}