本文整理汇总了PHP中Scalr类的典型用法代码示例。如果您正苦于以下问题:PHP Scalr类的具体用法?PHP Scalr怎么用?PHP Scalr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scalr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xRequestResultAction
public function xRequestResultAction()
{
$this->request->defineParams(array('requests' => array('type' => 'json'), 'decision'));
if (!in_array($this->getParam('decision'), array(FarmLease::STATUS_APPROVE, FarmLease::STATUS_DECLINE))) {
throw new Scalr_Exception_Core('Wrong status');
}
foreach ($this->getParam('requests') as $id) {
$req = $this->db->GetRow('SELECT * FROM farm_lease_requests WHERE id = ? LIMIT 1', array($id));
if ($req) {
$dbFarm = DBFarm::LoadByID($req['farm_id']);
$this->user->getPermissions()->validate($dbFarm);
$this->db->Execute('UPDATE farm_lease_requests SET status = ?, answer_comment = ?, answer_user_id = ? WHERE id = ?', array($this->getParam('decision'), $this->getParam('comment'), $this->user->getId(), $id));
try {
$mailer = Scalr::getContainer()->mailer;
if ($dbFarm->ownerId) {
$user = Entity\Account\User::findPk($dbFarm->ownerId);
if (\Scalr::config('scalr.auth_mode') == 'ldap') {
$email = $user->getSetting(Entity\Account\User\UserSetting::NAME_LDAP_EMAIL);
if (!$email) {
$email = $user->email;
}
} else {
$email = $user->email;
}
$mailer->addTo($email);
} else {
$mailer = null;
}
} catch (Exception $e) {
$mailer = null;
}
if ($this->getParam('decision') == FarmLease::STATUS_APPROVE) {
if ($req['request_days'] > 0) {
$dt = $dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE);
$dt = new DateTime($dt);
$dt->add(new DateInterval('P' . $req['request_days'] . 'D'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, null);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_approve.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{date}}' => $dt->format('M j, Y'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
} else {
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_STATUS, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, '');
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_forever.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
} else {
$dt = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
SettingEntity::increase(SettingEntity::LEASE_DECLINED_REQUEST);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_decline.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{date}}' => $dt->format('M j, Y'), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
}
}
$this->response->success();
}
示例2: getCrypto
/**
* @return CryptoTool
*/
protected function getCrypto()
{
if (!$this->crypto) {
$this->crypto = \Scalr::getContainer()->crypto;
}
return $this->crypto;
}
示例3: __construct
public function __construct(Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo $authInfo, $host, $port, $rndcPath, $zonesPath)
{
$this->ssh2Client = new Scalr_Net_Ssh2_Client();
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
$this->rndcPath = $rndcPath;
$this->zonesPath = $zonesPath;
$this->host = $host;
switch ($authInfo->getType()) {
case Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo::TYPE_PASSWORD:
$this->ssh2Client->addPassword($authInfo->login, $authInfo->password);
break;
case Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo::TYPE_PUBKEY:
$this->ssh2Client->addPubkey($authInfo->login, $authInfo->pubKeyPath, $authInfo->privKeyPath, $authInfo->keyPassword);
break;
}
try {
$this->ssh2Client->connect($host, $port);
} catch (Scalr_Net_Ssh2_Exception $e) {
throw new Exception("Unable to initialize SSH2 Transport: {$e->getMessage()}");
}
// COunt initial number of zones
$this->zonesCount = $this->rndcStatus();
if (!$this->zonesCount) {
throw new Exception(sprintf(_("Cannot fetch RNDC status on %s"), $host));
}
}
示例4: setupScalrAgent
public static function setupScalrAgent(\DBServer $dbServer)
{
$baseurl = \Scalr::config('scalr.endpoint.scheme') . "://" . \Scalr::config('scalr.endpoint.host');
$env = $dbServer->GetEnvironmentObject();
$azure = $env->azure();
$branch = $dbServer->getScalarizrRepository()['repository'];
$develRepos = \Scalr::getContainer()->config->get('scalr.scalarizr_update.devel_repos');
$scmBranch = $dbServer->GetFarmRoleObject()->GetSetting('user-data.scm_branch');
if ($scmBranch != '' && $develRepos) {
$branch = $dbServer->GetFarmRoleObject()->GetSetting('base.devel_repository');
$scmBranch = "{$scmBranch}/";
} else {
$scmBranch = '';
}
if ($dbServer->osType == 'linux') {
$extensionProperties = new ResourceExtensionProperties('Microsoft.OSTCExtensions', 'CustomScriptForLinux', '1.2');
$extensionProperties->setSettings(['commandToExecute' => "bash -c 'curl -k -L \"{$baseurl}/public/linux/{$branch}/azure/{$scmBranch}install_scalarizr.sh\" | bash && service scalr-upd-client start'"]);
} else {
$extensionProperties = new ResourceExtensionProperties('Microsoft.Compute', 'CustomScriptExtension', '1.4');
$extensionProperties->setSettings(["commandToExecute" => "powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('{$baseurl}/public/windows/{$branch}/{$scmBranch}install_scalarizr.ps1')); start-service ScalrUpdClient\""]);
}
$createExtension = new CreateResourceExtension('scalarizr', $dbServer->cloudLocation, $extensionProperties);
try {
$response = $azure->compute->resourceExtension->create($env->keychain(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::RESOURCE_GROUP), $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::SERVER_NAME), $createExtension);
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new \FarmLogMessage($dbServer, sprintf(_("Created azure resource extension to install and launch scalr agent"))));
$dbServer->SetProperty(\AZURE_SERVER_PROPERTIES::SZR_EXTENSION_DEPLOYED, 1);
} catch (\Exception $e) {
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->fatal(new \FarmLogMessage($dbServer, sprintf(_("Unable to create azure resource extension to install and launch scalr agent: %s"), $e->getMessage())));
}
}
示例5: tearDownAfterClass
/**
* {@inheritdoc}
* @see Scalr\Tests\TestCase::tearDownAfterClass()
*/
public static function tearDownAfterClass()
{
foreach (static::$testData as $rec) {
if ($rec['class'] === Farm::class) {
$entry = $rec['pk'];
$farm = Farm::findPk(...$entry);
/* @var $farm Farm */
if (!empty($farm)) {
try {
\Scalr::FireEvent($farm->id, new FarmTerminatedEvent(false, false, false, false, true, static::$user->id));
foreach ($farm->servers as $server) {
try {
$dbServer = Server::findPk($server->serverId);
/* @var $dbServer Server */
$dbServer->terminate(Server::TERMINATE_REASON_FARM_TERMINATED, true, static::$user);
} catch (Exception $e) {
\Scalr::logException($e);
}
$server->delete();
}
} catch (Exception $e) {
\Scalr::logException($e);
}
}
}
}
parent::tearDownAfterClass();
}
示例6: startChild
function startChild()
{
// Reopen DB connection in child
$this->db = Core::GetDBInstance(null, true);
// Reconfigure observers;
Scalr::ReconfigureObservers();
}
示例7: __construct
function __construct()
{
$this->cryptoTool = \Scalr::getContainer()->srzcrypto;
$this->serializer = new Scalr_Messaging_XmlSerializer();
$this->jsonSerializer = new Scalr_Messaging_JsonSerializer();
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
}
示例8: __construct
function __construct($nodeName, $jobConfig)
{
parent::__construct($nodeName, $jobConfig);
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
if (!key_exists("datacenter", $jobConfig)) {
throw new Scalr_System_Cronjob_Exception("Configuration array must have a key for 'datacenter'");
}
$dcConfig = $jobConfig["datacenter"];
if (!$dcConfig["centers"]) {
throw new Scalr_System_Cronjob_Exception("No datacenters defined in configuration");
}
if (!$dcConfig["leader"]) {
throw new Scalr_System_Cronjob_Exception("Configuration array must have a key for 'datacenter'.'leader' " . "that names the leader datacenter");
}
$centers = array_map("trim", explode(",", $dcConfig["centers"]));
$nodeCenterMap = array();
foreach ($centers as $center) {
$nodes = array_map("trim", explode(",", $dcConfig[$center]));
foreach ($nodes as $node) {
$nodeCenterMap[$node] = $center;
}
}
$this->dataCenter = key_exists($this->nodeName, $nodeCenterMap) ? $nodeCenterMap[$this->nodeName] : $dcConfig["default"];
$this->leaderDataCenter = $dcConfig["leader"];
}
示例9: run1
protected function run1($stage)
{
$this->console->out(sprintf("Reencrypting %s database from %s/%s to %s/%s!", \Scalr::getContainer()->config->get('scalr.connections.mysql.name'), $this->source->getCryptoAlgo(), $this->source->getCipherMode(), $this->target->getCryptoAlgo(), $this->target->getCipherMode()));
set_error_handler(function ($code, $message, $file, $line, $context) {
\Scalr::errorHandler($code, $message, $file, $line, $context);
if ($code == E_STRICT) {
throw new Exception($message);
}
}, E_USER_ERROR | E_STRICT | E_RECOVERABLE_ERROR | E_ERROR);
try {
$this->db->Execute('START TRANSACTION;');
$this->recrypt('ssh_keys', ['private_key', 'public_key']);
$this->recrypt('services_ssl_certs', ['ssl_pkey', 'ssl_pkey_password']);
$this->recrypt('account_user_settings', ['value'], "WHERE `name` = 'security.2fa.ggl.key'", ['user_id', 'name']);
$this->recrypt('services_chef_servers', ['auth_key', 'v_auth_key']);
$this->recrypt('variables', ['value'], '', ['name'], $this->globals);
$this->recrypt('account_variables', ['value'], '', ['name', 'account_id'], $this->globals);
$this->recrypt('client_environment_variables', ['value'], '', ['name', 'env_id'], $this->globals);
$this->recrypt('role_variables', ['value'], '', ['name', 'role_id'], $this->globals);
$this->recrypt('farm_variables', ['value'], '', ['name', 'farm_id'], $this->globals);
$this->recrypt('farm_role_variables', ['value'], '', ['name', 'farm_role_id'], $this->globals);
$this->recrypt('server_variables', ['value'], '', ['name', 'server_id'], $this->globals);
$reflection = new ReflectionClass('Scalr_Environment');
$method = $reflection->getMethod('getEncryptedVariables');
$method->setAccessible(true);
$this->recrypt('client_environment_properties', ['value'], "WHERE `name` IN ('" . implode("','", array_keys($method->invoke(null))) . "')");
$this->db->Execute("COMMIT;");
} catch (\Exception $e) {
$this->rollback($e->getCode(), $e->getMessage());
restore_error_handler();
throw $e;
}
restore_error_handler();
}
示例10: __call
public function __call($method, $args)
{
// If observer enabled
if (!$this->Config || $this->Config->GetFieldByName("IsEnabled")->Value == 0) {
return;
}
$enabled = $this->Config->GetFieldByName("{$method}Notify");
if (!$enabled || $enabled->Value == 0) {
return;
}
$DB = \Scalr::getDb();
// Event name
$name = substr($method, 2);
// Event message
$message = $DB->GetOne("SELECT message FROM events WHERE event_id = ? LIMIT 1", array($args[0]->GetEventID()));
$farm_name = $DB->GetOne("SELECT name FROM farms WHERE id=? LIMIT 1", array($args[0]->GetFarmID()));
// Set subject
if (!$farm_name) {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()})");
} else {
$this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()} FarmName: {$farm_name})");
}
// Set body
$this->Mailer->setMessage($message);
// Send mail
try {
$res = $this->Mailer->send();
} catch (\Exception $e) {
$res = false;
}
if (!$res) {
Logger::getLogger(__CLASS__)->info("Mail sent to '{$this->Config->GetFieldByName("EventMailTo")->Value}'. Result: {$res}");
}
}
示例11: __construct
/**
* Constructor
*/
function __construct()
{
$this->Logger = \Scalr::getContainer()->logger('SignalHandler');
if (!function_exists("pcntl_signal")) {
throw new \Exception("Function pcntl_signal() is not found. PCNTL must be enabled in PHP.", E_ERROR);
}
}
示例12: OnBeforeInstanceLaunch
/**
* {@inheritdoc}
* @see \Scalr\Observer\AbstractEventObserver::OnBeforeInstanceLaunch()
*/
public function OnBeforeInstanceLaunch(\BeforeInstanceLaunchEvent $event)
{
if ($event->DBServer->platform != \SERVER_PLATFORMS::EC2) {
return;
}
$DBFarm = $event->DBServer->GetFarmObject();
$DBFarmRole = $event->DBServer->GetFarmRoleObject();
// Create EBS volume for MySQLEBS
if (!$event->DBServer->IsSupported("0.6")) {
// Only for old AMIs
if ($DBFarmRole->GetRoleObject()->hasBehavior(\ROLE_BEHAVIORS::MYSQL) && $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_DATA_STORAGE_ENGINE) == \MYSQL_STORAGE_ENGINE::EBS) {
$server = $event->DBServer;
$masterServer = $DBFarm->GetMySQLInstances(true);
$isMaster = !$masterServer || $masterServer[0]->serverId == $server->serverId;
$farmMasterVolId = $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_MASTER_EBS_VOLUME_ID);
$createEbs = $isMaster && !$farmMasterVolId;
if ($createEbs) {
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new FarmLogMessage($event->DBServer, sprintf("Need EBS volume for MySQL %s instance...", $isMaster ? "Master" : "Slave")));
$req = new CreateVolumeRequestData($event->DBServer->GetProperty(\EC2_SERVER_PROPERTIES::AVAIL_ZONE), $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_EBS_VOLUME_SIZE));
$aws = $event->DBServer->GetEnvironmentObject()->aws($DBFarmRole->CloudLocation);
$res = $aws->ec2->volume->create($req);
if (!empty($res->volumeId)) {
$DBFarmRole->SetSetting(Entity\FarmRoleSetting::MYSQL_MASTER_EBS_VOLUME_ID, $res->volumeId, Entity\FarmRoleSetting::TYPE_LCL);
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new FarmLogMessage($event->DBServer, sprintf("MySQL %S volume created. Volume ID: %s...", $isMaster ? "Master" : "Slave", !empty($res->volumeId) ? $res->volumeId : null)));
}
}
}
}
}
示例13: run
public function run()
{
$container = \Scalr::getContainer();
$db = $container->adodb;
$row = $db->GetRow("SHOW TABLES LIKE 'upgrades'");
if ($row) {
print "Tables already exist. Terminating.\n";
exit;
}
$script = <<<EOL
CREATE TABLE `upgrades` (
`uuid` VARBINARY(16) NOT NULL COMMENT 'Unique identifier of update',
`released` DATETIME NOT NULL COMMENT 'The time when upgrade script is issued',
`appears` DATETIME NOT NULL COMMENT 'The time when upgrade does appear',
`applied` DATETIME DEFAULT NULL COMMENT 'The time when update is successfully applied',
`status` TINYINT NOT NULL COMMENT 'Upgrade status',
`hash` VARBINARY (20) COMMENT 'SHA1 hash of the upgrade file',
PRIMARY KEY (`uuid`),
INDEX `idx_status` (`status`),
INDEX `idx_appears` (`appears`)
) ENGINE = InnoDB;
CREATE TABLE `upgrade_messages` (
`uuid` VARBINARY(16) NOT NULL COMMENT 'upgrades.uuid reference',
`created` DATETIME NOT NULL COMMENT 'Creation timestamp',
`message` TEXT COMMENT 'Error messages',
INDEX idx_uuid (`uuid`),
CONSTRAINT `upgrade_messages_ibfk_1` FOREIGN KEY (`uuid`) REFERENCES `upgrades` (`uuid`) ON DELETE CASCADE
) ENGINE = InnoDB;
EOL;
$lines = array_filter(preg_split('/;[\\s\\r\\n]*/m', $script));
foreach ($lines as $stmt) {
$db->Execute($stmt);
}
}
示例14: setUserRoles
/**
* Saves all relations between all users of this team and ACL roles
*
* @param array $data Roles array should look like array(user_id => array(account_role_id, ...))
* @throws \Scalr\Acl\Exception\AclException
*/
public function setUserRoles(array $data = array())
{
if (empty($this->id)) {
throw new \Scalr\Acl\Exception\AclException(sprintf("ID of the team is expected. It hasn't been initialized yet."));
}
\Scalr::getContainer()->acl->setAllRolesForTeam($this->id, $data, $this->accountId);
}
示例15: setUp
/**
* {@inheritdoc}
* @see \Scalr\Tests\TestCase::setUp()
*/
protected function setUp()
{
parent::setUp();
if (!\Scalr::getContainer()->analytics->enabled) {
$this->markTestSkipped("Cost analytics has not been enabled in the configuration.");
}
}