当前位置: 首页>>代码示例>>PHP>>正文


PHP DBServer::SetProperty方法代码示例

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


在下文中一共展示了DBServer::SetProperty方法的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())));
     }
 }
开发者ID:scalr,项目名称:scalr,代码行数:30,代码来源:AzureHelper.php

示例2: TerminateServer

 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\Platforms\Cloudstack\CloudstackPlatformModule::TerminateServer()
  */
 public function TerminateServer(\DBServer $DBServer)
 {
     $cs = $DBServer->GetEnvironmentObject()->cloudstack($this->platform);
     if (!$DBServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE)) {
         $cs->instance->stop($DBServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID), true);
         $DBServer->SetProperty(\CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE, 1);
     }
     return parent::TerminateServer($DBServer);
 }
开发者ID:rickb838,项目名称:scalr,代码行数:13,代码来源:UCloudPlatformModule.php

示例3: ResumeServer

 public function ResumeServer(\DBServer $DBServer)
 {
     if ($this->getResumeStrategy() == \Scalr_Role_Behavior::RESUME_STRATEGY_INIT) {
         $DBServer->status = \SERVER_STATUS::PENDING;
     }
     $DBServer->SetProperty(\SERVER_PROPERTIES::RESUMING, 1);
     $DBServer->dateAdded = date("Y-m-d H:i:s");
     $DBServer->Save();
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:9,代码来源:AbstractPlatformModule.php

示例4: 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);
//.........这里部分代码省略.........
开发者ID:recipe,项目名称:scalr,代码行数:101,代码来源:Cloudstack.php

示例5: 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;
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:34,代码来源:Msr.php

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

示例7: LaunchServer

 public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
 {
     $RDSClient = $this->getRdsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION));
     $DBRole = DBRole::loadById($DBServer->roleId);
     $server_id = "scalr-{$DBServer->serverId}";
     $avail_zone = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE) ? $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE) : $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION) . "a";
     try {
         if ($DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)) == 'ScalrEmpty') {
             $RDSClient->CreateDBInstance($server_id, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::STORAGE), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_CLASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ENGINE), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::MASTER_USER), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::MASTER_PASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::PORT), null, null, null, $avail_zone, null, null, null);
         } else {
             $RDSClient->RestoreDBInstanceFromDBSnapshot($DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)), $server_id, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_CLASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::PORT), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE));
         }
         $DBServer->SetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ID, $server_id);
         $DBServer->SetProperty(RDS_SERVER_PROPERTIES::SNAPSHOT_ID, $DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)));
         return $DBServer;
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot launch new instance. %s"), $e->getMessage()));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:19,代码来源:Rds.php

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

示例9: 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::RACKSPACE, $DBServer->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
         $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_RS_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';
     }
     $rsClient = $this->getRsClient($DBServer->GetEnvironmentObject(), $launchOptions->cloudLocation);
     //Cannot launch new instance. Request to Rackspace failed (Code: 413): {"overLimit":{"message":"Too many requests...","code":413,"retryAfter":"2012-03-12T09:44:56.343-05:00"}} (19641119, 4)
     try {
         $result = $rsClient->createServer($DBServer->serverId, $launchOptions->imageId, $launchOptions->serverType, array(), array('path' => '/etc/scalr/private.d/.user-data', 'contents' => base64_encode($launchOptions->userData)));
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), $e->getMessage(), $launchOptions->imageId, $launchOptions->serverType));
     }
     if ($result->server) {
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::SERVER_ID, $result->server->id);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::IMAGE_ID, $result->server->imageId);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID, $result->server->flavorId);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::ADMIN_PASS, $result->server->adminPass);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::NAME, $DBServer->serverId);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::HOST_ID, $result->server->hostId);
         $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture);
         $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER, $launchOptions->cloudLocation);
         return $DBServer;
     } else {
         throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), serialize($result), $launchOptions->imageId, $launchOptions->serverType));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:38,代码来源:Rackspace.php

