示例#1
0
 public function xGetFlavorsAction()
 {
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Rackspace::USERNAME, true, $this->getParam('cloudLocation')), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Rackspace::API_KEY, true, $this->getParam('cloudLocation')), $this->getParam('cloudLocation'));
     $data = array();
     foreach ($cs->listFlavors(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));
 }
示例#2
0
 public function xGetFlavorsAction()
 {
     //TODO: check correct platform name
     $ccProps = $this->environment->cloudCredentials("{$this->getParam('cloudLocation')}." . SERVER_PLATFORMS::RACKSPACE)->properties;
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], $this->getParam('cloudLocation'));
     $data = array();
     foreach ($cs->listFlavors(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));
 }
示例#3
0
 public function xListLimitsAction()
 {
     $cloudLocation = $this->getParam('cloudLocation');
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($this->environment->getPlatformConfigValue(Modules_Platforms_Rackspace::USERNAME, true, $cloudLocation), $this->environment->getPlatformConfigValue(Modules_Platforms_Rackspace::API_KEY, true, $cloudLocation), $cloudLocation);
     $limits = $cs->limits();
     $l = array();
     foreach ($limits->limits->rate as $limit) {
         $limit->resetTime = Scalr_Util_DateTime::convertTz(date("c", $limit->resetTime));
         $l[] = (array) $limit;
     }
     $response = $this->buildResponseFromData($l, array());
     $this->response->data($response);
 }
示例#4
0
 public function xListLimitsAction()
 {
     //TODO: check correct platform name
     $ccProps = $this->environment->cloudCredentials($this->getParam('cloudLocation') . SERVER_PLATFORMS::RACKSPACE)->properties;
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], $this->getParam('cloudLocation'));
     $limits = $cs->limits();
     $l = array();
     foreach ($limits->limits->rate as $limit) {
         $limit->resetTime = Scalr_Util_DateTime::convertTz(date("c", $limit->resetTime));
         $l[] = (array) $limit;
     }
     $response = $this->buildResponseFromData($l, array());
     $this->response->data($response);
 }
示例#5
0
 private function getCfSignedUrl($path, $location, $platform)
 {
     $expires = time() + 3600;
     $platform = PlatformFactory::NewPlatform($platform);
     $user = $platform->getConfigVariable(RackspacePlatformModule::USERNAME, $this->environment, true, $location);
     $key = $platform->getConfigVariable(RackspacePlatformModule::API_KEY, $this->environment, true, $location);
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($user, $key, $location);
     $auth = $cs->authToReturn();
     $stringToSign = "GET\n\n\n{$expires}\n/{$path}";
     $signature = urlencode(base64_encode(hash_hmac("sha1", utf8_encode($stringToSign), $key, true)));
     $authenticationParams = "temp_url_sig={$signature}&temp_url_expires={$expires}";
     $link = "{$auth['X-Cdn-Management-Url']}/{$path}?{$authenticationParams}";
     return $link;
 }
 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);
     }
 }
