Exemplo n.º 1
0
 public function xGetFlavorsAction()
 {
     $os = Scalr_Service_Cloud_Openstack::newNovaCC($this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Openstack::API_URL, true, $this->getParam('cloudLocation')), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Openstack::USERNAME, true, $this->getParam('cloudLocation')), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Openstack::API_KEY, true, $this->getParam('cloudLocation')), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Openstack::PROJECT_NAME, true, $this->getParam('cloudLocation')));
     $data = array();
     foreach ($os->flavorsList(true)->flavors as $flavor) {
         $data[] = array('id' => $flavor->id, 'name' => sprintf('RAM: %s MB Disk: %s GB', $flavor->ram, $flavor->disk));
     }
     $this->response->data(array('data' => $data));
 }
Exemplo n.º 2
0
 private function onHello($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::TEMPORARY) {
         $bundleTask = BundleTask::LoadById($dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID));
         $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PENDING;
         $bundleTask->Log("Received Hello message from scalarizr on server. Creating image");
         $bundleTask->save();
     }
     if ($dbserver->status == SERVER_STATUS::IMPORTING) {
         switch ($dbserver->platform) {
             case SERVER_PLATFORMS::EC2:
                 $dbserver->SetProperties(array(EC2_SERVER_PROPERTIES::AMIID => $message->awsAmiId, EC2_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EC2_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EC2_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, EC2_SERVER_PROPERTIES::REGION => substr($message->awsAvailZone, 0, -1), SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::EUCALYPTUS:
                 $dbserver->SetProperties(array(EUCA_SERVER_PROPERTIES::EMIID => $message->awsAmiId, EUCA_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EUCA_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EUCA_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::NIMBULA:
                 $dbserver->SetProperties(array(NIMBULA_SERVER_PROPERTIES::NAME => $message->serverName, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::CLOUDSTACK:
                 $dbserver->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID => $message->cloudstack->instanceId, CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $message->cloudstack->availZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::RACKSPACE:
                 $env = $dbserver->GetEnvironmentObject();
                 $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(Modules_Platforms_Rackspace::USERNAME, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $env->getPlatformConfigValue(Modules_Platforms_Rackspace::API_KEY, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
                 $csServer = null;
                 $list = $cs->listServers(true);
                 if ($list) {
                     foreach ($list->servers as $_tmp) {
                         if ($_tmp->addresses->public && in_array($message->remoteIp, $_tmp->addresses->public)) {
                             $csServer = $_tmp;
                         }
                     }
                 }
                 if (!$csServer) {
                     $this->logger->error(sprintf("Server not found on CloudServers (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::SERVER_ID => $csServer->id, RACKSPACE_SERVER_PROPERTIES::NAME => $csServer->name, RACKSPACE_SERVER_PROPERTIES::IMAGE_ID => $csServer->imageId, RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID => $csServer->flavorId, RACKSPACE_SERVER_PROPERTIES::HOST_ID => $csServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::OPENSTACK:
                 $env = $dbserver->GetEnvironmentObject();
                 $os = Scalr_Service_Cloud_Openstack::newNovaCC($env->getPlatformConfigValue(Modules_Platforms_Openstack::API_URL, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::USERNAME, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::API_KEY, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::PROJECT_NAME, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)));
                 $csServer = null;
                 $list = $os->serversList(true);
                 if ($list) {
                     foreach ($list->servers as $_tmp) {
                         $ipaddresses = array();
                         if ($_tmp->addresses->private) {
                             foreach ($_tmp->addresses->private as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if ($_tmp->addresses->internet) {
                             foreach ($_tmp->addresses->internet as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if (in_array($message->localIp, $ipaddresses) || in_array($message->remoteIp, $ipaddresses)) {
                             $osServer = $_tmp;
                         }
                     }
                 }
                 if (!$osServer) {
                     $this->logger->error(sprintf("Server not found on Openstack (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::SERVER_ID => $osServer->id, OPENSTACK_SERVER_PROPERTIES::NAME => $osServer->name, OPENSTACK_SERVER_PROPERTIES::IMAGE_ID => $osServer->image->id, OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID => $osServer->flavor->id, OPENSTACK_SERVER_PROPERTIES::HOST_ID => $osServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
         }
         // Bundle image
         $creInfo = new ServerSnapshotCreateInfo($dbserver, $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
         $bundleTask = BundleTask::Create($creInfo);
     }
 }
Exemplo n.º 3
0
 /**
  * @return Scalr_Service_Cloud_Openstack_v1_1_Client
  */
 private function getOsClient(Scalr_Environment $environment, $cloudLocation)
 {
     return Scalr_Service_Cloud_Openstack::newNovaCC($environment->getPlatformConfigValue(self::API_URL, true, $cloudLocation), $environment->getPlatformConfigValue(self::USERNAME, true, $cloudLocation), $environment->getPlatformConfigValue(self::API_KEY, true, $cloudLocation), $environment->getPlatformConfigValue(self::PROJECT_NAME, true, $cloudLocation));
 }