本文整理汇总了PHP中Scalr_Model::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Model::init方法的具体用法?PHP Scalr_Model::init怎么用?PHP Scalr_Model::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Model
的用法示例。
在下文中一共展示了Scalr_Model::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSource
/**
* @return Scalr_Dm_Source
*/
public function getSource()
{
if (!$this->source) {
$this->source = Scalr_Model::init(Scalr_Model::DM_SOURCE)->loadById($this->sourceId);
}
return $this->source;
}
示例2: getEnvironmentObject
/**
* @return Scalr_Environment
*/
public function getEnvironmentObject()
{
if (!$this->environment) {
$this->environment = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($this->envId);
}
return $this->environment;
}
示例3: farmSave
public static function farmSave(DBFarm $DBFarm, array $roles)
{
foreach ($roles as $DBFarmRole) {
if ($DBFarmRole->Platform != SERVER_PLATFORMS::EUCALYPTUS) {
continue;
}
$location = $DBFarmRole->CloudLocation;
$sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
$key_name = "FARM-{$DBFarm->ID}";
$eucaClient = Scalr_Service_Cloud_Eucalyptus::newCloud($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::SECRET_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::ACCESS_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::EC2_URL, true, $location));
$result = $eucaClient->CreateKeyPair($key_name);
if ($result->keyMaterial) {
$sshKey->farmId = $DBFarm->ID;
$sshKey->clientId = $DBFarm->ClientID;
$sshKey->envId = $DBFarm->EnvID;
$sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = $location;
$sshKey->cloudKeyName = $key_name;
$sshKey->platform = SERVER_PLATFORMS::EUCALYPTUS;
$sshKey->setPrivate($result->keyMaterial);
$sshKey->save();
}
}
}
}
示例4: getApplication
public function getApplication()
{
if (!$this->application) {
$this->application = Scalr_Model::init(Scalr_Model::DM_APPLICATION)->loadById($this->applicationId);
}
return $this->application;
}
示例5: farmSave
public static function farmSave(\DBFarm $DBFarm, array $roles)
{
foreach ($roles as $DBFarmRole) {
if ($DBFarmRole->Platform != \SERVER_PLATFORMS::EC2) {
continue;
}
$location = $DBFarmRole->CloudLocation;
$sshKey = \Scalr_Model::init(\Scalr_Model::SSH_KEY);
if (!$sshKey->loadGlobalByFarmId($DBFarm->EnvID, $DBFarm->ID, $location, \SERVER_PLATFORMS::EC2)) {
$key_name = "FARM-" . $DBFarm->ID . "-" . SCALR_ID;
$aws = $DBFarm->GetEnvironmentObject()->aws($location);
$result = $aws->ec2->keyPair->create($key_name);
if (!empty($result->keyMaterial)) {
$sshKey->farmId = $DBFarm->ID;
$sshKey->envId = $DBFarm->EnvID;
$sshKey->type = \Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = $location;
$sshKey->cloudKeyName = $key_name;
$sshKey->platform = \SERVER_PLATFORMS::EC2;
$sshKey->setPrivate($result->keyMaterial);
$sshKey->save();
}
}
}
}
示例6: onCreateDataBundleResult
public static function onCreateDataBundleResult(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
$dbFarm = $dbServer->GetFarmObject();
$dbFarmRole = $dbServer->GetFarmRoleObject();
$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_LAST_TS, time());
$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0);
//$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_SERVER_ID, "");
$dbSettings = $message->{$message->dbType};
if ($dbSettings->snapshotConfig) {
try {
$snapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
$snapshot->loadBy(array('id' => $dbSettings->snapshotConfig->id, 'client_id' => $dbServer->clientId, 'env_id' => $dbServer->envId, 'name' => "Automatical '{$message->dbType}' data bundle", 'type' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'description' => "'{$message->dbType}' data bundle created automatically by Scalr", 'service' => $message->dbType));
$snapshot->setConfig($dbSettings->snapshotConfig);
$snapshot->save(true);
$dbFarmRole->SetSetting(Scalr_Db_Msr::SNAPSHOT_ID, $snapshot->id);
if ($message->dbType == self::DB_TYPE_MYSQL) {
$dbFarmRole->SetSetting(Scalr_Db_Msr_Mysql::LOG_FILE, $dbSettings->logFile);
$dbFarmRole->SetSetting(Scalr_Db_Msr_Mysql::LOG_POS, $dbSettings->logPos);
} elseif ($message->dbType == self::DB_TYPE_POSTGRESQL) {
$dbFarmRole->SetSetting(Scalr_Db_Msr_Postgresql::XLOG_LOCATION, $dbSettings->currentXlogLocation);
} elseif ($message->dbType == self::DB_TYPE_REDIS) {
//Nothing todo
}
} catch (Exception $e) {
Logger::getLogger(__CLASS__)->error(new FarmLogMessage($dbServer->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
}
}
}
示例7: OnStartForking
public function OnStartForking()
{
$db = Core::GetDBInstance(null, true);
// selects rows where the snapshot's time has come to create new snapshot.
$resultset = $db->Execute("SELECT * FROM autosnap_settings \r\n\t\t\t\t\t\tWHERE (UNIX_TIMESTAMP(DATE_ADD(dtlastsnapshot, INTERVAL period HOUR)) < UNIX_TIMESTAMP(NOW())\r\n\t\t\t\t\t\tOR dtlastsnapshot IS NULL)\r\n\t\t\t\t\t\tAND objectid \t!= '0' \r\n\t\t\t\t\t\tAND object_type = ?", array(AUTOSNAPSHOT_TYPE::RDSSnap));
while ($snapshotsSettings = $resultset->FetchRow()) {
try {
$environment = Scalr_Model::init(Scalr_Model::ENVIRONMENT)->loadById($snapshotsSettings['env_id']);
$AmazonRDSClient = Scalr_Service_Cloud_Aws::newRds($environment->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $environment->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $snapshotsSettings['region']);
// Check instance. If instance wasn't found then delete current recrod from settings table
try {
$AmazonRDSClient->DescribeDBInstances($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("DELETE FROM autosnap_settings WHERE id = ?", array($snapshotsSettings['id']));
}
$this->Logger->error(sprintf(_("RDS instance %s was not found. Auto-snapshot settings for this \r\n\t\t\t\t\t\t\t\tinstance 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
$AmazonRDSClient->CreateDBSnapshot($snapshotId, $snapshotsSettings['objectid']);
// update last snapshot creation date in settings
$db->Execute("UPDATE autosnap_settings SET last_snapshotid=?, dtlastsnapshot=NOW() WHERE id=?", array($snapshotId, $snapshotsSettings['id']));
// create new snapshot record in DB
$db->Execute("INSERT INTO rds_snaps_info SET \r\n\t\t\t\t\t\t\tsnapid\t\t= ?,\r\n\t\t\t\t\t\t\tcomment\t\t= ?,\r\n\t\t\t\t\t\t\tdtcreated\t= NOW(),\r\n\t\t\t\t\t\t\tregion\t\t= ?,\r\n\t\t\t\t\t\t\tautosnapshotid = ?", array($snapshotId, _("Auto snapshot"), $snapshotsSettings['region'], $snapshotsSettings['id']));
} catch (Exception $e) {
$this->Logger->warn(sprintf(_("Cannot create RDS snapshot: %s."), $e->getMessage()));
}
// Remove old snapshots
if ($snapshotsSettings['rotate'] != 0) {
$oldSnapshots = $db->GetAll("SELECT * FROM rds_snaps_info WHERE autosnapshotid = ? ORDER BY id ASC", 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
$AmazonRDSClient->DeleteDBSnapshot($deletingSnapshot['snapid']);
$db->Execute("DELETE FROM rds_snaps_info WHERE id = ?", array($deletingSnapshot['id']));
} catch (Exception $e) {
if (stristr($e->getMessage(), "not found") || stristr($e->getMessage(), "not a valid")) {
$db->Execute("DELETE FROM rds_snaps_info WHERE id = ?", array($deletingSnapshot['id']));
}
$this->Logger->error(sprintf(_("DBsnapshot %s for RDS instance %s was not found \r\n\t\t\t\t\t\t\t\t\t\t\t\tand 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()));
}
}
}
示例8: OnHostInit
/**
* Upload S3cmd config file, AWS private key and certificate to instance aftre instance boot.
* Also execute hostInit hooks from hooks/hostInit folder
*
* @param array $instanceinfo
* @param string $local_ip
* @param string $remote_ip
* @param string $public_key
*/
public function OnHostInit(HostInitEvent $event)
{
if ($event->DBServer->IsSupported("0.5")) {
$this->Logger->info("Scalarizr instance. Skipping SSH observer...");
return true;
}
if ($event->DBServer->platform != SERVER_PLATFORMS::EC2) {
return true;
}
// Get farm info and client info from database;
$DBFarm = DBFarm::LoadByID($this->FarmID);
$DBRole = DBRole::loadById($event->DBServer->roleId);
// Get Role info
$ssh_port = $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) ? $DBRole->getProperty(DBRole::PROPERTY_SSH_PORT) : 22;
// Generate s3cmd config file
$s3cfg = CONFIG::$S3CFG_TEMPLATE;
$s3cfg = str_replace("[access_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $s3cfg);
$s3cfg = str_replace("[secret_key]", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $s3cfg);
$s3cfg = str_replace("\r\n", "\n", $s3cfg);
// Prepare public key for SSH connection
$pub_key_file = tempnam("/tmp", "AWSK");
$res = file_put_contents($pub_key_file, $event->PublicKey);
$this->Logger->debug("Creating temporary file for public key: {$res}");
try {
$key = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($event->DBServer->farmId, $event->DBServer->GetFarmRoleObject()->CloudLocation);
if (!$key) {
throw new Exception(_("There is no SSH key for server: {$event->DBServer->serverId}"));
}
} catch (Exception $e) {
throw new Exception("Cannot init SshKey object: {$e->getMessage()}");
}
// Prepare private key for SSH connection
$priv_key_file = tempnam("/tmp", "AWSK");
$res = file_put_contents($priv_key_file, $key->getPrivate());
$this->Logger->debug("Creating temporary file for private key: {$res}");
// Connect to SSH
$SSH2 = new Scalr_Net_Ssh2_Client();
$SSH2->addPubkey("root", $pub_key_file, $priv_key_file);
if ($SSH2->connect($event->ExternalIP, $ssh_port)) {
// Upload keys and s3 config to instance
$res = $SSH2->sendFile("/etc/aws/keys/pk.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), "w+", false);
$res2 = $SSH2->sendFile("/etc/aws/keys/cert.pem", $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE), "w+", false);
$res3 = $SSH2->sendFile("/etc/aws/keys/s3cmd.cfg", $s3cfg, "w+", false);
// remove temporary files
@unlink($pub_key_file);
@unlink($priv_key_file);
} else {
// remove temporary files
@unlink($pub_key_file);
@unlink($priv_key_file);
Logger::getLogger(LOG_CATEGORY::FARM)->warn(new FarmLogMessage($this->FarmID, "Cannot upload ec2 keys to '{$event->DBServer->serverId}' instance. Failed to connect to SSH '{$event->ExternalIP}:{$ssh_port}'"));
throw new Exception("Cannot upload keys on '{$event->DBServer->serverId}'. Failed to connect to '{$event->ExternalIP}:{$ssh_port}'.");
}
}
示例9: setFarmRoleMetrics
function setFarmRoleMetrics($metrics)
{
foreach ($this->farmRoleMetrics as $id => $farmRoleMetric) {
if (!$metrics[$farmRoleMetric->metricId]) {
$farmRoleMetric->delete();
unset($this->farmRoleMetrics[$farmRoleMetric->metricId]);
}
}
foreach ($metrics as $metric_id => $metric_settings) {
if (!$this->farmRoleMetrics[$metric_id]) {
$this->farmRoleMetrics[$metric_id] = Scalr_Model::init(Scalr_Model::SCALING_FARM_ROLE_METRIC);
$this->farmRoleMetrics[$metric_id]->metricId = $metric_id;
$this->farmRoleMetrics[$metric_id]->farmRoleId = $this->dbFarmRole->ID;
}
$this->farmRoleMetrics[$metric_id]->setSettings($metric_settings);
$this->farmRoleMetrics[$metric_id]->save();
}
}
示例10: handleWork
function handleWork($deploymentTaskId)
{
try {
$deploymentTask = Scalr_Model::init(Scalr_Model::DM_DEPLOYMENT_TASK)->loadById($deploymentTaskId);
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
} catch (Exception $e) {
$deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_ARCHIVED;
return;
}
switch ($deploymentTask->status) {
case Scalr_Dm_DeploymentTask::STATUS_PENDING:
$deploymentTask->deploy();
break;
case Scalr_Dm_DeploymentTask::STATUS_DEPLOYING:
//TODO:
break;
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
}
示例11: setFarmRoleMetrics
function setFarmRoleMetrics($metrics)
{
foreach ($this->farmRoleMetrics as $id => $farmRoleMetric) {
if (!$metrics[$farmRoleMetric->metricId]) {
$farmRoleMetric->delete();
unset($this->farmRoleMetrics[$farmRoleMetric->metricId]);
}
}
foreach ($metrics as $metric_id => $metric_settings) {
if (!is_array($metric_settings)) {
continue;
}
if (!$this->farmRoleMetrics[$metric_id]) {
$this->farmRoleMetrics[$metric_id] = Scalr_Model::init(Scalr_Model::SCALING_FARM_ROLE_METRIC);
$this->farmRoleMetrics[$metric_id]->metricId = $metric_id;
$this->farmRoleMetrics[$metric_id]->farmRoleId = $this->dbFarmRole->ID;
}
$this->farmRoleMetrics[$metric_id]->clearSettings();
$this->farmRoleMetrics[$metric_id]->setSettings($metric_settings);
$this->farmRoleMetrics[$metric_id]->save(false, array('dtlastpolled', 'last_value', 'last_data'));
}
}
示例12: init
/**
*
* @return Scalr_SshKey
*/
public static function init($className = null)
{
return parent::init();
}
示例13: onMysql_PromoteToMasterResult
/**
* @param Scalr_Messaging_Msg_Mysql_PromoteToMasterResult $message
* @param DBServer $dbserver
*/
private function onMysql_PromoteToMasterResult($message, DBServer $dbserver)
{
$dbserver->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER, 0);
if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_OK) {
$dbFarm = $dbserver->GetFarmObject();
$dbFarmRole = $dbserver->GetFarmRoleObject();
$oldMaster = $dbFarm->GetMySQLInstances(true);
if ($dbserver->IsSupported("0.7")) {
if ($message->volumeConfig) {
try {
$storageVolume = Scalr_Storage_Volume::init();
try {
$storageVolume->loadById($message->volumeConfig->id);
$storageVolume->setConfig($message->volumeConfig);
$storageVolume->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageVolume->loadBy(array('id' => $message->volumeConfig->id, 'client_id' => $dbserver->clientId, 'env_id' => $dbserver->envId, 'name' => "MySQL data volume", 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'size' => $message->volumeConfig->size, 'fstype' => $message->volumeConfig->fstype, 'purpose' => ROLE_BEHAVIORS::MYSQL, 'farm_roleid' => $dbserver->farmRoleId, 'server_index' => $dbserver->index));
$storageVolume->setConfig($message->volumeConfig);
$storageVolume->save(true);
} else {
throw $e;
}
}
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage volume: {$e->getMessage()}"));
}
}
if ($message->snapshotConfig) {
try {
$snapshot = Scalr_Model::init(Scalr_Model::STORAGE_SNAPSHOT);
$snapshot->loadBy(array('id' => $message->snapshotConfig->id, 'client_id' => $dbserver->clientId, 'env_id' => $dbserver->envId, 'name' => "Automatical MySQL data bundle", 'type' => $dbFarmRole->GetSetting(DBFarmRole::SETTING_MYSQL_DATA_STORAGE_ENGINE), 'platform' => $dbserver->platform, 'description' => "MySQL data bundle created automatically by Scalr", 'ismysql' => true));
$snapshot->setConfig($message->snapshotConfig);
$snapshot->save(true);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_SCALR_SNAPSHOT_ID, $snapshot->id);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_FILE, $message->logFile);
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_LOG_POS, $message->logPos);
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($dbserver->farmId, "Cannot save storage snapshot: {$e->getMessage()}"));
}
}
} else {
// TODO: delete old slave volume if new one was created
$dbFarmRole->SetSetting(DBFarmRole::SETTING_MYSQL_MASTER_EBS_VOLUME_ID, $message->volumeId);
}
return new NewMysqlMasterUpEvent($dbserver, "", $oldMaster[0]);
} elseif ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
$dbserver->SetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER, 0);
$dbserver->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
// XXX: Need to do smth
$this->logger->error(sprintf("Promote to Master failed for server %s. Last error: %s", $dbserver->serverId, $message->lastError));
}
}
示例14: LaunchServer
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
{
$RunInstancesType = new RunInstancesType();
$RunInstancesType->ConfigureRootPartition();
if (!$launchOptions) {
$launchOptions = new Scalr_Server_LaunchOptions();
$DBRole = DBRole::loadById($DBServer->roleId);
// Set Cloudwatch monitoring
$RunInstancesType->SetCloudWatchMonitoring($DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_ENABLE_CW_MONITORING));
$launchOptions->architecture = $DBRole->architecture;
$launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::EC2, $DBServer->GetFarmRoleObject()->CloudLocation);
$launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation;
$akiId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AKIID);
if (!$akiId) {
$akiId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_AKI_ID);
}
if ($akiId) {
$RunInstancesType->kernelId = $akiId;
}
$ariId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::ARIID);
if (!$ariId) {
$ariId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_ARI_ID);
}
if ($ariId) {
$RunInstancesType->ramdiskId = $ariId;
}
$i_type = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_INSTANCE_TYPE);
if (!$i_type) {
$DBRole = DBRole::loadById($DBServer->roleId);
$i_type = $DBRole->getProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE);
}
$launchOptions->serverType = $i_type;
foreach ($DBServer->GetCloudUserData() as $k => $v) {
$u_data .= "{$k}={$v};";
}
$RunInstancesType->SetUserData(trim($u_data, ";"));
$vpcPrivateIp = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_VPC_PRIVATE_IP);
$vpcSubnetId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID);
if ($vpcSubnetId) {
$RunInstancesType->subnetId = $vpcSubnetId;
if ($vpcPrivateIp) {
$RunInstancesType->privateIpAddress = $vpcPrivateIp;
}
}
} else {
$RunInstancesType->SetUserData(trim($launchOptions->userData));
}
$DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture);
$EC2Client = Scalr_Service_Cloud_Aws::newEc2($launchOptions->cloudLocation, $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PRIVATE_KEY), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::CERTIFICATE));
// Set AMI, AKI and ARI ids
$RunInstancesType->imageId = $launchOptions->imageId;
if (!$RunInstancesType->subnetId) {
// Set Security groups
foreach ($this->GetServerSecurityGroupsList($DBServer, $EC2Client) as $sgroup) {
$RunInstancesType->AddSecurityGroup($sgroup);
}
}
$RunInstancesType->minCount = 1;
$RunInstancesType->maxCount = 1;
// Set availability zone
if (!$launchOptions->availZone) {
$avail_zone = $this->GetServerAvailZone($DBServer, $EC2Client, $launchOptions);
if ($avail_zone) {
$RunInstancesType->SetAvailabilityZone($avail_zone);
}
} else {
$RunInstancesType->SetAvailabilityZone($launchOptions->availZone);
}
// Set instance type
$RunInstancesType->instanceType = $launchOptions->serverType;
if (in_array($RunInstancesType->instanceType, array('cc1.4xlarge', 'cg1.4xlarge', 'cc2.8xlarge'))) {
$placementGroup = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_CLUSTER_PG);
if (!$placementGroup) {
$placementGroup = "scalr-role-{$DBServer->farmRoleId}";
if (!$EC2Client->CreatePlacementGroup($placementGroup)) {
throw new Exception(sprintf(_("Cannot launch new instance. Unable to create placement group: %s"), $result->faultstring));
}
$DBServer->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_AWS_CLUSTER_PG, $placementGroup);
}
$RunInstancesType->SetPlacementGroup($placementGroup);
}
// Set additional info
$RunInstancesType->additionalInfo = "";
/////
if ($DBServer->status == SERVER_STATUS::TEMPORARY) {
$keyName = "SCALR-ROLESBUILDER";
$sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
if (!$sshKey->loadGlobalByName($keyName, $launchOptions->cloudLocation, $DBServer->envId)) {
$result = $EC2Client->CreateKeyPair($keyName);
if ($result->keyMaterial) {
$sshKey->farmId = 0;
$sshKey->clientId = $DBServer->clientId;
$sshKey->envId = $DBServer->envId;
$sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = $launchOptions->cloudLocation;
$sshKey->cloudKeyName = $keyName;
$sshKey->platform = SERVER_PLATFORMS::EC2;
$sshKey->setPrivate($result->keyMaterial);
$sshKey->setPublic($sshKey->generatePublicKey());
$sshKey->save();
//.........这里部分代码省略.........
示例15: OnHostInit
/**
* Update database when 'hostInit' event recieved from instance
*
* @param HostInitEvent $event
*
*/
public function OnHostInit(HostInitEvent $event)
{
$event->DBServer->SetProperty("tmp.status", $event->DBServer->status);
$event->DBServer->localIp = $event->InternalIP;
$event->DBServer->remoteIp = $event->ExternalIP;
$event->DBServer->status = SERVER_STATUS::INIT;
$event->DBServer->Save();
$event->DBServer->SetProperty("tmp.status.processed", $event->DBServer->status);
$this->DB->Execute("DELETE FROM server_operations WHERE server_id=?", array($event->DBServer->serverId));
$event->DBServer->SetProperty(SERVER_PROPERTIES::SZR_IS_INIT_FAILED, false);
try {
$key = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($event->DBServer->farmId, $event->DBServer->GetFarmRoleObject()->CloudLocation, $event->DBServer->platform);
if ($key && !$key->getPublic()) {
$key->setPublic($event->PublicKey);
$key->save();
}
} catch (Exception $e) {
}
}