• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Scalr_Environment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Scalr_Environment的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Environment类的具体用法?PHP Scalr_Environment怎么用?PHP Scalr_Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Scalr_Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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];
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:25,代码来源:Ec2.php


示例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);
 }
开发者ID:scalr,项目名称:scalr,代码行数:14,代码来源:AbstractAwsPlatformModule.php


示例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);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:18,代码来源:AbstractPlatformModule.php


示例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)');
 }
开发者ID:rickb838,项目名称:scalr,代码行数:14,代码来源:AbstractAwsPlatformModule.php


示例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;
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:14,代码来源:OpenStackTestCase.php


示例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;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:15,代码来源:NimbulaPlatformModule.php


示例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']);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:52,代码来源:EnvironmentTest.php


示例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;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:19,代码来源:UCloudPlatformModule.php


示例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());
             }
         }
     }
 }
开发者ID:scalr,项目名称:scalr,代码行数:29,代码来源:Update20160401132637.php


示例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);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:36,代码来源:Environments.php


示例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());
             }
         }
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:46,代码来源:Update20140211014306.php


示例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;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:30,代码来源:Account2.php


示例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());
                 }
             }
         }
     }
 }
开发者ID:solderzzc,项目名称:scalr,代码行数:27,代码来源:Update20150818090745.php


示例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();
 }
开发者ID:mheydt,项目名称:scalr,代码行数:29,代码来源:AzureTest.php


示例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;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:21,代码来源:AbstractAwsPlatformModule.php


示例16: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     if (self::isSkippedFunctionalTest(self::TEST_TYPE_UI)) {
         return;
     }
     $db = \Scalr::getDb();
     self::deleteTestVariables();
     $envId = \Scalr::config('scalr.phpunit.envid');
     if (!$envId) {
         return;
     }
     $env = \Scalr_Environment::init()->loadById($envId);
     self::$vars[ScopeInterface::SCOPE_SCALR] = new Scalr_Scripting_GlobalVariables();
     self::$vars[ScopeInterface::SCOPE_ACCOUNT] = new Scalr_Scripting_GlobalVariables($env->clientId, 0, ScopeInterface::SCOPE_ACCOUNT);
     self::$vars[ScopeInterface::SCOPE_ENVIRONMENT] = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, ScopeInterface::SCOPE_ENVIRONMENT);
     self::$args[ScopeInterface::SCOPE_SCALR] = self::$args[ScopeInterface::SCOPE_ACCOUNT] = self::$args[ScopeInterface::SCOPE_ENVIRONMENT] = [0, 0, 0, ''];
     /* @var $farm Farm */
     $farm = Farm::findOne([['envId' => $env->id]]);
     if ($farm) {
         self::$vars[ScopeInterface::SCOPE_FARM] = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, ScopeInterface::SCOPE_FARM);
         self::$args[ScopeInterface::SCOPE_FARM] = [0, $farm->id, 0, ''];
         /* @var $farmRole FarmRole */
         $farmRole = FarmRole::findOne([['farmId' => $farm->id]]);
         if ($farmRole) {
             self::$vars[ScopeInterface::SCOPE_ROLE] = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, ScopeInterface::SCOPE_ROLE);
             self::$args[ScopeInterface::SCOPE_ROLE] = [$farmRole->roleId, 0, 0, ''];
             self::$vars[ScopeInterface::SCOPE_FARMROLE] = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, ScopeInterface::SCOPE_FARMROLE);
             self::$args[ScopeInterface::SCOPE_FARMROLE] = [$farmRole->roleId, $farm->id, $farmRole->id, ''];
         }
     }
 }
开发者ID:scalr,项目名称:scalr,代码行数:32,代码来源:GlobalVariablesTest.php


