本文整理汇总了PHP中Scalr\Modules\PlatformFactory::isCloudstack方法的典型用法代码示例。如果您正苦于以下问题:PHP PlatformFactory::isCloudstack方法的具体用法?PHP PlatformFactory::isCloudstack怎么用?PHP PlatformFactory::isCloudstack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr\Modules\PlatformFactory
的用法示例。
在下文中一共展示了PlatformFactory::isCloudstack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param string $platform Platform
* @param DBFarmRole $DBFarmRole optional Farm Role object
* @param int $index optional Server index within the Farm Role scope
* @param string $role_id optional Identifier of the Role
*/
public function __construct($platform, DBFarmRole $DBFarmRole = null, $index = null, $role_id = null)
{
$this->platform = $platform;
$this->dbFarmRole = $DBFarmRole;
$this->index = $index;
$this->roleId = $role_id === null ? $this->dbFarmRole->RoleID : $role_id;
if ($DBFarmRole) {
$this->envId = $DBFarmRole->GetFarmObject()->EnvID;
}
//Refletcion
$Reflect = new ReflectionClass(DBServer::$platformPropsClasses[$this->platform]);
foreach ($Reflect->getConstants() as $k => $v) {
$this->platformProps[] = $v;
}
if ($DBFarmRole) {
if (PlatformFactory::isOpenstack($this->platform)) {
$this->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
} elseif (PlatformFactory::isCloudstack($this->platform)) {
$this->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
} else {
switch ($this->platform) {
case SERVER_PLATFORMS::GCE:
$this->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $DBFarmRole->CloudLocation));
break;
case SERVER_PLATFORMS::EC2:
$this->SetProperties(array(EC2_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation));
break;
}
}
}
$this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.20.0'));
}
示例2: adapter
/**
* Gets a new Instance of the adapter
*
* @param string|CloudCredentials|object $name The name of the adapter, or CloudCredentials entity, or cloud credentials data
*
* @return ApiEntityAdapter Returns the instance of cloud credentials adapter
*
* @throws ApiErrorException
*/
public function adapter($name, array $transform = null)
{
if (is_object($name)) {
//
$property = $name instanceof $this->entityClass ? static::$entityDescriminator : static::$objectDiscriminator;
$value = empty($transform) ? $name->{$property} : $transform[$name->{$property}];
switch (true) {
case PlatformFactory::isOpenstack($value, true):
$value = SERVER_PLATFORMS::OPENSTACK;
break;
case PlatformFactory::isCloudstack($value):
$value = SERVER_PLATFORMS::CLOUDSTACK;
break;
case PlatformFactory::isRackspace($value):
$value = SERVER_PLATFORMS::RACKSPACE;
break;
}
if (!isset(static::$inheritanceMap[$value])) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unknown cloud '{$value}'");
}
$class = empty(static::$inheritanceMap) ? $value : static::$inheritanceMap[$value];
$name = empty(static::$inheritedNamespace) ? $class : static::$inheritedNamespace . "\\{$class}";
}
return parent::adapter($name);
}
示例3: parseInstallScriptArgs
/**
* Decode params from href depending on type of OS
*
* Possible formats (branch is optioanl):
* for windows: /{repo}/[{branch}/]install_scalarizr.ps1
* for linux: /{repo}/{platform}/[{branch}]/install_scalarizr.sh
*
* @param array $params
* @param bool $isLinux
* @return array
*/
protected function parseInstallScriptArgs($params, $isLinux = true)
{
$result = ['repo' => '', 'platform' => '', 'repoUrls' => []];
$repo = array_shift($params);
$platform = $isLinux ? array_shift($params) : '';
array_pop($params);
// pop script name from the end of href
$branch = implode('/', $params);
$repos = $this->getContainer()->config('scalr.scalarizr_update.' . ($branch ? 'devel_repos' : 'repos'));
if (in_array($repo, array_keys($repos))) {
if ($branch) {
// strip illegal chars
$branch = preg_replace('/[^A-Za-z\\/0-9_.-]/', '', $branch);
$branch = str_replace(array(".", '/'), array('', '-'), $branch);
}
$repoUrls = $repos[$repo];
if ($branch) {
foreach ($repoUrls as $key => &$url) {
$url = sprintf($url, $branch);
}
}
if ($isLinux) {
if (in_array($platform, $this->getContainer()->config('scalr.allowed_clouds'))) {
if (PlatformFactory::isOpenstack($platform)) {
$platform = SERVER_PLATFORMS::OPENSTACK;
} else {
if (PlatformFactory::isCloudstack($platform)) {
$platform = SERVER_PLATFORMS::CLOUDSTACK;
}
}
$result['platform'] = $platform;
$result['repo'] = $repo;
$result['repoUrls'] = $repoUrls;
}
} else {
$result['repo'] = $repo;
$result['repoUrls'] = $repoUrls;
}
}
return $result;
}
示例4: xGetCloudServersListAction
public function xGetCloudServersListAction()
{
$this->request->defineParams(array('platform', 'cloudLocation'));
if (!$this->environment->isPlatformEnabled($this->getParam('platform'))) {
throw new Exception(sprintf('Cloud %s is not enabled for current environment', $this->getParam('platform')));
}
$results = array();
$platform = PlatformFactory::NewPlatform($this->getParam('platform'));
//TODO: Added support for GCE
if ($this->getParam('platform') == SERVER_PLATFORMS::GCE) {
$gce = $platform->getClient($this->environment, $this->getParam('cloudLocation'));
$result = $gce->instances->listInstances($this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID), $this->getParam('cloudLocation'), array());
if (is_array($result->items)) {
foreach ($result->items as $server) {
if ($server->status != 'RUNNING') {
continue;
}
$ips = $platform->determineServerIps($gce, $server);
$itm = array('id' => $server->name, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(GCE_SERVER_PROPERTIES::SERVER_NAME, $server->name);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
}
} elseif (PlatformFactory::isOpenstack($this->getParam('platform'))) {
$client = $this->environment->openstack($this->getParam('platform'), $this->getParam('cloudLocation'));
$r = $client->servers->list(true);
do {
foreach ($r as $server) {
if ($server->status != 'ACTIVE') {
continue;
}
$ips = $platform->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
} while (false !== ($r = $r->getNextPage()));
} elseif (PlatformFactory::isCloudstack($this->getParam('platform'))) {
$client = $this->environment->cloudstack($this->getParam('platform'));
$platform = PlatformFactory::NewPlatform($this->getParam('platform'));
$r = $client->instance->describe(array('zoneid' => $this->getParam('cloudLocation')));
if (count($r) > 0) {
foreach ($r as $server) {
$ips = $platform->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
}
} elseif ($this->getParam('platform') == SERVER_PLATFORMS::EC2) {
$client = $this->environment->aws($this->getParam('cloudLocation'))->ec2;
$nextToken = null;
do {
if (isset($r)) {
$nextToken = $r->getNextToken();
}
$r = $client->instance->describe(null, null, $nextToken);
if (count($r)) {
foreach ($r as $reservation) {
/* @var $reservation Scalr\Service\Aws\Ec2\DataType\ReservationData */
foreach ($reservation->instancesSet as $instance) {
/* @var $instance Scalr\Service\Aws\Ec2\DataType\InstanceData */
if ($instance->instanceState->name != 'running') {
continue;
//.........这里部分代码省略.........
示例5: run1
public function run1($stage)
{
if ($this->hasTable('images')) {
$this->db->Execute('DROP TABLE images');
// drop old table if existed
}
$this->db->Execute("CREATE TABLE `images` (\n `hash` binary(16) NOT NULL,\n `id` varchar(128) NOT NULL DEFAULT '',\n `env_id` int(11) NULL DEFAULT NULL,\n `bundle_task_id` int(11) NULL DEFAULT NULL,\n `platform` varchar(25) NOT NULL DEFAULT '',\n `cloud_location` varchar(255) NOT NULL DEFAULT '',\n `os_family` varchar(25) NULL DEFAULT NULL,\n `os_version` varchar(10) NULL DEFAULT NULL,\n `os_name` varchar(255) NULL DEFAULT NULL,\n `created_by_id` int(11) NULL DEFAULT NULL,\n `created_by_email` varchar(100) NULL DEFAULT NULL,\n `architecture` enum('i386','x86_64') NOT NULL DEFAULT 'x86_64',\n `is_deprecated` tinyint(1) NOT NULL DEFAULT '0',\n `source` enum('BundleTask','Manual') NOT NULL DEFAULT 'Manual',\n `type` varchar(20) NULL DEFAULT NULL,\n `status` varchar(20) NOT NULL,\n `status_error` varchar(255) NULL DEFAULT NULL,\n `agent_version` varchar(20) NULL DEFAULT NULL,\n PRIMARY KEY (`hash`),\n UNIQUE KEY `idx_id` (`env_id`, `id`, `platform`, `cloud_location`),\n CONSTRAINT `fk_images_client_environmnets_id` FOREIGN KEY (`env_id`) REFERENCES `client_environments` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION\n ) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n ");
$allRecords = 0;
$excludedCL = 0;
$excludedMissing = 0;
// convert
$tasks = [];
foreach ($this->db->GetAll('SELECT id as bundle_task_id, client_id as account_id, env_id, platform, snapshot_id as id, cloud_location, os_family, os_name,
os_version, created_by_id, created_by_email, bundle_type as type FROM bundle_tasks WHERE status = ?', [\SERVER_SNAPSHOT_CREATION_STATUS::SUCCESS]) as $t) {
if (!is_array($tasks[$t['env_id']])) {
$tasks[$t['env_id']] = [];
}
$allRecords++;
$tasks[$t['env_id']][] = $t;
}
foreach ($this->db->GetAll('SELECT r.client_id as account_id, r.env_id, ri.platform, ri.image_id as id, ri.cloud_location, ri.os_family, ri.os_name,
ri.os_version, r.added_by_userid as created_by_id, r.added_by_email as created_by_email, ri.agent_version FROM role_images ri JOIN roles r ON r.id = ri.role_id') as $t) {
if (!is_array($tasks[$t['env_id']])) {
$tasks[$t['env_id']] = [];
}
$allRecords++;
$tasks[$t['env_id']][] = $t;
}
foreach ($tasks as $id => $e) {
if ($id == 0) {
continue;
}
try {
$env = (new \Scalr_Environment())->loadById($id);
} catch (\Exception $e) {
$this->console->warning('Invalid environment %d: %s', $id, $e->getMessage());
continue;
}
foreach ($e as $t) {
// check if snapshot exists
$add = false;
if ($this->db->GetOne('SELECT id FROM images WHERE id = ? AND env_id = ? AND platform = ? AND cloud_location = ? LIMIT 1', [$t['id'], $t['env_id'], $t['platform'], $t['cloud_location']])) {
continue;
}
if ($t['platform'] != \SERVER_PLATFORMS::GCE && !$t['cloud_location']) {
$excludedCL++;
continue;
}
try {
switch ($t['platform']) {
case \SERVER_PLATFORMS::EC2:
$snap = $env->aws($t['cloud_location'])->ec2->image->describe($t['id']);
if (count($snap)) {
$add = true;
$t['architecture'] = $snap->toArray()[0]['architecture'];
}
break;
case \SERVER_PLATFORMS::RACKSPACE:
$platform = PlatformFactory::NewPlatform(\SERVER_PLATFORMS::RACKSPACE);
/* @var $platform RackspacePlatformModule */
$client = \Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(RackspacePlatformModule::USERNAME, true, $t['cloud_location']), $env->getPlatformConfigValue(RackspacePlatformModule::API_KEY, true, $t['cloud_location']), $t['cloud_location']);
$snap = $client->getImageDetails($t['id']);
if ($snap) {
$add = true;
} else {
$excludedMissing++;
}
break;
case \SERVER_PLATFORMS::GCE:
$platform = PlatformFactory::NewPlatform(\SERVER_PLATFORMS::GCE);
/* @var $platform GoogleCEPlatformModule */
$client = $platform->getClient($env);
/* @var $client \Google_Service_Compute */
$projectId = $env->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID);
$snap = $client->images->get($projectId, str_replace($projectId . '/images/', '', $t['id']));
if ($snap) {
$add = true;
$t['architecture'] = 'x86_64';
} else {
$excludedMissing++;
}
break;
case \SERVER_PLATFORMS::EUCALYPTUS:
$snap = $env->eucalyptus($t['cloud_location'])->ec2->image->describe($t['id']);
if (count($snap)) {
$add = true;
$t['architecture'] = $snap->toArray()[0]['architecture'];
}
break;
default:
if (PlatformFactory::isOpenstack($t['platform'])) {
$snap = $env->openstack($t['platform'], $t['cloud_location'])->servers->getImage($t['id']);
if ($snap) {
$add = true;
$t['architecture'] = $snap->metadata->arch == 'x84-64' ? 'x84_64' : 'i386';
} else {
$excludedMissing++;
}
} else {
if (PlatformFactory::isCloudstack($t['platform'])) {
//.........这里部分代码省略.........
示例6: dashboardAction
public function dashboardAction()
{
$this->request->defineParams(array('farmId' => array('type' => 'int'), 'farmRoleId' => array('type' => 'int'), 'type'));
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
if ($this->getParam('farmRoleId')) {
$dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
if ($dbFarmRole->FarmID != $dbFarm->ID) {
throw new Exception("Role not found");
}
} elseif ($this->getParam('type')) {
foreach ($dbFarm->GetFarmRoles() as $sDbFarmRole) {
if ($sDbFarmRole->GetRoleObject()->hasBehavior($this->getParam('type'))) {
$dbFarmRole = $sDbFarmRole;
break;
}
}
if (!$dbFarmRole) {
throw new Exception("Role not found");
}
} else {
throw new Scalr_UI_Exception_NotFound();
}
$data = array('farmRoleId' => $dbFarmRole->ID, 'farmId' => $dbFarmRole->FarmID);
$data['dbType'] = $dbFarmRole->GetRoleObject()->getDbMsrBehavior();
if (!$data['dbType']) {
$this->response->failure("Unknown db type");
return;
}
switch ($data['dbType']) {
case ROLE_BEHAVIORS::MYSQL2:
case ROLE_BEHAVIORS::PERCONA:
case ROLE_BEHAVIORS::MARIADB:
$szrApiNamespace = Scalr_Net_Scalarizr_Client::NAMESPACE_MYSQL;
break;
case ROLE_BEHAVIORS::REDIS:
$szrApiNamespace = Scalr_Net_Scalarizr_Client::NAMESPACE_REDIS;
$data['extras'] = array(array('name' => 'Processes', 'value' => $dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::NUM_PROCESSES)), array('name' => 'Persistence type', 'value' => $dbFarmRole->GetSetting(Scalr_Db_Msr_Redis::PERSISTENCE_TYPE)));
break;
case ROLE_BEHAVIORS::POSTGRESQL:
$szrApiNamespace = Scalr_Net_Scalarizr_Client::NAMESPACE_POSTGRESQL;
break;
}
// Get PMA details for MySQL / Percona
if (in_array($data['dbType'], array(ROLE_BEHAVIORS::MYSQL, ROLE_BEHAVIORS::MYSQL2, ROLE_BEHAVIORS::PERCONA, ROLE_BEHAVIORS::MARIADB))) {
$data['pma'] = $this->getPmaDetails($dbFarmRole);
}
$behavior = Scalr_Role_Behavior::loadByName($data['dbType']);
$masterServer = $behavior->getMasterServer($dbFarmRole);
if ($masterServer) {
// Get Storage details
$data['storage'] = $this->getDbStorageStatus($masterServer, $data['dbType']);
}
// Get Access details and DNS endpoints
$data['accessDetails'] = $this->getDbAccessDetails($dbFarmRole);
$data['name'] = ROLE_BEHAVIORS::GetName($data['dbType']);
// Get data bundle info
$bundlesEnabled = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_ENABLED);
$lastActionTime = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_BUNDLE_LAST_TS"));
$data['bundles'] = array('history' => $this->db->GetAll("SELECT *, UNIX_TIMESTAMP(date) as date FROM services_db_backups_history WHERE `farm_role_id` = ? AND `operation` = ? ORDER BY id ASC", array($dbFarmRole->ID, 'bundle')), 'inProgress' => array('status' => (int) $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_IS_RUNNING), 'serverId' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_SERVER_ID)), 'last' => $lastActionTime ? Scalr_Util_DateTime::convertTz((int) $lastActionTime, 'd M Y \\a\\t H:i:s') : 'Never');
foreach ($data['bundles']['history'] as &$h) {
$h['date'] = Scalr_Util_DateTime::convertTz((int) $h['date'], 'd M Y \\a\\t H:i:s');
}
if ($bundlesEnabled) {
$period = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BUNDLE_EVERY);
if ($lastActionTime) {
$nextTime = $lastActionTime + $period * 3600;
}
$data['bundles']['next'] = !$nextTime || $nextTime < time() ? "Within 30 minutes" : Scalr_Util_DateTime::convertTz((int) $nextTime, 'd M Y \\a\\t H:i:s');
$data['bundles']['schedule'] = "Every {$period} hours";
} else {
$data['bundles']['next'] = " - ";
$data['bundles']['schedule'] = "Auto-snapshotting disabled";
}
// Get backups info
$lastActionTime = $dbFarmRole->GetSetting(Scalr_Db_Msr::getConstant("DATA_BACKUP_LAST_TS"));
$nextTime = false;
$backupsEnabled = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BACKUP_ENABLED);
$data['backups'] = array('history' => $this->db->GetAll("SELECT *, UNIX_TIMESTAMP(date) as date FROM services_db_backups_history WHERE `farm_role_id` = ? AND `operation` = ? ORDER BY id ASC", array($dbFarmRole->ID, 'backup')), 'inProgress' => array('status' => (int) $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING), 'serverId' => $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BACKUP_SERVER_ID)), 'last' => $lastActionTime ? Scalr_Util_DateTime::convertTz((int) $lastActionTime, 'd M Y \\a\\t H:i:s') : 'Never', 'supported' => !PlatformFactory::isCloudstack($dbFarmRole->Platform) && (!PlatformFactory::isOpenstack($dbFarmRole->Platform) || PlatformFactory::NewPlatform($dbFarmRole->Platform)->getConfigVariable(OpenstackPlatformModule::EXT_SWIFT_ENABLED, $this->getEnvironment(), false)));
foreach ($data['backups']['history'] as &$h) {
$h['date'] = Scalr_Util_DateTime::convertTz((int) $h['date'], 'd M Y \\a\\t H:i:s');
}
if ($backupsEnabled) {
$period = $dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_BACKUP_EVERY);
if ($lastActionTime) {
$nextTime = $lastActionTime + $period * 3600;
}
$data['backups']['next'] = !$nextTime || $nextTime < time() ? "Within 30 minutes" : Scalr_Util_DateTime::convertTz((int) $nextTime, 'd M Y \\a\\t H:i:s');
$data['backups']['schedule'] = "Every {$period} hours";
} else {
$data['backups']['next'] = " - ";
$data['backups']['schedule'] = "Auto-backups disabled";
}
/*
if ($dbFarmRole->GetSetting(Scalr_Db_Msr::DATA_STORAGE_ENGINE) == 'lvm') {
$data['noDataBundleForSlaves'] = ($dbFarmRole->GetSetting(Scalr_Role_DbMsrBehavior::ROLE_NO_DATA_BUNDLE_FOR_SLAVES)) ? true : false;
}
*/
$conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter');
foreach ($dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, SERVER_STATUS::PENDING))) as $dbServer) {
//.........这里部分代码省略.........
示例7: checkImage
//.........这里部分代码省略.........
} else {
if ($sn['rootDeviceType'] == 'instance-store') {
$this->type = 'instance-store';
}
}
if ($sn['virtualizationType'] == 'hvm') {
$this->type = $this->type . '-hvm';
}
foreach ($sn['blockDeviceMapping'] as $b) {
if ($b['deviceName'] == $sn['rootDeviceName'] && $b['ebs']) {
$this->size = $b['ebs']['volumeSize'];
}
}
}
} catch (Exception $e) {
return false;
}
break;
case SERVER_PLATFORMS::GCE:
try {
$platform = PlatformFactory::NewPlatform(SERVER_PLATFORMS::GCE);
/* @var $platform GoogleCEPlatformModule */
$client = $platform->getClient($env);
/* @var $client \Google_Service_Compute */
// for global images we use another projectId
$ind = strpos($this->id, '/global/');
if ($ind !== FALSE) {
$projectId = substr($this->id, 0, $ind);
$id = str_replace("{$projectId}/global/images/", '', $this->id);
} else {
$ind = strpos($this->id, '/images/');
if ($ind !== false) {
$projectId = substr($this->id, 0, $ind);
} else {
$projectId = $env->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID);
}
$id = str_replace("{$projectId}/images/", '', $this->id);
}
$snap = $client->images->get($projectId, $id);
if ($update) {
$this->name = $snap->name;
$this->size = $snap->diskSizeGb;
$this->architecture = 'x86_64';
}
} catch (Exception $e) {
return false;
}
break;
case SERVER_PLATFORMS::RACKSPACE:
try {
$client = \Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(RackspacePlatformModule::USERNAME, true, $this->cloudLocation), $env->getPlatformConfigValue(RackspacePlatformModule::API_KEY, true, $this->cloudLocation), $this->cloudLocation);
$snap = $client->getImageDetails($this->id);
if ($snap) {
if ($update) {
$this->name = $snap->image->name;
}
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
break;
default:
if (PlatformFactory::isOpenstack($this->platform)) {
try {
$snap = $env->openstack($this->platform, $this->cloudLocation)->servers->getImage($this->id);
if ($snap) {
if ($update) {
$this->name = $snap->name;
$this->size = $snap->metadata->instance_type_root_gb;
}
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
} else {
if (PlatformFactory::isCloudstack($this->platform)) {
try {
$snap = $env->cloudstack($this->platform)->template->describe(['templatefilter' => 'executable', 'id' => $this->id, 'zoneid' => $this->cloudLocation]);
if ($snap && isset($snap[0])) {
if ($update) {
$this->name = $snap[0]->name;
$this->size = ceil($snap[0]->size / (1024 * 1024 * 1024));
}
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
} else {
return false;
}
}
}
return true;
}
示例8: getUrl
/**
* Gets a normalized url for an each platform
*
* @param string $platform Cloud platform
* @return string Returns url
*/
public function getUrl($platform)
{
if (!isset($this->aUrl[$platform])) {
if ($platform == \SERVER_PLATFORMS::EC2 || $platform == \SERVER_PLATFORMS::GCE || $platform == \SERVER_PLATFORMS::AZURE) {
$value = '';
} else {
if (PlatformFactory::isOpenstack($platform)) {
$value = CloudLocation::normalizeUrl($this->env->keychain($platform)->properties[CloudCredentialsProperty::OPENSTACK_KEYSTONE_URL]);
} else {
if (PlatformFactory::isCloudstack($platform)) {
$value = CloudLocation::normalizeUrl($this->env->keychain($platform)->properties[CloudCredentialsProperty::CLOUDSTACK_API_URL]);
}
}
}
$this->aUrl[$platform] = $value;
}
return $this->aUrl[$platform];
}
示例9: xGetCloudServersListAction
/**
* @param string $platform
* @param string $cloudLocation
* @throws Exception
*/
public function xGetCloudServersListAction($platform, $cloudLocation)
{
if (!$this->environment->isPlatformEnabled($platform)) {
throw new Exception(sprintf('Cloud %s is not enabled for current environment', $platform));
}
$results = [];
$platformObj = PlatformFactory::NewPlatform($platform);
if ($platform == SERVER_PLATFORMS::GCE) {
$gce = $platformObj->getClient($this->environment);
$result = $gce->instances->listInstances($this->environment->keychain(SERVER_PLATFORMS::GCE)->properties[CloudCredentialsProperty::GCE_PROJECT_ID], $cloudLocation, []);
if (is_array($result->items)) {
foreach ($result->items as $server) {
if ($server->status != 'RUNNING') {
continue;
}
$ips = $platformObj->determineServerIps($gce, $server);
$itm = ['id' => $server->name, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $cloudLocation, 'isImporting' => false, 'isManaged' => false];
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(GCE_SERVER_PROPERTIES::SERVER_NAME, $server->name);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
}
} else {
if ($platform == SERVER_PLATFORMS::AZURE) {
// cloudLocation is resourceGroup
$t = $this->getEnvironment()->azure()->compute->virtualMachine->getList($this->getEnvironment()->keychain(SERVER_PLATFORMS::AZURE)->properties[CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $cloudLocation);
foreach ($t as $server) {
$itm = ['id' => $server->name, 'isImporting' => false, 'isManaged' => false];
$nicInfo = $server->properties->networkProfile->networkInterfaces[0]->id;
// get id and call
if (!empty($nicInfo->properties->ipConfigurations)) {
foreach ($nicInfo->properties->ipConfigurations as $ipConfig) {
$privateIp = $ipConfig->properties->privateIPAddress;
if ($ipConfig->properties->publicIPAddress) {
$publicIp = $ipConfig->properties->publicIPAddress->properties->ipAddress;
if ($publicIp) {
break;
}
}
}
}
$itm['localIp'] = $privateIp;
$itm['publicIp'] = $publicIp;
$itm['zone'] = $server->location;
$results[] = $itm;
}
} elseif (PlatformFactory::isOpenstack($platform)) {
$client = $this->environment->openstack($platform, $cloudLocation);
$r = $client->servers->list(true);
do {
foreach ($r as $server) {
if ($server->status != 'ACTIVE') {
continue;
}
$ips = $platformObj->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $cloudLocation, 'isImporting' => false, 'isManaged' => false, 'fullInfo' => $server);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
} while (false !== ($r = $r->getNextPage()));
} elseif (PlatformFactory::isCloudstack($platform)) {
$client = $this->environment->cloudstack($platform);
$platformObj = PlatformFactory::NewPlatform($platform);
$r = $client->instance->describe(array('zoneid' => $cloudLocation));
if (count($r) > 0) {
foreach ($r as $server) {
$ips = $platformObj->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $cloudLocation, 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
//.........这里部分代码省略.........
示例10: xGetPlatformInstanceTypesAction
/**
* xGetPlatformInstanceTypesAction
*
* @param string $platform The name of the cloud platform
* @param string $cloudLocation The cloud location
* @param string $envId optional The identifier of the environment
* @param string $effectiveDate optional The date on which prices should be applied YYYY-MM-DD
* @throws \Exception
*/
public function xGetPlatformInstanceTypesAction($platform, $cloudLocation, $envId = null, $effectiveDate = null)
{
list($curDate, $effectiveDate) = $this->handleEffectiveDate($effectiveDate);
$pm = PlatformFactory::NewPlatform($platform);
$env = null;
$url = '';
try {
if (!empty($envId)) {
$env = Scalr_Environment::init()->loadById($envId);
if (PlatformFactory::isOpenstack($platform)) {
$key = $platform . '.' . OpenstackPlatformModule::KEYSTONE_URL;
} else {
if (PlatformFactory::isCloudstack($platform)) {
$key = $platform . '.' . CloudstackPlatformModule::API_URL;
} else {
if ($platform == SERVER_PLATFORMS::EUCALYPTUS) {
$key = EucalyptusPlatformModule::EC2_URL;
$url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key, false, $cloudLocation));
} else {
throw new Exception('This action is not yet supported for the specified cloud platform.');
}
}
}
if (empty($url)) {
$url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key));
}
} else {
if ($platform == SERVER_PLATFORMS::EC2 || $platform == SERVER_PLATFORMS::GCE) {
$gcenvid = $this->getPlatformEnvId($platform);
$env = Scalr_Environment::init()->loadById($gcenvid);
}
}
} catch (Exception $e) {
if (stristr($e->getMessage(), 'not found')) {
//Tries to find url from the cloud_locations table
if (empty($url) && (PlatformFactory::isOpenstack($platform) || PlatformFactory::isCloudstack($platform))) {
$clEntity = CloudLocation::findOne([['platform' => $platform], ['cloudLocation' => $cloudLocation]], ['updated' => false]);
if ($clEntity instanceof CloudLocation) {
$url = $clEntity->url;
}
}
} else {
throw $e;
}
}
$result = $this->getTypesWithPrices($cloudLocation, $url, $pm, $platform, $effectiveDate, $env);
$this->response->data(['data' => $result]);
}
示例11: terminateAction
/**
* Terminates instance
*
* @param string $serverId UUID of the server
* @return ResultEnvelope
* @throws ApiErrorException
*/
public function terminateAction($serverId)
{
$server = $this->getServer($serverId);
$this->checkPermissions($server, Acl::PERM_FARMS_SERVERS);
if (in_array($server->status, [Server::STATUS_IMPORTING, Server::STATUS_TEMPORARY])) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_STATE, sprintf("The Server can't be terminated in %s state.", $server->status));
}
if ($server->platform == SERVER_PLATFORMS::EC2 && !empty($server->properties[EC2_SERVER_PROPERTIES::IS_LOCKED])) {
throw new ApiErrorException(409, ErrorMessage::ERR_LOCKED, "Server has disableAPITermination flag and can not be terminated.");
}
$object = $this->request->getJsonBody();
$force = isset($object->force) ? ServerAdapter::convertInputValue('boolean', $object->force) : false;
if ((PlatformFactory::isOpenstack($server->platform) || PlatformFactory::isCloudstack($server->platform)) && $force) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, sprintf("Force termination is not available for platform %s.", $server->platform));
}
if (!$server->terminate([Server::TERMINATE_REASON_MANUALLY_API, $this->getUser()->fullName], $force, $this->getUser())) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_STATE, sprintf("Server with id %s has already been terminated.", $serverId));
}
$this->response->setStatus(200);
return $this->result($this->adapter('server')->toData($server));
}
示例12: worker
//.........这里部分代码省略.........
if ($event == false) {
$doNotProcessMessage = true;
}
} elseif ($message instanceof Scalr_Messaging_Msg_RebootStart) {
$event = new RebootBeginEvent($dbserver);
} elseif ($message instanceof Scalr_Messaging_Msg_RebootFinish) {
if ($dbserver->status == \SERVER_STATUS::RESUMING) {
try {
// UPDATE IPs
$p = PlatformFactory::NewPlatform($dbserver->platform);
$ipaddresses = $p->GetServerIPAddresses($dbserver);
if ($ipaddresses['remoteIp'] && !$dbserver->remoteIp || $ipaddresses['localIp'] && !$dbserver->localIp) {
$dbserver->remoteIp = $update['remoteIp'] = $ipaddresses['remoteIp'];
if (!$dbserver->localIp) {
$update['localIp'] = $ipaddresses['localIp'] ? $ipaddresses['localIp'] : $message->localIp;
}
}
// Update type after resume on EC2
if ($dbserver->platform == \SERVER_PLATFORMS::EC2) {
$cacheKey = sprintf('%s:%s', $dbserver->envId, $dbserver->cloudLocation);
$type = $p->instancesListCache[$cacheKey][$dbserver->GetCloudServerID()]['type'];
if ($type != $dbserver->getType()) {
$dbserver->setType($type);
}
}
} catch (Exception $e) {
if (stristr($e->getMessage(), "AWS Error. Request DescribeInstances failed. Cannot establish connection to AWS server")) {
$doNotProcessMessage = true;
} else {
throw $e;
}
}
// Set cloudstack Static IP if needed
if (PlatformFactory::isCloudstack($dbserver->platform) && !$dbserver->remoteIp) {
$remoteIp = CloudstackHelper::getSharedIP($dbserver);
if ($remoteIp) {
$dbserver->remoteIp = $update['remoteIp'] = $remoteIp;
}
}
if (!$doNotProcessMessage) {
if (!empty($update)) {
$dbserver->update($update);
unset($update);
}
$event = new \ResumeCompleteEvent($dbserver);
}
} elseif ($dbserver->status == \SERVER_STATUS::SUSPENDED) {
//We need to wait for Poller to update status to RESUMING before processing this message
$doNotProcessMessage = true;
} elseif ($dbserver->status == \SERVER_STATUS::RUNNING) {
if (!$dbserver->localIp && $message->localIp) {
$dbserver->update(['localIp' => $message->localIp]);
}
$event = new RebootCompleteEvent($dbserver);
}
} elseif ($message instanceof Scalr_Messaging_Msg_BeforeHostUp) {
$event = new BeforeHostUpEvent($dbserver);
try {
$dbserver->updateTimelog('ts_bhu');
} catch (Exception $e) {
}
} elseif ($message instanceof Scalr_Messaging_Msg_BlockDeviceAttached) {
if ($dbserver->platform == SERVER_PLATFORMS::EC2) {
$aws = $dbserver->GetEnvironmentObject()->aws($dbserver->GetProperty(EC2_SERVER_PROPERTIES::REGION));
$instanceId = $dbserver->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
//The main goal of using filters there is to considerably decrease the size of the response.
示例13: getInstanceType
/**
* Returns instance type id
*
* @return mixed
*/
public function getInstanceType()
{
switch ($this->Platform) {
case SERVER_PLATFORMS::EC2:
$name = Entity\FarmRoleSetting::AWS_INSTANCE_TYPE;
break;
case SERVER_PLATFORMS::GCE:
$name = Entity\FarmRoleSetting::GCE_MACHINE_TYPE;
break;
case SERVER_PLATFORMS::RACKSPACE:
$name = Entity\FarmRoleSetting::RS_FLAVOR_ID;
break;
case SERVER_PLATFORMS::AZURE:
$name = Entity\FarmRoleSetting::SETTING_AZURE_VM_SIZE;
break;
default:
if (PlatformFactory::isOpenstack($this->Platform)) {
$name = Entity\FarmRoleSetting::OPENSTACK_FLAVOR_ID;
} else {
if (PlatformFactory::isCloudstack($this->Platform)) {
$name = Entity\FarmRoleSetting::CLOUDSTACK_SERVICE_OFFERING_ID;
}
}
}
return $this->GetSetting($name);
}
示例14: xGetPlatformInstanceTypesAction
/**
* xGetPlatformInstanceTypesAction
*
* @param string $platform The name of the cloud platform
* @param string $cloudLocation The cloud location
* @param string $envId optional The identifier of the environment
* @param string $effectiveDate optional The date on which prices should be applied YYYY-MM-DD
* @throws \Exception
*/
public function xGetPlatformInstanceTypesAction($platform, $cloudLocation, $envId = null, $effectiveDate = null)
{
list($curDate, $effectiveDate) = $this->handleEffectiveDate($effectiveDate);
$pm = PlatformFactory::NewPlatform($platform);
$env = null;
$url = '';
if (!empty($envId)) {
$env = Scalr_Environment::init()->loadById($envId);
//TODO the key should be retrieved from the method which is provisioned by interface
if (PlatformFactory::isOpenstack($platform)) {
$key = $platform . '.' . OpenstackPlatformModule::KEYSTONE_URL;
} else {
if (PlatformFactory::isCloudstack($platform)) {
$key = $platform . '.' . CloudstackPlatformModule::API_URL;
} else {
if ($platform == SERVER_PLATFORMS::EUCALYPTUS) {
$key = EucalyptusPlatformModule::EC2_URL;
$url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key, false, $cloudLocation));
} else {
throw new Exception('This action is not yet supported for the specified cloud platform.');
}
}
}
if (empty($url)) {
$url = $this->getContainer()->analytics->prices->normalizeUrl($env->getPlatformConfigValue($key));
}
}
$result = $this->getTypesWithPrices($cloudLocation, $url, $pm, $platform, $effectiveDate, $env);
$this->response->data(['data' => $result]);
}
示例15: getBaseConfiguration
public function getBaseConfiguration(DBServer $dbServer, $isHostInit = false, $onlyBase = false)
{
$configuration = new stdClass();
$dbFarmRole = $dbServer->GetFarmRoleObject();
//Storage
if (!$onlyBase) {
try {
if ($dbFarmRole) {
$storage = new FarmRoleStorage($dbFarmRole);
$volumes = $storage->getVolumesConfigs($dbServer, $isHostInit);
if (!empty($volumes)) {
$configuration->volumes = $volumes;
}
}
} catch (Exception $e) {
$this->logger->error(new FarmLogMessage($dbServer->farmId, "Cannot init storage: {$e->getMessage()}"));
}
}
// Base
try {
if ($dbFarmRole) {
$scriptingLogTimeout = $dbFarmRole->GetSetting(self::ROLE_BASE_KEEP_SCRIPTING_LOGS_TIME);
if (!$scriptingLogTimeout) {
$scriptingLogTimeout = 3600;
}
$configuration->base = new stdClass();
$configuration->base->keepScriptingLogsTime = $scriptingLogTimeout;
$configuration->base->abortInitOnScriptFail = (int) $dbFarmRole->GetSetting(self::ROLE_BASE_ABORT_INIT_ON_SCRIPT_FAIL);
$configuration->base->disableFirewallManagement = (int) $dbFarmRole->GetSetting(self::ROLE_BASE_DISABLE_FIREWALL_MANAGEMENT);
$configuration->base->rebootAfterHostinitPhase = (int) $dbFarmRole->GetSetting(self::ROLE_BASE_REBOOT_AFTER_HOSTINIT_PHASE);
$configuration->base->resumeStrategy = PlatformFactory::NewPlatform($dbFarmRole->Platform)->getResumeStrategy();
//Dev falgs for our
if (Scalr::isHostedScalr() && $dbServer->envId == 3414) {
$configuration->base->unionScriptExecutor = 1;
}
$governance = new Scalr_Governance($dbFarmRole->GetFarmObject()->EnvID);
if ($governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_HOSTNAME_FORMAT)) {
$hostNameFormat = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_HOSTNAME_FORMAT);
} else {
$hostNameFormat = $dbFarmRole->GetSetting(self::ROLE_BASE_HOSTNAME_FORMAT);
}
$configuration->base->hostname = !empty($hostNameFormat) ? $dbServer->applyGlobalVarsToValue($hostNameFormat) : '';
if ($configuration->base->hostname != '') {
$dbServer->SetProperty(self::SERVER_BASE_HOSTNAME, $configuration->base->hostname);
}
$apiPort = null;
$messagingPort = null;
if (!PlatformFactory::isCloudstack($dbFarmRole->Platform)) {
$apiPort = $dbFarmRole->GetSetting(self::ROLE_BASE_API_PORT);
$messagingPort = $dbFarmRole->GetSetting(self::ROLE_BASE_MESSAGING_PORT);
}
$configuration->base->apiPort = $apiPort ? $apiPort : 8010;
$configuration->base->messagingPort = $messagingPort ? $messagingPort : 8013;
}
//Update settings
$updateSettings = $dbServer->getScalarizrRepository();
$configuration->base->update = new stdClass();
foreach ($updateSettings as $k => $v) {
$configuration->base->update->{$k} = $v;
}
} catch (Exception $e) {
}
return $configuration;
}