示例#7
0
 /**
  * @return Scalr_Service_Cloud_Rackspace_CS
  */
 private function getRsClient(Scalr_Environment $environment, $cloudLocation)
 {
     return Scalr_Service_Cloud_Rackspace::newRackspaceCS($environment->getPlatformConfigValue(self::USERNAME, true, $cloudLocation), $environment->getPlatformConfigValue(self::API_KEY, true, $cloudLocation), $cloudLocation);
 }
 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'])) {
                                 $snap = $env->cloudstack($t['platform'])->template->describe(['templatefilter' => 'executable', 'id' => $t['id'], 'zoneid' => $t['cloud_location']]);
                                 if ($snap) {
                                     if (isset($snap[0])) {
                                         $add = true;
                                     }
                                 } else {
                                     $excludedMissing++;
                                 }
                             } else {
                                 $this->console->warning('Unknown platform: %s', $t['platform']);
                             }
                         }
                 }
                 if ($add) {
                     $image = new Image();
                     $image->id = $t['id'];
                     $image->envId = $t['env_id'];
                     $image->bundleTaskId = $t['bundle_task_id'];
                     $image->platform = $t['platform'];
                     $image->cloudLocation = $t['cloud_location'];
                     $image->createdById = $t['created_by_id'];
                     $image->createdByEmail = $t['created_by_email'];
                     $image->architecture = $t['architecture'] ? $t['architecture'] : 'x86_64';
                     $image->isDeprecated = 0;
                     $image->source = $t['bundle_task_id'] ? 'BundleTask' : 'Manual';
                     $image->type = $t['type'];
                     $image->status = Image::STATUS_ACTIVE;
                     $image->agentVersion = $t['agent_version'];
                     $image->save();
                 } else {
                     $excludedMissing++;
                 }
             } catch (\Exception $e) {
                 if (strpos($e->getMessage(), 'The resource could not be found') !== FALSE) {
                     $excludedMissing++;
                 } else {
                     if (strpos($e->getMessage(), 'The requested URL / was not found on this server.') !== FALSE) {
                         $excludedMissing++;
                     } else {
                         if (strpos($e->getMessage(), 'Not Found') !== FALSE) {
                             $excludedMissing++;
                         } else {
                             if (strpos($e->getMessage(), 'was not found') !== FALSE) {
                                 $excludedMissing++;
                             } else {
                                 if (strpos($e->getMessage(), 'Bad username or password') !== FALSE) {
                                     $excludedMissing++;
                                 } else {
                                     if (strpos($e->getMessage(), 'unable to verify user credentials and/or request signature') !== FALSE) {
                                         $excludedMissing++;
                                     } else {
                                         if (strpos($e->getMessage(), 'OpenStack error. Image not found.') !== FALSE) {
                                             $excludedMissing++;
                                         } else {
                                             if (strpos($e->getMessage(), 'Neither api key nor password was provided for the OpenStack config.') !== FALSE) {
                                                 $excludedMissing++;
                                             } else {
                                                 $this->console->warning('SnapshotId: %s, envId: %d, error: %s', $t['id'], $t['env_id'], $e->getMessage());
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->console->notice('Found %d records', $allRecords);
     $this->console->notice('Excluded %d images because of null cloud_location', $excludedCL);
     $this->console->notice('Excluded %d missed images', $excludedMissing);
 }
示例#9
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->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('redhat', 'oel', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->save();
     }
     if ($dbserver->status == SERVER_STATUS::IMPORTING) {
         if (!$dbserver->remoteIp || !$dbserver->localIp) {
             if (!$dbserver->remoteIp && $message->remoteIp && $dbserver->platform != SERVER_PLATFORMS::IDCF) {
                 $dbserver->remoteIp = $message->remoteIp;
             }
             if (!$dbserver->localIp && $message->localIp) {
                 $dbserver->localIp = $message->localIp;
             }
             if (!$message->behaviour) {
                 $message->behaviour = array('base');
             }
             if ((!$dbserver->remoteIp || $dbserver->localIp == $dbserver->remoteIp) && $message->messageIpAddress != $dbserver->remoteIp) {
                 $dbserver->remoteIp = $message->messageIpAddress;
             }
         }
         if (count($message->behaviour) == 1 && $message->behaviour[0] == ROLE_BEHAVIORS::CHEF) {
             $message->behaviour[] = ROLE_BEHAVIORS::BASE;
         }
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR, @implode(",", $message->behaviour));
         $dbserver->save();
         $importVersion = $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_VERSION);
         if ($importVersion == 2) {
             $dbserver->SetProperties(array(SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
         } else {
             if ($dbserver->isOpenstack()) {
                 $env = $dbserver->GetEnvironmentObject();
                 $os = $env->openstack($dbserver->platform, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
                 $csServer = null;
                 $list = $os->servers->list(true);
                 do {
                     foreach ($list as $_tmp) {
                         $ipaddresses = array();
                         if (!is_array($_tmp->addresses)) {
                             $_tmp->addresses = (array) $_tmp->addresses;
                         }
                         foreach ($_tmp->addresses as $net => $addresses) {
                             foreach ($addresses as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if ($_tmp->accessIPv4) {
                             array_push($ipaddresses, $_tmp->accessIPv4);
                         }
                         if (in_array($dbserver->localIp, $ipaddresses) || in_array($dbserver->remoteIp, $ipaddresses)) {
                             $osServer = $_tmp;
                         }
                     }
                 } while (false !== ($list = $list->getNextPage()));
                 if (!$osServer) {
                     $this->logger->error(sprintf("Server not found on Openstack (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $dbserver->remoteIp, $dbserver->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));
             } elseif ($dbserver->isCloudstack()) {
                 $dbserver->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID => $message->cloudstack->instanceId, CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $message->cloudstack->availZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
             } else {
                 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::GCE:
                         $dbserver->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $message->{$dbserver->platform}->cloudLocation, GCE_SERVER_PROPERTIES::SERVER_ID => $message->{$dbserver->platform}->serverId, GCE_SERVER_PROPERTIES::SERVER_NAME => $message->{$dbserver->platform}->serverName, GCE_SERVER_PROPERTIES::MACHINE_TYPE => $message->{$dbserver->platform}->machineType, 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::RACKSPACE:
                         $env = $dbserver->GetEnvironmentObject();
                         $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(RackspacePlatformModule::USERNAME, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $env->getPlatformConfigValue(RackspacePlatformModule::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;
                 }
             }
         }
         //TODO: search for existing bundle task
         // Bundle image
         $creInfo = new ServerSnapshotCreateInfo($dbserver, $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
         $bundleTask = BundleTask::Create($creInfo);
         $bundleTask->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('oel', 'redhat', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->setDate("started");
         $bundleTask->createdByEmail = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_EMAIL);
         $bundleTask->createdById = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_ID);
         if ($importVersion == 2) {
             $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::ESTABLISHING_COMMUNICATION;
         }
         $bundleTask->Save();
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     }
 }
示例#10
0
 /**
  * {@inheritdoc}
  * @see PlatformModuleInterface::getImageInfo()
  */
 public function getImageInfo(\Scalr_Environment $environment, $cloudLocation, $imageId)
 {
     $ccProps = $environment->cloudCredentials("{$cloudLocation}." . SERVER_PLATFORMS::RACKSPACE)->properties;
     $client = \Scalr_Service_Cloud_Rackspace::newRackspaceCS($ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], $cloudLocation);
     $snap = $client->getImageDetails($imageId);
     return $snap ? ["name" => $snap->image->name] : [];
 }
示例#11
0
 /**
  * Check if image exists
  *
  * @param bool $update on true update name, size, status from cloud information (you should call save manually)
  * @return bool
  */
 public function checkImage($update = true)
 {
     if (!$this->envId) {
         return true;
     }
     $env = Scalr_Environment::init()->loadById($this->envId);
     switch ($this->platform) {
         case SERVER_PLATFORMS::EC2:
             try {
                 $snap = $env->aws($this->cloudLocation)->ec2->image->describe($this->id);
                 if ($snap->count() == 0) {
                     return false;
                 }
                 if ($update) {
                     $sn = $snap->get(0)->toArray();
                     $this->name = $sn['name'];
                     $this->architecture = $sn['architecture'];
                     if ($sn['rootDeviceType'] == 'ebs') {
                         $this->type = 'ebs';
                     } 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;
 }
示例#12
0
文件: Backups.php 项目: mheydt/scalr
 private function getCfSignedUrl($path, $location, $platform)
 {
     $expires = time() + 3600;
     $ccProps = $this->environment->cloudCredentials("{$location}." . $platform)->properties;
     $user = $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME];
     $key = $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY];
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($user, $key, $location);
     $auth = $cs->authToReturn();
     $stringToSign = "GET\n\n\n{$expires}\n/{$path}";
     $signature = urlencode(base64_encode(hash_hmac("sha1", utf8_encode($stringToSign), $key, true)));
     $authenticationParams = "temp_url_sig={$signature}&temp_url_expires={$expires}";
     $link = "{$auth['X-Cdn-Management-Url']}/{$path}?{$authenticationParams}";
     return $link;
 }