/** * * @param string $platform (From SERVER_PLATFORMS class) * @param integer $farmid * @param integer $farm_roleid * @param integer $index * @return void */ 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::NIMBULA: break; case SERVER_PLATFORMS::EUCALYPTUS: $this->SetProperties(array(EUCA_SERVER_PROPERTIES::REGION => $DBFarmRole->CloudLocation)); break; case SERVER_PLATFORMS::RACKSPACE: $this->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::DATACENTER => $DBFarmRole->CloudLocation)); break; 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; } } //TODO: $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.20.0')); } else { $this->SetProperties(array(SERVER_PROPERTIES::SZR_VESION => '0.20.0')); } }
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(Modules_Platforms_GoogleCE::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_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 (PlatformFactory::isOpenstack($this->getParam('platform'))) { $client = $this->environment->openstack($this->getParam('platform'), $this->getParam('cloudLocation')); $r = $client->servers->list(true); 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; } } elseif (PlatformFactory::isCloudstack($this->getParam('platform'))) { $client = Scalr_Service_Cloud_Cloudstack::newCloudstack($platform->getConfigVariable(Modules_Platforms_Cloudstack::API_URL, $this->environment), $platform->getConfigVariable(Modules_Platforms_Cloudstack::API_KEY, $this->environment), $platform->getConfigVariable(Modules_Platforms_Cloudstack::SECRET_KEY, $this->environment), $this->getParam('platform')); $platform = PlatformFactory::NewPlatform($this->getParam('platform')); $r = $client->listVirtualMachines(null, $this->getParam('cloudLocation')); 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; $r = $client->instance->describe(); 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; } $itm = array('id' => $instance->instanceId, 'localIp' => $instance->privateIpAddress, 'publicIp' => $instance->ipAddress, 'zone' => $instance->placement->availabilityZone, 'isImporting' => false, 'isManaged' => false); //Check is instance already importing try { $dbServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instance->instanceId); 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; } } } } $this->response->data(array('data' => $results)); }
public function isCloudstack() { return PlatformFactory::isCloudstack($this->platform); }