示例10: LaunchServer

 public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
 {
     $environment = $DBServer->GetEnvironmentObject();
     $farmRole = $DBServer->GetFarmRoleObject();
     $location = $farmRole->CloudLocation;
     $nimbulaClient = $this->getNimbulaClient($environment, $location);
     $dbRole = $DBServer->GetFarmRoleObject()->GetRoleObject();
     if (!$dbRole->getProperty(DBRole::PROPERTY_NIMBULA_ENTRY)) {
         $username = $environment->getPlatformConfigValue(self::USERNAME);
         $imageLists = $nimbulaClient->imageListList();
         $listFound = false;
         foreach ($imageLists as $list) {
             if ($list->name == "{$username}/scalr") {
                 $listFound = true;
             }
         }
         if (!$listFound) {
             $nimbulaClient->imageListCreate('scalr', 'Image list for scalr images');
         }
         $entry = (int) $environment->getPlatformConfigValue(Modules_Platforms_Nimbula::IMAGE_LIST_ENTRY_VALUE);
         $entry++;
         $nimbulaClient->imageListAddEntry('scalr', $dbRole->getImageId($DBServer->platform, $location), $entry);
         $environment->setPlatformConfig(array(Modules_Platforms_Nimbula::IMAGE_LIST_ENTRY_VALUE => $entry));
         $dbRole->setProperty(DBRole::PROPERTY_NIMBULA_ENTRY, $entry);
     }
     $instance = $nimbulaClient->instanceLaunch($DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_NIMBULA_SHAPE), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::USERNAME) . "/scalr", $dbRole->getProperty(DBRole::PROPERTY_NIMBULA_ENTRY), "Scalr server: FarmID: {$DBServer->farmId} RoleName: {$DBServer->GetFarmRoleObject()->GetRoleObject()->name}");
     $instanceInfo = $instance->instances[0];
     if ($instanceInfo->name) {
         $serverName = str_replace($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::USERNAME) . "/", "", $instanceInfo->name);
         $DBServer->SetProperty(NIMBULA_SERVER_PROPERTIES::NAME, $serverName);
         $DBServer->SetProperty(NIMBULA_SERVER_PROPERTIES::CLOUD_LOCATION, $location);
         return $DBServer;
     } else {
         throw new Exception("Scalr unable to launch Nimbula server");
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:36,代码来源:Nimbula.php

示例11: LaunchServer

 public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
 {
     $DBRole = DBRole::loadById($DBServer->roleId);
     $eucaClient = $this->getEucaClient($DBServer->GetEnvironmentObject(), $DBServer->GetCloudLocation());
     $i_type = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_EUCA_INSTANCE_TYPE);
     foreach ($DBServer->GetCloudUserData() as $k => $v) {
         $u_data .= "{$k}={$v};";
     }
     /*
     $imageId, $instanceType, $keyName = null, $availZone = null, $securityGroup = array(), $userData = "", 
     			 $minCount = 1, $maxCount = 1, $kernelId = null, $ramdiskId = null, $monitoring = false
     */
     $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $DBRole->architecture);
     $key_pair_name = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($DBServer->farmId, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION))->cloudKeyName;
     $result = $eucaClient->runInstances($DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION)), $i_type, $key_pair_name, $this->GetServerAvailZone($DBServer), $this->GetServerSecurityGroupsList($DBServer, $eucaClient), trim($u_data, ";"));
     if ($result->instancesSet) {
         $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::AVAIL_ZONE, (string) $result->instancesSet->item[0]->placement->availabilityZone);
         $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_ID, (string) $result->instancesSet->item[0]->instanceId);
         $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_TYPE, $i_type);
         $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::EMIID, $DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION)));
         return $DBServer;
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:23,代码来源:Eucalyptus.php

示例12: LaunchServer