示例17: run2

 protected function run2($stage)
 {
     $farms = $this->db->Execute("SELECT farmid, value FROM farm_settings WHERE name='ec2.vpc.id' AND value != '' AND value IS NOT NULL");
     while ($farm = $farms->FetchRow()) {
         $dbFarm = \DBFarm::LoadByID($farm['farmid']);
         $roles = $dbFarm->GetFarmRoles();
         foreach ($roles as $dbFarmRole) {
             $vpcSubnetId = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_VPC_SUBNET_ID);
             if ($vpcSubnetId && substr($vpcSubnetId, 0, 6) != 'subnet') {
                 $subnets = json_decode($vpcSubnetId);
                 $vpcSubnetId = $subnets[0];
             }
             if ($vpcSubnetId) {
                 try {
                     $platform = PlatformFactory::NewPlatform(\SERVER_PLATFORMS::EC2);
                     $info = $platform->listSubnets(\Scalr_Environment::init()->loadById($dbFarm->EnvID), $dbFarmRole->CloudLocation, $farm['value'], true, $vpcSubnetId);
                     if ($info && $info['type'] != 'public') {
                         $routerRole = $dbFarm->GetFarmRoleByBehavior(\ROLE_BEHAVIORS::VPC_ROUTER);
                         $dbFarmRole->SetSetting(\Scalr_Role_Behavior_Router::ROLE_VPC_SCALR_ROUTER_ID, $routerRole->ID);
                         $this->console->out("Updating router.scalr.farm_role_id property for Farm Role: %s", $dbFarmRole->ID);
                     }
                 } catch (\Exception $e) {
                     continue;
                 }
             }
         }
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:28,代码来源:Update20140612235154.php


示例18: init

 public function init()
 {
     $this->env = Scalr_Environment::init()->loadById($this->getParam(Scalr_UI_Controller_Environments::CALL_PARAM_NAME));
     $this->user->getPermissions()->validate($this->env);
     if (!($this->user->getType() == Scalr_Account_User::TYPE_ACCOUNT_OWNER || $this->user->isTeamUserInEnvironment($this->env->id, Scalr_Account_Team::PERMISSIONS_OWNER))) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:8,代码来源:Platform.php


示例19: run1

 protected function run1($stage)
 {
     $envIds = $this->db->Execute("SELECT `id` FROM `client_environments`");
     $platformVariables = static::getCloudsCredentialProperties();
     foreach ($envIds as $row) {
         $environment = \Scalr_Environment::init()->loadById($row['id']);
         $platforms = [];
         foreach (array_keys(SERVER_PLATFORMS::getList()) as $platform) {
             if ($environment->getPlatformConfigValue($platform . '.is_enabled', false)) {
                 $platforms[] = $platform;
             }
         }
         foreach ($platforms as $platform) {
             try {
                 switch ($platform) {
                     case SERVER_PLATFORMS::RACKSPACE:
                         foreach (['rs-ORD1', 'rs-LONx'] as $location) {
                             $cloudCredentials = new Entity\CloudCredentials();
                             $cloudCredentials->accountId = $environment->getAccountId();
                             $cloudCredentials->envId = $environment->id;
                             $cloudCredentials->cloud = "{$location}.{$platform}";
                             $cloudCredentials->name = "{$environment->id}-{$environment->getAccountId()}-{$cloudCredentials->cloud}-" . \Scalr::GenerateUID(true);
                             foreach ($platformVariables[$platform] as $name => $newName) {
                                 $value = $environment->getPlatformConfigValue($name, true, $location);
                                 if ($value === null) {
                                     $value = false;
                                 }
                                 $cloudCredentials->properties[$newName] = $value;
                             }
                             $cloudCredentials->save();
                             $cloudCredentials->bindToEnvironment($environment);
                         }
                         break;
                     default:
                         $cloudCredentials = new Entity\CloudCredentials();
                         $cloudCredentials->accountId = $environment->getAccountId();
                         $cloudCredentials->envId = $environment->id;
                         $cloudCredentials->cloud = $platform;
                         $cloudCredentials->name = "{$environment->id}-{$environment->getAccountId()}-{$platform}-" . \Scalr::GenerateUID(true);
                         $cloudCredentials->status = Entity\CloudCredentials::STATUS_ENABLED;
                         foreach ($platformVariables[$platform] as $name => $newName) {
                             $value = $environment->getPlatformConfigValue($name);
                             if ($value === null) {
                                 $value = false;
                             }
                             $cloudCredentials->properties[$newName] = $value;
                         }
                         $cloudCredentials->save();
                         $cloudCredentials->bindToEnvironment($environment);
                         break;
                 }
             } catch (Exception $e) {
                 $this->console->error(get_class($e) . " in {$e->getFile()} on line {$e->getLine()}: " . $e->getMessage());
                 error_log(get_class($e) . " in {$e->getFile()} at line {$e->getLine()}: {$e->getMessage()}\n{$e->getTraceAsString()}");
             }
         }
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:58,代码来源:Update20151009141048.php


示例20: OnStartForking

 /**
  * Auto-snapshoting
  * {@inheritdoc}
  * @see \Scalr\System\Pcntl\ProcessInterface::OnStartForking()
  */
 public function OnStartForking()
 {
     $db = \Scalr::getDb();
     // selects rows where the snapshot's time has come to create new snapshot.
     $resultset = $db->Execute("\n            SELECT * FROM autosnap_settings\n            WHERE (`dtlastsnapshot` < NOW() - INTERVAL `period` HOUR OR `dtlastsnapshot` IS NULL)\n            AND objectid != '0'\n            AND object_type = ?\n        ", array(AUTOSNAPSHOT_TYPE::RDSSnap));
     while ($snapshotsSettings = $resultset->FetchRow()) {
         try {
             $environment = Scalr_Environment::init()->loadById($snapshotsSettings['env_id']);
             $aws = $environment->aws($snapshotsSettings['region']);
             // Check instance. If instance wasn't found then delete current recrod from settings table
             try {
                 $aws->rds->dbInstance->describe($snapshotsSettings['objectid']);
             } catch (Exception $e) {
                 if (stristr($e->getMessage(), "not found") || stristr($e->getMessage(), "not a valid") || stristr($e->getMessage(), "security token included in the request is invalid")) {
                     $db->Execute("\n                            DELETE FROM autosnap_settings WHERE id = ?\n                        ", array($snapshotsSettings['id']));
                 }
                 $this->Logger->error(sprintf(_("RDS instance %s was not found. " . "Auto-snapshot settings for this instance will be deleted. %s."), $snapshotsSettings['objectid'], $e->getMessage()));
                 throw $e;
             }
             // snapshot random unique name
             $snapshotId = "scalr-auto-" . dechex(microtime(true) * 10000) . rand(0, 9);
             try {
                 // Create new snapshot
                 $aws->rds->dbSnapshot->create($snapshotsSettings['objectid'], $snapshotId);
                 // update last snapshot creation date in settings
                 $db->Execute("\n                        UPDATE autosnap_settings\n                        SET last_snapshotid=?, dtlastsnapshot=NOW() WHERE id=?\n                    ", array($snapshotId, $snapshotsSettings['id']));
                 // create new snapshot record in DB
                 $db->Execute("\n                        INSERT INTO rds_snaps_info\n                        SET snapid = ?,\n                            comment = ?,\n                            dtcreated = NOW(),\n                            region = ?,\n                            autosnapshotid = ?\n                    ", array($snapshotId, _("Auto snapshot"), $snapshotsSettings['region'], $snapshotsSettings['id']));
             } catch (Exception $e) {
                 $this->Logger->warn(sprintf(_("Could not create RDS snapshot: %s."), $e->getMessage()));
             }
             // Remove old snapshots
             if ($snapshotsSettings['rotate'] != 0) {
                 $oldSnapshots = $db->GetAll("\n                        SELECT * FROM rds_snaps_info\n                        WHERE autosnapshotid = ?\n                        ORDER BY id ASC\n                    ", array($snapshotsSettings['id']));
                 if (count($oldSnapshots) > $snapshotsSettings['rotate']) {
                     while (count($oldSnapshots) > $snapshotsSettings['rotate']) {
                         // takes the oldest snapshot ...
                         $deletingSnapshot = array_shift($oldSnapshots);
                         try {
                             // and deletes it from amazon and from DB
                             $aws->rds->dbSnapshot->delete($deletingSnapshot['snapid']);
                             $db->Execute("\n                                    DELETE FROM rds_snaps_info WHERE id = ?\n                                ", array($deletingSnapshot['id']));
                         } catch (Exception $e) {
                             if (stristr($e->getMessage(), "not found") || stristr($e->getMessage(), "not a valid")) {
                                 $db->Execute("\n                                        DELETE FROM rds_snaps_info WHERE id = ?\n                                    ", array($deletingSnapshot['id']));
                             }
                             $this->Logger->error(sprintf(_("DBsnapshot %s for RDS instance %s was not found and cannot be deleted . %s."), $deletingSnapshot['snapid'], $snapshotsSettings['objectid'], $e->getMessage()));
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $this->Logger->warn(sprintf(_("Cannot create snapshot for RDS Instance %s. %s"), $snapshotsSettings['objectid'], $e->getMessage()));
         }
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:61,代码来源:class.RDSMaintenanceProcess.php



注:本文中的Scalr_Environment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Scalr_Model类代码示例发布时间:2022-05-23
下一篇:
PHP Scalr_Account_User类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap