本文整理汇总了PHP中DBServer::GetFarmRoleObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::GetFarmRoleObject方法的具体用法?PHP DBServer::GetFarmRoleObject怎么用?PHP DBServer::GetFarmRoleObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::GetFarmRoleObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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())));
}
}
示例2: removeIpFromServer
public static function removeIpFromServer(\DBServer $dbServer)
{
try {
if ($dbServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP)) {
if ($dbServer->farmRoleId) {
if ($dbServer->GetFarmRoleObject()->GetSetting(\DBFarmRole::SETTING_OPENSTACK_KEEP_FIP_ON_SUSPEND)) {
if (in_array($dbServer->status, array(\SERVER_STATUS::PENDING_SUSPEND, \SERVER_STATUS::SUSPENDED)) || $dbServer->GetRealStatus()->isSuspended()) {
return false;
}
}
}
$environment = $dbServer->GetEnvironmentObject();
$osClient = $environment->openstack($dbServer->platform, $dbServer->GetCloudLocation());
$ipId = $dbServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID);
if ($osClient->hasService('network')) {
$osClient->network->floatingIps->delete($ipId);
} else {
$osClient->servers->deleteFloatingIp($ipId);
}
$dbServer->SetProperties(array(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP => null, \OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID => null));
}
} catch (\Exception $e) {
\Logger::getLogger("OpenStackObserver")->fatal("OpenStackObserver observer failed: " . $e->getMessage());
}
}
示例3: sendNewDbMsrMasterUpMessage
private function sendNewDbMsrMasterUpMessage(DBServer $newMasterServer)
{
$dbFarmRole = $newMasterServer->GetFarmRoleObject();
$servers = $dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
$dbType = $newMasterServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior();
$props = Scalr_Db_Msr_Info::init($dbFarmRole, $newMasterServer, $dbType)->getMessageProperties();
foreach ($servers as $dbServer) {
$msg = new Scalr_Messaging_Msg_DbMsr_NewMasterUp($dbFarmRole->GetRoleObject()->getBehaviors(), $dbFarmRole->GetRoleObject()->name, $newMasterServer->localIp, $newMasterServer->remoteIp, $dbType);
$msg->{$dbType} = new stdClass();
$msg->{$dbType}->snapshotConfig = $props->snapshotConfig;
foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$msg = $behavior->extendMessage($msg, $dbServer);
}
$dbServer->SendMessage($msg);
}
}
示例4: sendNewDbMsrMasterUpMessage
private function sendNewDbMsrMasterUpMessage(\DBServer $newMasterServer, $event)
{
$dbFarmRole = $newMasterServer->GetFarmRoleObject();
$servers = $dbFarmRole->GetServersByFilter(array('status' => array(\SERVER_STATUS::INIT, \SERVER_STATUS::RUNNING)));
$dbType = $newMasterServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior();
$props = \Scalr_Db_Msr_Info::init($dbFarmRole, $newMasterServer, $dbType)->getMessageProperties();
foreach ($servers as $dbServer) {
$msg = new \Scalr_Messaging_Msg_DbMsr_NewMasterUp($dbType);
$msg->setServerMetaData($newMasterServer);
$msg->{$dbType} = new \stdClass();
$msg->{$dbType}->snapshotConfig = $props->snapshotConfig;
foreach (\Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
$msg = $behavior->extendMessage($msg, $dbServer);
}
$dbServer->SendMessage($msg, false, true);
}
}
示例5: setServerMetaData
public function setServerMetaData(DBServer $dbServer)
{
try {
$this->behaviour = $dbServer->GetFarmRoleObject()->GetRoleObject()->getBehaviors();
$this->roleName = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
$this->farmRoleAlias = $dbServer->GetFarmRoleObject()->Alias;
if (empty($this->farmRoleAlias)) {
$this->farmRoleAlias = $this->roleName;
}
} catch (Exception $e) {
}
$this->localIp = $dbServer->localIp;
$this->remoteIp = $dbServer->remoteIp;
$this->serverIndex = $dbServer->index;
$this->serverId = $dbServer->serverId;
$this->cloudLocation = $dbServer->GetCloudLocation();
$this->farmRoleId = $dbServer->farmRoleId;
}
示例6: getConfiguration
public function getConfiguration(DBServer $dbServer)
{
$config = new stdClass();
$config->cookie = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_COOKIE_NAME);
$config->volumeConfig = $this->getVolumeConfig($dbServer->GetFarmRoleObject(), $dbServer);
$config->nodeType = $this->getNodeType($dbServer->GetFarmRoleObject(), $dbServer);
$config->password = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_PASSWORD);
$dbServer->SetProperty(self::SERVER_NODE_TYPE, $config->nodeType);
return $config;
}
示例7: getConfiguration
public function getConfiguration(DBServer $dbServer)
{
$configuration = new stdClass();
$configuration->proxies = json_decode($dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_PROXIES), true);
if ($dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_TEMPLATE)) {
$configuration->template = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_TEMPLATE);
}
if (count($configuration->proxies) > 0) {
$dbFarm = $dbServer->GetFarmObject();
foreach ($configuration->proxies as &$proxy) {
if (count($proxy['backends']) > 0) {
foreach ($proxy['backends'] as &$backend) {
if (isset($backend['farm_role_alias']) && !empty($backend['farm_role_alias'])) {
$backend['farm_role_id'] = $dbFarm->GetFarmRoleIdByAlias($backend['farm_role_alias']);
}
}
}
}
}
return $configuration;
}
示例8: DeregisterInstanceFromLB
private function DeregisterInstanceFromLB(DBServer $DBServer)
{
try {
$DBFarmRole = $DBServer->GetFarmRoleObject();
if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_USE_ELB) == 1) {
$Client = $DBServer->GetClient();
$AmazonELBClient = Scalr_Service_Cloud_Aws::newElb($DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
$AmazonELBClient->DeregisterInstancesFromLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), array($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID)));
Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Instance '%s' deregistered from '%s' load balancer"), $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME))));
}
} catch (Exception $e) {
Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Cannot deregister instance from the load balancer: %s"), $e->getMessage())));
}
}
示例9: extendMessage
public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
$message = parent::extendMessage($message);
switch (get_class($message)) {
case "Scalr_Messaging_Msg_HostInitResponse":
$message->rabbitmq = new stdClass();
$message->rabbitmq->cookie = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_COOKIE_NAME);
$message->rabbitmq->volumeConfig = $this->getVolumeConfig($dbServer->GetFarmRoleObject(), $dbServer);
$message->rabbitmq->nodeType = $this->getNodeType($dbServer->GetFarmRoleObject(), $dbServer);
$message->rabbitmq->password = $dbServer->GetFarmRoleObject()->GetSetting(self::ROLE_PASSWORD);
$dbServer->SetProperty(self::SERVER_NODE_TYPE, $message->rabbitmq->nodeType);
break;
}
return $message;
}
示例10: DeregisterInstanceFromLB
private function DeregisterInstanceFromLB(DBServer $DBServer)
{
try {
$DBFarmRole = $DBServer->GetFarmRoleObject();
if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_USE_ELB)) {
$useElb = true;
$elbId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME);
}
if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ELB_ENABLED)) {
$useElb = true;
$elbId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ELB_ID);
}
if ($useElb) {
$Client = $DBServer->GetClient();
$elb = $DBServer->GetEnvironmentObject()->aws($DBServer)->elb;
$elb->loadBalancer->deregisterInstances($elbId, $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID));
Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Instance '%s' deregistered from '%s' load balancer"), $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $elbId)));
}
} catch (Exception $e) {
Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Cannot deregister instance from the load balancer: %s"), $e->getMessage())));
}
}
示例11: handleMessage
public function handleMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
try {
$dbFarmRole = $dbServer->GetFarmRoleObject();
} catch (Exception $e) {
}
switch (get_class($message)) {
case "Scalr_Messaging_Msg_HostUp":
if ($message->dbType && in_array($message->dbType, array(ROLE_BEHAVIORS::REDIS, ROLE_BEHAVIORS::POSTGRESQL, ROLE_BEHAVIORS::MYSQL2))) {
$dbMsrInfo = Scalr_Db_Msr_Info::init($dbFarmRole, $dbServer, $message->dbType);
$dbMsrInfo->setMsrSettings($message->{$message->dbType});
}
break;
case "Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult":
if (Scalr_Db_Msr::onPromoteToMasterResult($message, $dbServer)) {
Scalr::FireEvent($dbServer->farmId, new NewDbMsrMasterUpEvent($dbServer));
}
break;
case "Scalr_Messaging_Msg_DbMsr_CreateDataBundleResult":
if ($message->status == "ok") {
Scalr_Db_Msr::onCreateDataBundleResult($message, $dbServer);
} else {
$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING, 0);
//TODO: store last error
}
break;
case "Scalr_Messaging_Msg_DbMsr_CreateBackupResult":
if ($message->status == "ok") {
Scalr_Db_Msr::onCreateBackupResult($message, $dbServer);
} else {
$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0);
//TODO: store last error
}
break;
}
}
示例12: getEventScriptList
public static function getEventScriptList(AbstractServerEvent $event, DBServer $eventServer, DBServer $targetServer)
{
$db = \Scalr::getDb();
$accountScripts = $db->GetAll("\n SELECT * FROM account_scripts\n WHERE account_id = ?\n AND (event_name = ? OR event_name = '*')\n ", [$eventServer->clientId, $event->GetName()]);
$roleScripts = $db->GetAll("\n SELECT * FROM role_scripts\n WHERE (event_name = ? OR event_name = '*') AND role_id = ?\n ", [$event->GetName(), $eventServer->GetFarmRoleObject()->RoleID]);
$scripts = $db->GetAll("\n SELECT *, `script_type` as `type`\n FROM farm_role_scripts\n WHERE (event_name = ? OR event_name = '*') AND farmid = ?\n ", [$event->GetName(), $eventServer->farmId]);
foreach ($accountScripts as $script) {
$scripts[] = array("id" => "a{$script['id']}", "type" => $script['script_type'], "scriptid" => $script['script_id'], "params" => $script['params'], "event_name" => $event->GetName(), "target" => $script['target'], "version" => $script['version'], "timeout" => $script['timeout'], "issync" => $script['issync'], "order_index" => $script['order_index'], "scope" => "account", 'script_path' => $script['script_path'], 'run_as' => $script['run_as'], 'script_type' => $script['script_type']);
}
foreach ($roleScripts as $script) {
$params = $db->GetOne("\n SELECT params\n FROM farm_role_scripting_params\n WHERE farm_role_id = ?\n AND `hash` = ?\n AND farm_role_script_id = '0'\n LIMIT 1\n ", array($eventServer->farmRoleId, $script['hash']));
if ($params) {
$script['params'] = $params;
}
$scripts[] = array("id" => "r{$script['id']}", "scriptid" => $script['script_id'], "type" => $script['script_type'], "params" => $script['params'], "event_name" => $event->GetName(), "target" => $script['target'], "version" => $script['version'], "timeout" => $script['timeout'], "issync" => $script['issync'], "order_index" => $script['order_index'], "scope" => "role", 'script_path' => $script['script_path'], 'run_as' => $script['run_as'], 'script_type' => $script['script_type']);
}
$retval = [];
foreach ($scripts as $scriptSettings) {
$scriptSettings['order_index'] = (double) $scriptSettings['order_index'];
// If target set to that instance only
if ($scriptSettings['target'] == Script::TARGET_INSTANCE && $eventServer->serverId != $targetServer->serverId) {
continue;
}
// If target set to all instances in specific role
if ($scriptSettings['target'] == Script::TARGET_ROLE && $eventServer->farmRoleId != $targetServer->farmRoleId) {
continue;
}
if (!$scriptSettings['scope']) {
// Validate that event was triggered on the same farmRoleId as script
if ($eventServer->farmRoleId != $scriptSettings['farm_roleid']) {
continue;
}
// Validate that target server has the same farmRoleId as event server with target ROLE
if ($scriptSettings['target'] == Script::TARGET_ROLE && $targetServer->farmRoleId != $scriptSettings['farm_roleid']) {
continue;
}
}
if ($scriptSettings['target'] == Script::TARGET_ROLES || $scriptSettings['target'] == Script::TARGET_BEHAVIORS || $scriptSettings['target'] == Script::TARGET_FARMROLES) {
if ($scriptSettings['scope'] != 'role') {
$targets = $db->GetAll("SELECT * FROM farm_role_scripting_targets WHERE farm_role_script_id = ?", array($scriptSettings['id']));
} else {
$targets = [];
}
$execute = false;
foreach ($targets as $target) {
switch ($target['target_type']) {
case "farmrole":
if ($scriptSettings['target'] == Script::TARGET_ROLES && $targetServer->farmRoleId == $target['target'] || $scriptSettings['target'] == Script::TARGET_FARMROLES && $targetServer->GetFarmRoleObject()->Alias == $target['target']) {
$execute = true;
}
break;
case "behavior":
if ($targetServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior($target['target'])) {
$execute = true;
}
break;
}
}
if (!$execute) {
continue;
}
}
if ($scriptSettings['target'] == "" || $scriptSettings['id'] == "") {
continue;
}
$script = self::prepareScript($scriptSettings, $targetServer, $event);
if ($script) {
while (true) {
$index = (string) $scriptSettings['order_index'];
if (empty($retval[$index])) {
$retval[$index] = $script;
break;
} else {
$scriptSettings['order_index'] += 0.01;
}
}
}
}
if (!empty($retval) && is_array($retval)) {
ksort($retval);
}
return $retval;
}
示例13: LaunchServer
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
{
$environment = $DBServer->GetEnvironmentObject();
$diskOffering = null;
$size = null;
if (!$launchOptions) {
$farmRole = $DBServer->GetFarmRoleObject();
$launchOptions = new Scalr_Server_LaunchOptions();
$dbRole = DBRole::loadById($DBServer->roleId);
$launchOptions->imageId = $dbRole->getImageId($this->platform, $DBServer->GetFarmRoleObject()->CloudLocation);
$launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID);
$launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation;
/*
* User Data
*/
foreach ($DBServer->GetCloudUserData() as $k => $v) {
$u_data .= "{$k}={$v};";
}
$launchOptions->userData = trim($u_data, ";");
$diskOffering = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_DISK_OFFERING_ID);
if ($diskOffering === false || $diskOffering === null) {
$diskOffering = null;
}
$sharedIp = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SHARED_IP_ID);
$networkType = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
$networkId = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID);
$roleName = $farmRole->GetRoleObject()->name;
} else {
$launchOptions->userData = array();
$roleName = 'TemporaryScalrServer' . rand(100, 999);
}
$launchOptions->architecture = 'x86_64';
$cs = $this->getCloudStackClient($environment, $launchOptions->cloudLocation);
if (!$sharedIp) {
if ($networkId && ($networkType == 'Virtual' || $networkType == 'Isolated' || !$networkType)) {
$sharedIpId = $this->getConfigVariable(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}", $environment, false);
if (!$sharedIpId) {
$ipResult = $cs->associateIpAddress($launchOptions->cloudLocation);
$ipId = $ipResult->id;
if ($ipId) {
while (true) {
$ipInfo = $cs->listPublicIpAddresses($ipId);
$ipInfo = $ipInfo->publicipaddress[0];
if (!$ipInfo) {
throw new Exception("Cannot allocate IP address: listPublicIpAddresses -> failed");
}
if ($ipInfo->state == 'Allocated') {
$this->setConfigVariable(array(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}" => $ipId), $environment, false);
$this->setConfigVariable(array(self::SHARED_IP . ".{$launchOptions->cloudLocation}" => $ipInfo->ipaddress), $environment, false);
$this->setConfigVariable(array(self::SHARED_IP_INFO . ".{$launchOptions->cloudLocation}" => serialize($ipInfo)), $environment, false);
$sharedIpId = $ipId;
break;
} else {
if ($ipInfo->state == 'Allocating') {
sleep(1);
} else {
throw new Exception("Cannot allocate IP address: ipAddress->state = {$ipInfo->state}");
}
}
}
} else {
throw new Exception("Cannot allocate IP address: associateIpAddress -> failed");
}
}
}
}
if ($DBServer->status == SERVER_STATUS::TEMPORARY) {
$keyName = "SCALR-ROLESBUILDER-" . SCALR_ID;
$farmId = 0;
} else {
$keyName = "FARM-{$DBServer->farmId}-" . SCALR_ID;
$farmId = $DBServer->farmId;
}
$sshKey = Scalr_SshKey::init();
try {
if (!$sshKey->loadGlobalByName($keyName, "", $DBServer->envId, $this->platform)) {
$result = $cs->createSSHKeyPair($keyName);
if ($result->keypair->privatekey) {
$sshKey->farmId = $farmId;
$sshKey->clientId = $DBServer->clientId;
$sshKey->envId = $DBServer->envId;
$sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
$sshKey->cloudLocation = "";
//$launchOptions->cloudLocation;
$sshKey->cloudKeyName = $keyName;
$sshKey->platform = $this->platform;
$sshKey->setPrivate($result->keypair->privatekey);
$sshKey->setPublic($sshKey->generatePublicKey());
$sshKey->save();
}
}
} catch (Exception $e) {
Logger::getLogger("CloudStack")->error(new FarmLogMessage($DBServer->farmId, "Unable to generate keypair: {$e->getMessage()}"));
}
$vResult = $cs->deployVirtualMachine($launchOptions->serverType, $launchOptions->imageId, $launchOptions->cloudLocation, null, $diskOffering, $DBServer->serverId, null, $roleName, null, null, $keyName, "", $networkId, null, null, $size, base64_encode($launchOptions->userData));
if ($vResult->id) {
$DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $vResult->id);
$DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation);
$DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::LAUNCH_JOB_ID, $vResult->jobid);
$DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture);
//.........这里部分代码省略.........
示例14: onPromoteToMasterResult
public static function onPromoteToMasterResult(Scalr_Messaging_Msg_DbMsr_PromoteToMasterResult $message, DBServer $dbServer)
{
$dbFarm = $dbServer->GetFarmObject();
$dbFarmRole = $dbServer->GetFarmRoleObject();
$dbFarmRole->SetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER, 0);
if ($message->status == Scalr_Messaging_Msg_Mysql_PromoteToMasterResult::STATUS_FAILED) {
$dbServer->SetProperty(Scalr_Db_Msr::REPLICATION_MASTER, 0);
return false;
}
$dbSettings = $message->{$message->dbType};
//Update volumeCondig
if ($dbSettings->volumeConfig) {
try {
$storageVolume = Scalr_Storage_Volume::init();
try {
$storageVolume->loadById($dbSettings->volumeConfig->id);
$storageVolume->setConfig($dbSettings->volumeConfig);
$storageVolume->save();
} catch (Exception $e) {
if (strpos($e->getMessage(), 'not found')) {
$storageVolume->loadBy(array('id' => $dbSettings->volumeConfig->id, 'client_id' => $dbServer->clientId, 'env_id' => $dbServer->envId, 'name' => "'{$message->dbType}' data volume", 'type' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE), 'platform' => $dbServer->platform, 'size' => $dbSettings->volumeConfig->size, 'fstype' => $dbSettings->volumeConfig->fstype, 'purpose' => $message->dbType, 'farm_roleid' => $dbFarmRole->ID, 'server_index' => $dbServer->index));
$storageVolume->setConfig($dbSettings->volumeConfig);
$storageVolume->save(true);
} else {
throw $e;
}
}
} catch (Exception $e) {
Logger::getLogger(__CLASS__)->error(new FarmLogMessage($dbServer->farmId, "Cannot save storage volume: {$e->getMessage()}"));
}
}
self::onCreateDataBundleResult($message, $dbServer);
return true;
}
示例15: LaunchServer
/**
launchOptions: imageId
*/
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
{
if (!$launchOptions) {
$launchOptions = new Scalr_Server_LaunchOptions();
$DBRole = DBRole::loadById($DBServer->roleId);
$launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::OPENSTACK, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
$launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_FLAVOR_ID);
$launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation;
foreach ($DBServer->GetCloudUserData() as $k => $v) {
$u_data .= "{$k}={$v};";
}
$launchOptions->userData = trim($u_data, ";");
$launchOptions->architecture = 'x86_64';
}
$osClient = $this->getOsClient($DBServer->GetEnvironmentObject(), $launchOptions->cloudLocation);
$result = $osClient->serverCreate($DBServer->serverId, $launchOptions->imageId, $launchOptions->serverType, base64_encode($launchOptions->userData), array('path' => '/etc/scalr/private.d/.user-data', 'contents' => base64_encode($launchOptions->userData)));
if ($result->server) {
//TODO:
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $result->server->id);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::IMAGE_ID, $result->server->image->id);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID, $result->server->flavor->id);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::ADMIN_PASS, $result->server->adminPass);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::NAME, $DBServer->serverId);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::HOST_ID, $result->server->hostId);
$DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture);
$DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation);
return $DBServer;
} else {
throw new Exception(sprintf(_("Cannot launch new instance. %s"), $result->faultstring));
}
}