//.........这里部分代码省略.........
     $accessConfig = new Google_AccessConfig();
     $accessConfig->setName("External NAT");
     $accessConfig->setType("ONE_TO_ONE_NAT");
     $network = new Google_NetworkInterface();
     $network->setNetwork($this->getObjectUrl($networkName, 'networks', $environment->getPlatformConfigValue(self::PROJECT_ID)));
     $network->setAccessConfigs(array($accessConfig));
     $instance->setNetworkInterfaces(array($network));
     $serviceAccount = new Google_ServiceAccount();
     $serviceAccount->setEmail("default");
     $serviceAccount->setScopes(array("https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.full_control"));
     $instance->setServiceAccounts(array($serviceAccount));
     if ($launchOptions->cloudLocation != 'x-scalr-custom') {
         $availZone = $launchOptions->cloudLocation;
     } else {
         $location = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_GCE_CLOUD_LOCATION);
         $availZones = array();
         if (stristr($location, "x-scalr-custom")) {
             $zones = explode("=", $location);
             foreach (explode(":", $zones[1]) as $zone) {
                 if ($zone != "") {
                     array_push($availZones, $zone);
                 }
             }
         }
         sort($availZones);
         $availZones = array_reverse($availZones);
         $servers = $DBServer->GetFarmRoleObject()->GetServersByFilter(array("status" => array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT, SERVER_STATUS::PENDING)));
         $availZoneDistribution = array();
         foreach ($servers as $cDbServer) {
             if ($cDbServer->serverId != $DBServer->serverId) {
                 $availZoneDistribution[$cDbServer->GetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION)]++;
             }
         }
         $sCount = 1000000;
         foreach ($availZones as $zone) {
             if ((int) $availZoneDistribution[$zone] <= $sCount) {
                 $sCount = (int) $availZoneDistribution[$zone];
                 $availZone = $zone;
             }
         }
         $aZones = implode(",", $availZones);
         // Available zones
         $dZones = "";
         // Zones distribution
         foreach ($availZoneDistribution as $zone => $num) {
             $dZones .= "({$zone}:{$num})";
         }
         $DBServer->SetProperty("tmp.gce.avail_zone.algo2", "[A:{$aZones}][D:{$dZones}][S:{$availZone}]");
     }
     $instance->setZone($this->getObjectUrl($availZone, 'zones', $environment->getPlatformConfigValue(self::PROJECT_ID)));
     $instance->setMachineType($this->getObjectUrl($launchOptions->serverType, 'machineTypes', $environment->getPlatformConfigValue(self::PROJECT_ID), $availZone));
     $instance->setImage($this->getObjectUrl($launchOptions->imageId, 'images', $environment->getPlatformConfigValue(self::PROJECT_ID)));
     $instance->setName($DBServer->serverId);
     $tags = array('scalr', "env-{$DBServer->envId}");
     if ($DBServer->farmId) {
         $tags[] = "farm-{$DBServer->farmId}";
     }
     if ($DBServer->farmRoleId) {
         $tags[] = "farmrole-{$DBServer->farmRoleId}";
     }
     $gTags = new Google_Tags();
     $gTags->setItems($tags);
     $instance->setTags($gTags);
     $metadata = new Google_Metadata();
     $items = array();
     // Set user data
     foreach ($userData as $k => $v) {
         $uData .= "{$k}={$v};";
     }
     $uData = trim($uData, ";");
     if ($uData) {
         $item = new Google_MetadataItems();
         $item->setKey('scalr');
         $item->setValue($uData);
         $items[] = $item;
     }
     // Add SSH Key
     $item = new Google_MetadataItems();
     $item->setKey("sshKeys");
     $item->setValue("scalr:{$publicKey}");
     $items[] = $item;
     $metadata->setItems($items);
     $instance->setMetadata($metadata);
     try {
         $result = $gce->instances->insert($environment->getPlatformConfigValue(self::PROJECT_ID), $availZone, $instance);
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), $e->getMessage(), $launchOptions->imageId, $launchOptions->serverType));
     }
     if ($result->id) {
         $DBServer->SetProperty(GCE_SERVER_PROPERTIES::PROVISIONING_OP_ID, $result->name);
         $DBServer->SetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME, $DBServer->serverId);
         $DBServer->SetProperty(GCE_SERVER_PROPERTIES::SERVER_ID, $DBServer->serverId);
         $DBServer->SetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION, $availZone);
         $DBServer->SetProperty(GCE_SERVER_PROPERTIES::MACHINE_TYPE, $launchOptions->serverType);
         $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture);
         return $DBServer;
     } else {
         throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), serialize($result), $launchOptions->imageId, $launchOptions->serverType));
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:101,代码来源:GoogleCE.php

示例13: LaunchServer

 public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
 {
     $environment = $DBServer->GetEnvironmentObject();
     $farmRole = $DBServer->GetFarmRoleObject();
     if (!$launchOptions) {
         $launchOptions = new Scalr_Server_LaunchOptions();
         $dbRole = DBRole::loadById($DBServer->roleId);
         $launchOptions->imageId = $dbRole->getImageId(SERVER_PLATFORMS::CLOUDSTACK, $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, ";");
         $launchOptions->architecture = 'x86_64';
     }
     $cs = $this->getCloudStackClient($environment, $launchOptions->cloudLocation);
     $networkType = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
     if ($networkType == 'Virtual') {
         $sharedIpId = $environment->getPlatformConfigValue(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}", 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') {
                         $environment->setPlatformConfig(array(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}" => $ipId), false);
                         $environment->setPlatformConfig(array(self::SHARED_IP . ".{$launchOptions->cloudLocation}" => $ipInfo->ipaddress), false);
                         $environment->setPlatformConfig(array(self::SHARED_IP_INFO . ".{$launchOptions->cloudLocation}" => serialize($ipInfo)), 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");
             }
         }
     }
     $sshKey = Scalr_SshKey::init();
     try {
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $launchOptions->cloudLocation)) {
             $key_name = "FARM-{$DBServer->farmId}";
             $result = $cs->createSSHKeyPair($key_name);
             if ($result->keypair->privatekey) {
                 $sshKey->farmId = $DBServer->farmId;
                 $sshKey->clientId = $DBServer->clientId;
                 $sshKey->envId = $DBServer->envId;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $launchOptions->cloudLocation;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::CLOUDSTACK;
                 $sshKey->setPrivate($result->keypair->privatekey);
                 $sshKey->setPublic($sshKey->generatePublicKey());
                 $sshKey->save();
             }
         }
     } catch (Exception $e) {
     }
     $keyName = $sshKey->cloudKeyName;
     $vResult = $cs->deployVirtualMachine($launchOptions->serverType, $launchOptions->imageId, $launchOptions->cloudLocation, null, null, "", null, $farmRole->GetRoleObject()->name, null, null, $keyName, "", $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID), null, null, null, 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);
         return $DBServer;
     } else {
         throw new Exception(sprintf("Cannot launch new instance: %s", $vResult->errortext));
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:83,代码来源:Cloudstack.php

示例14: handleMessage

 public function handleMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     if (!$message->chef) {
         return;
     }
     switch (get_class($message)) {
         case "Scalr_Messaging_Msg_HostUp":
             $dbServer->SetProperty(self::SERVER_CHEF_NODENAME, $message->chef->nodeName);
             break;
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:11,代码来源:Chef.php

示例15: handleMessage

 /**
  * Handle message from scalarizr
  *
  * @param Scalr_Messaging_Msg $message
  * @param DBServer $dbServer
  */
 public function handleMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
 {
     switch (get_class($message)) {
         case "Scalr_Messaging_Msg_HostUpdate":
             if ($message->base->apiPort) {
                 $currentApiPort = $dbServer->getPort(DBServer::PORT_API);
                 $this->logger->warn(new FarmLogMessage($dbServer->farmId, "Scalarizr API port was changed from {$currentApiPort} to {$message->base->apiPort}", $dbServer->serverId));
                 $dbServer->SetProperty(SERVER_PROPERTIES::SZR_API_PORT, $message->base->apiPort);
             }
             if ($message->base->messagingPort) {
                 $currentCtrlPort = $dbServer->getPort(DBServer::PORT_CTRL);
                 $this->logger->warn(new FarmLogMessage($dbServer->farmId, "Scalarizr CTRL port was changed from {$currentCtrlPort} to {$message->base->messagingPort}", $dbServer->serverId));
                 $dbServer->SetProperty(SERVER_PROPERTIES::SZR_CTRL_PORT, $message->base->messagingPort);
             }
             break;
         case "Scalr_Messaging_Msg_HostUp":
             try {
                 if (!empty($message->volumes) && $dbServer->farmRoleId) {
                     $storage = new FarmRoleStorage($dbServer->GetFarmRoleObject());
                     $storage->setVolumes($dbServer, $message->volumes);
                 }
             } catch (Exception $e) {
                 $this->logger->error(new FarmLogMessage($dbServer->farmId, "Error in role message handler: {$e->getMessage()}", $dbServer->serverId));
             }
             if (isset($message->base) && isset($message->base->hostname)) {
                 $dbServer->SetProperty(self::SERVER_BASE_HOSTNAME, $message->base->hostname);
             }
             break;
     }
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:36,代码来源:Behavior.php


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