Example #1
0
 function _testAuthorizeSecurityGroupIngress()
 {
     $IpPermissionSet = new IpPermissionSetType();
     $IpPermissionSet->AddItem("tcp", "80", "80", null, array("0.0.0.0/0"));
     $res = $this->AmazonEC2->AuthorizeSecurityGroupIngress($this->AWSAccountID, "testGroup", $IpPermissionSet);
     $this->assertTrue($res->return === true, "AuthorizeSecurityGroupIngress returned true");
 }
Example #2
0
 private function GetServerSecurityGroupsList(DBServer $DBServer, $EC2Client)
 {
     // Add default security group
     $retval = array('default');
     if ($DBServer->farmRoleId) {
         $dbFarmRole = $DBServer->GetFarmRoleObject();
         $sgList = trim($dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_SG_LIST));
         if ($sgList) {
             $sgList = explode(",", $sgList);
             foreach ($sgList as $sg) {
                 if ($sg != '') {
                     array_push($retval, trim($sg));
                 }
             }
         }
     }
     try {
         $aws_sgroups_list_t = $EC2Client->DescribeSecurityGroups();
         $aws_sgroups_list_t = $aws_sgroups_list_t->securityGroupInfo->item;
         if ($aws_sgroups_list_t instanceof stdClass) {
             $aws_sgroups_list_t = array($aws_sgroups_list_t);
         }
         $aws_sgroups = array();
         foreach ($aws_sgroups_list_t as $sg) {
             $aws_sgroups[strtolower($sg->groupName)] = $sg;
         }
         unset($aws_sgroups_list_t);
     } catch (Exception $e) {
         throw new Exception("GetServerSecurityGroupsList failed: {$e->getMessage()}");
     }
     /**** Security group for role builder ****/
     if ($DBServer->status == SERVER_STATUS::TEMPORARY) {
         if (!$aws_sgroups['scalr-rb-system']) {
             try {
                 $EC2Client->CreateSecurityGroup('scalr-rb-system', _("Security group for Roles Builder"));
             } catch (Exception $e) {
                 throw new Exception("GetServerSecurityGroupsList failed: {$e->getMessage()}");
             }
             $IpPermissionSet = new IpPermissionSetType();
             $group_rules = array(array('rule' => 'tcp:22:22:0.0.0.0/0'), array('rule' => 'tcp:8013:8013:0.0.0.0/0'), array('rule' => 'udp:8014:8014:0.0.0.0/0'), array('rule' => 'icmp:-1:-1:0.0.0.0/0'));
             foreach ($group_rules as $rule) {
                 $group_rule = explode(":", $rule["rule"]);
                 $IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($group_rule[3]));
             }
             // Create security group
             $EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'scalr-rb-system', $IpPermissionSet);
         }
         array_push($retval, 'scalr-rb-system');
         return $retval;
     }
     /**********************************/
     // Add Role security group
     $role_sec_group = CONFIG::$SECGROUP_PREFIX . $DBServer->GetFarmRoleObject()->GetRoleObject()->name;
     $partent_sec_group = CONFIG::$SECGROUP_PREFIX . $DBServer->GetFarmRoleObject()->GetRoleObject()->getRoleHistory();
     $new_role_sec_group = "scalr-role." . $DBServer->GetFarmRoleObject()->ID;
     /****
      * SCALR IP POOL SECURITY GROUP
      */
     $scalrSecuritySettings = @parse_ini_file(APPPATH . '/etc/security.ini', true);
     if (!$aws_sgroups[$scalrSecuritySettings['ec2']['security_group_name']]) {
         try {
             $EC2Client->CreateSecurityGroup($scalrSecuritySettings['ec2']['security_group_name'], "Security rules needed by Scalr");
         } catch (Exception $e) {
             throw new Exception("GetServerSecurityGroupsList failed on scalr.ip-pool: {$e->getMessage()}");
         }
         $sRules = array(array('rule' => 'tcp:8008:8013:0.0.0.0/0'), array('rule' => 'udp:8014:8014:0.0.0.0/0'), array('rule' => 'tcp:3306:3306:0.0.0.0/0'));
         $IpPermissionSet = new IpPermissionSetType();
         foreach ($scalrSecuritySettings['ip-pool'] as $name => $ip) {
             foreach ($sRules as $rule) {
                 $group_rule = explode(":", $rule["rule"]);
                 $IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($ip));
             }
         }
         // Create security group
         $EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), $scalrSecuritySettings['ec2']['security_group_name'], $IpPermissionSet);
     }
     array_push($retval, $scalrSecuritySettings['ec2']['security_group_name']);
     /**********************************************/
     if ($aws_sgroups[strtolower($role_sec_group)]) {
         // OLD System. scalr.%ROLENAME% . Nothing to do
         array_push($retval, $role_sec_group);
     } else {
         if ($aws_sgroups[strtolower($new_role_sec_group)]) {
             // NEW System. scalr-role.%FARM_ROLE_ID% . Nothing to do
             array_push($retval, $new_role_sec_group);
         } else {
             try {
                 $EC2Client->CreateSecurityGroup($new_role_sec_group, sprintf("Security group for FarmRoleID #%s on FarmID #%s", $DBServer->GetFarmRoleObject()->ID, $DBServer->farmId));
             } catch (Exception $e) {
                 throw new Exception("GetServerSecurityGroupsList failed: {$e->getMessage()}");
             }
             $IpPermissionSet = new IpPermissionSetType();
             $group_rules = $DBServer->GetFarmRoleObject()->GetRoleObject()->getSecurityRules();
             //
             // Check parent security group
             //
             if (count($group_rules) == 0) {
                 $group_rules = array(array('rule' => 'tcp:22:22:0.0.0.0/0'), array('rule' => 'icmp:-1:-1:0.0.0.0/0'));
                 if ($DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                     $group_rules[] = array('rule' => 'tcp:3306:3306:0.0.0.0/0');
                 }
                 if ($DBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::CASSANDRA)) {
                     $group_rules[] = array('rule' => 'tcp:7000:7000:0.0.0.0/0');
                     $group_rules[] = array('rule' => 'tcp:9160:9160:0.0.0.0/0');
                 }
                 foreach (Scalr_Role_Behavior::getListForFarmRole($DBServer->GetFarmRoleObject()) as $bObj) {
                     $bRules = $bObj->getSecurityRules();
                     foreach ($bRules as $r) {
                         if ($r) {
                             $group_rules[] = array('rule' => $r);
                         }
                     }
                 }
             }
             foreach ($group_rules as $rule) {
                 $group_rule = explode(":", $rule["rule"]);
                 $IpPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($group_rule[3]));
             }
             //Create SG rule to enable communication between instances inside this role
             $IpPermissionSet->AddItem('tcp', 0, 65535, array('userId' => $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'groupName' => $new_role_sec_group));
             $IpPermissionSet->AddItem('udp', 0, 65535, array('userId' => $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), 'groupName' => $new_role_sec_group));
             // Create security group
             $EC2Client->AuthorizeSecurityGroupIngress($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::ACCOUNT_ID), $new_role_sec_group, $IpPermissionSet);
             $DBServer->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_AWS_SECURITY_GROUP, $new_role_sec_group);
             array_push($retval, $new_role_sec_group);
         }
     }
     return $retval;
 }
 function handleWork($serverId)
 {
     try {
         $dbserver = DBServer::LoadByID($serverId);
         if ($dbserver->farmId) {
             if ($dbserver->GetFarmObject()->Status == FARM_STATUS::TERMINATED) {
                 throw new ServerNotFoundException("");
             }
         }
     } catch (Exception $e) {
         $this->db->Execute("DELETE FROM messages WHERE server_id=? AND `type`='in'", array($serverId));
         return;
     }
     $rs = $this->db->Execute("SELECT * FROM messages \n            \t\tWHERE server_id = ? AND type = ? AND status = ? \n            \t\tORDER BY id ASC", array($serverId, "in", MESSAGE_STATUS::PENDING));
     while ($row = $rs->FetchRow()) {
         try {
             $message = $this->serializer->unserialize($row["message"]);
             $event = null;
             // Update scalarizr package version
             if ($message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]) {
                 $dbserver->SetProperty(SERVER_PROPERTIES::SZR_VESION, $message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]);
             }
             if ($message->meta[Scalr_Messaging_MsgMeta::SZR_UPD_CLIENT_VERSION]) {
                 $dbserver->SetProperty(SERVER_PROPERTIES::SZR_UPD_CLIENT_VERSION, $message->meta[Scalr_Messaging_MsgMeta::SZR_UPD_CLIENT_VERSION]);
             }
             try {
                 if ($message instanceof Scalr_Messaging_Msg_OperationResult) {
                     $this->db->Execute("UPDATE server_operations SET `status` = ? WHERE id = ?", array($message->status, $message->id));
                     if ($message->status == 'error') {
                         if ($message->name == 'Initialization') {
                             $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IS_INIT_FAILED, 1);
                         }
                         if ($message->error) {
                             $msg = $message->error->message;
                             $trace = $message->error->trace;
                             $handler = $message->error->handler;
                         }
                         $this->db->Execute("INSERT INTO server_operation_progress SET \n\t\t\t\t\t\t\t\t\t`operation_id` = ?,\n\t\t\t\t\t\t\t\t\t`timestamp` = ?,\n\t\t\t\t\t\t\t\t\t`phase` = ?,\n\t\t\t\t\t\t\t\t\t`step` = ?,\n\t\t\t\t\t\t\t\t\t`status` = ?,\n\t\t\t\t\t\t\t\t\t`message`= ?,\n\t\t\t\t\t\t\t\t\t`trace` = ?,\n\t\t\t\t\t\t\t\t\t`handler` = ?,\n\t\t\t\t\t\t\t\t\t`progress` = ?,\n\t\t\t\t\t\t\t\t\t`stepno` = ? \n\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE status = ?, progress = ?, trace = ?, handler = ?, message = ?\n\t\t\t\t\t\t\t\t", array($message->id, $message->getTimestamp(), $message->phase, $message->step, $message->status, $msg, $trace, $handler, $message->progress, $message->stepno, $message->status, $message->progress, $trace, $handler, $msg));
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Win_HostDown) {
                     $status = PlatformFactory::NewPlatform($dbserver->platform)->GetServerRealStatus($dbserver);
                     if ($status->isRunning()) {
                         $event = new RebootBeginEvent($dbserver);
                     } else {
                         $event = new HostDownEvent($dbserver);
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Win_PrepareBundleResult) {
                     try {
                         $bundleTask = BundleTask::LoadById($message->bundleTaskId);
                     } catch (Exception $e) {
                     }
                     if ($bundleTask) {
                         if ($message->status == 'ok') {
                             $metaData = array('szr_version' => $message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION], 'os' => $message->os, 'software' => $message->software);
                             $bundleTask->setMetaData($metaData);
                             $bundleTask->Save();
                             PlatformFactory::NewPlatform($bundleTask->platform)->CreateServerSnapshot($bundleTask);
                         } else {
                             $bundleTask->SnapshotCreationFailed("PrepareBundle procedure failed: {$message->lastError}");
                         }
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_DeployResult) {
                     try {
                         $deploymentTask = Scalr_Model::init(Scalr_Model::DM_DEPLOYMENT_TASK)->loadById($message->deployTaskId);
                     } catch (Exception $e) {
                     }
                     if ($deploymentTask) {
                         if ($message->status == 'error') {
                             $deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_FAILED;
                             $deploymentTask->lastError = $message->lastError;
                         } else {
                             $deploymentTask->status = Scalr_Dm_DeploymentTask::STATUS_DEPLOYED;
                             $deploymentTask->dtDeployed = date("Y-m-d H:i:s");
                         }
                         $deploymentTask->save();
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Hello) {
                     $event = $this->onHello($message, $dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_MongoDb) {
                     try {
                         $dbFarmRole = $dbserver->GetFarmRoleObject();
                     } catch (Exception $e) {
                     }
                     if ($dbFarmRole instanceof DBFarmRole) {
                         foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
                             $behavior->handleMessage($message, $dbserver);
                         }
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_DbMsr) {
                     try {
                         $dbFarmRole = $dbserver->GetFarmRoleObject();
                     } catch (Exception $e) {
                     }
                     if ($dbFarmRole instanceof DBFarmRole) {
                         foreach (Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $behavior) {
                             $behavior->handleMessage($message, $dbserver);
                         }
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_HostInit) {
                     $event = $this->onHostInit($message, $dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_HostUp) {
                     $event = $this->onHostUp($message, $dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_HostDown) {
                     $isMoving = false;
                     if ($dbserver->platform == SERVER_PLATFORMS::RACKSPACE) {
                         $p = PlatformFactory::NewPlatform($dbserver->platform);
                         $status = $p->GetServerRealStatus($dbserver)->getName();
                         if (stristr($status, 'MOVE') || stristr($status, 'REBOOT')) {
                             $this->logger->error(new FarmLogMessage($dbserver->farmId, "Rackspace server is in MOVING state. Ignoring HostDown message."));
                             $isMoving = true;
                         }
                     }
                     if (!$isMoving) {
                         $event = new HostDownEvent($dbserver);
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_RebootStart) {
                     $event = new RebootBeginEvent($dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_RebootFinish) {
                     $event = new RebootCompleteEvent($dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_BeforeHostUp) {
                     $event = new BeforeHostUpEvent($dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_BlockDeviceAttached) {
                     if ($dbserver->platform == SERVER_PLATFORMS::EC2) {
                         $ec2Client = Scalr_Service_Cloud_Aws::newEc2($dbserver->GetProperty(EC2_SERVER_PROPERTIES::REGION), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
                         $instanceId = $dbserver->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
                         $volumes = $ec2Client->DescribeVolumes()->volumeSet->item;
                         if (!is_array($volumes)) {
                             $volumes = array($volumes);
                         }
                         foreach ($volumes as $volume) {
                             if ($volume->status == AMAZON_EBS_STATE::IN_USE && $volume->attachmentSet->item->instanceId == $instanceId && $volume->attachmentSet->item->device == $message->deviceName) {
                                 $message->volumeId = $volume->volumeId;
                             }
                         }
                     }
                     $event = new EBSVolumeAttachedEvent($dbserver, $message->deviceName, $message->volumeId);
                 } elseif ($message instanceof Scalr_Messaging_Msg_BlockDeviceMounted) {
                     // Single volume
                     $ebsinfo = $this->db->GetRow("SELECT * FROM ec2_ebs WHERE volume_id=?", array($message->volumeId));
                     if ($ebsinfo) {
                         $this->db->Execute("UPDATE ec2_ebs SET mount_status=?, isfsexist='1' WHERE id=?", array(EC2_EBS_MOUNT_STATUS::MOUNTED, $ebsinfo['id']));
                     }
                     $event = new EBSVolumeMountedEvent($dbserver, $message->mountpoint, $message->volumeId, $message->deviceName);
                 } elseif ($message instanceof Scalr_Messaging_Msg_RebundleResult) {
                     if ($message->status == Scalr_Messaging_Msg_RebundleResult::STATUS_OK) {
                         $metaData = array('szr_version' => $message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION], 'dist' => $message->dist, 'os' => $message->os, 'software' => $message->software);
                         if ($dbserver->platform == SERVER_PLATFORMS::EC2) {
                             if ($message->aws) {
                                 if ($message->aws->root - device - type == 'ebs') {
                                     $tags[] = ROLE_TAGS::EC2_EBS;
                                 }
                                 if ($message->aws->virtualization - type == 'hvm') {
                                     $tags[] = ROLE_TAGS::EC2_HVM;
                                 }
                             } else {
                                 $ec2Client = Scalr_Service_Cloud_Aws::newEc2($dbserver->GetProperty(EC2_SERVER_PROPERTIES::REGION), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
                                 try {
                                     $DescribeImagesType = new DescribeImagesType(null, array(), null);
                                     $DescribeImagesType->imagesSet = new stdClass();
                                     $DescribeImagesType->imagesSet->item = array();
                                     $DescribeImagesType->imagesSet->item[] = array('imageId' => $dbserver->GetProperty(EC2_SERVER_PROPERTIES::AMIID));
                                     $info = $ec2Client->DescribeImages($DescribeImagesType);
                                     if ($info->imagesSet->item->rootDeviceType == 'ebs') {
                                         $tags[] = ROLE_TAGS::EC2_EBS;
                                     } else {
                                         try {
                                             $bundleTask = BundleTask::LoadById($message->bundleTaskId);
                                             if ($bundleTask->bundleType == SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS) {
                                                 $tags[] = ROLE_TAGS::EC2_EBS;
                                             }
                                         } catch (Exception $e) {
                                         }
                                     }
                                     if ($info->imagesSet->item->virtualizationType == 'hvm') {
                                         $tags[] = ROLE_TAGS::EC2_HVM;
                                     }
                                 } catch (Exception $e) {
                                     $metaData['tagsError'] = $e->getMessage();
                                 }
                             }
                         } elseif ($dbserver->platform == SERVER_PLATFORMS::NIMBULA) {
                             $metaData['init_root_user'] = $message->sshUser;
                             $metaData['init_root_pass'] = $message->sshPassword;
                         }
                         $metaData['tags'] = $tags;
                         $event = new RebundleCompleteEvent($dbserver, $message->snapshotId, $message->bundleTaskId, $metaData);
                     } else {
                         if ($message->status == Scalr_Messaging_Msg_RebundleResult::STATUS_FAILED) {
                             $event = new RebundleFailedEvent($dbserver, $message->bundleTaskId, $message->lastError);
                         }
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Mysql_CreateDataBundleResult) {
                     if ($message->status == "ok") {
                         $event = new MysqlBackupCompleteEvent($dbserver, MYSQL_BACKUP_TYPE::BUNDLE, array('snapshotConfig' => $message->snapshotConfig, 'logFile' => $message->logFile, 'logPos' => $message->logPos, 'dataBundleSize' => $message->dataBundleSize, 'snapshotId' => $message->snapshotId));
                     } else {
                         $event = new MysqlBackupFailEvent($dbserver, MYSQL_BACKUP_TYPE::BUNDLE);
                         $event->lastError = $message->lastError;
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Mysql_CreateBackupResult) {
                     if ($message->status == "ok") {
                         $event = new MysqlBackupCompleteEvent($dbserver, MYSQL_BACKUP_TYPE::DUMP);
                     } else {
                         $event = new MysqlBackupFailEvent($dbserver, MYSQL_BACKUP_TYPE::DUMP);
                         $event->lastError = $message->lastError;
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_Mysql_PromoteToMasterResult) {
                     $event = $this->onMysql_PromoteToMasterResult($message, $dbserver);
                 } elseif ($message instanceof Scalr_Messaging_Msg_Mysql_CreatePmaUserResult) {
                     $farmRole = DBFarmRole::LoadByID($message->farmRoleId);
                     if ($message->status == "ok") {
                         $farmRole->SetSetting(DbFarmRole::SETTING_MYSQL_PMA_USER, $message->pmaUser);
                         $farmRole->SetSetting(DbFarmRole::SETTING_MYSQL_PMA_PASS, $message->pmaPassword);
                     } else {
                         $farmRole->SetSetting(DBFarmRole::SETTING_MYSQL_PMA_REQUEST_TIME, "");
                         $farmRole->SetSetting(DBFarmRole::SETTING_MYSQL_PMA_REQUEST_ERROR, $message->lastError);
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_RabbitMq_SetupControlPanelResult) {
                     $farmRole = $dbserver->GetFarmRoleObject();
                     if ($message->status == "ok") {
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_SERVER_ID, $dbserver->serverId);
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_URL, $message->cpanelUrl);
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_REQUEST_TIME, "");
                     } else {
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_SERVER_ID, "");
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_REQUEST_TIME, "");
                         $farmRole->SetSetting(Scalr_Role_Behavior_RabbitMQ::ROLE_CP_ERROR_MSG, $message->lastError);
                     }
                 } elseif ($message instanceof Scalr_Messaging_Msg_AmiScriptsMigrationResult) {
                     try {
                         //Open security group:
                         if ($dbserver->platform == SERVER_PLATFORMS::EC2) {
                             $info = PlatformFactory::NewPlatform($dbserver->platform)->GetServerExtendedInformation($dbserver);
                             $sg = explode(", ", $info['Security groups']);
                             foreach ($sg as $sgroup) {
                                 if ($sgroup != 'default') {
                                     $ipPermissionSet = new IpPermissionSetType();
                                     $group_rules = array(array('rule' => 'tcp:8013:8013:0.0.0.0/0'), array('rule' => 'udp:8014:8014:0.0.0.0/0'));
                                     foreach ($group_rules as $rule) {
                                         $group_rule = explode(":", $rule["rule"]);
                                         $ipPermissionSet->AddItem($group_rule[0], $group_rule[1], $group_rule[2], null, array($group_rule[3]));
                                     }
                                     $ec2Client = Scalr_Service_Cloud_Aws::newEc2($dbserver->GetProperty(EC2_SERVER_PROPERTIES::REGION), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
                                     // Create security group
                                     $ec2Client->AuthorizeSecurityGroupIngress($dbserver->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID), $sgroup, $ipPermissionSet);
                                     break;
                                 }
                             }
                         }
                     } catch (Exception $e) {
                         $this->logger->fatal($e->getMessage());
                     }
                     $dbserver->SetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT, 8014);
                     $dbserver->SetProperty(SERVER_PROPERTIES::SZR_VESION, "0.7.217");
                     if ($message->mysql) {
                         $event = $this->onHostUp($message, $dbserver, true);
                     }
                 }
                 $handle_status = MESSAGE_STATUS::HANDLED;
             } catch (Exception $e) {
                 $handle_status = MESSAGE_STATUS::FAILED;
                 $this->logger->error(sprintf("Cannot handle message '%s' (message_id: %s) " . "from server '%s' (server_id: %s). %s", $message->getName(), $message->messageId, $dbserver->remoteIp ? $dbserver->remoteIp : '*no-ip*', $dbserver->serverId, $e->getMessage() . "({$e->getFile()}:{$e->getLine()})"));
             }
             $this->db->Execute("UPDATE messages SET status = ? WHERE messageid = ?", array($handle_status, $message->messageId));
             if ($event) {
                 Scalr::FireEvent($dbserver->farmId, $event);
             }
         } catch (Exception $e) {
             $this->logger->error($e->getMessage(), $e);
         }
     }
 }
Example #4
0
 private function updateRules(array $rules, $method, $securityGroupId)
 {
     $platformClient = $this->getPlatformClient();
     switch ($this->getParam('platform')) {
         case SERVER_PLATFORMS::EC2:
             $ipPermissionSet = new IpPermissionSetType();
             foreach ($rules as $rule) {
                 $ipPermissionSet->AddItem($rule['ipProtocol'], $rule['fromPort'], $rule['toPort'], null, array($rule['cidrIp']));
             }
             $accountId = $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID);
             if ($method == 'add') {
                 $platformClient->AuthorizeSecurityGroupIngress($accountId, $securityGroupId, $ipPermissionSet);
             } else {
                 $platformClient->RevokeSecurityGroupIngress($accountId, $securityGroupId, $ipPermissionSet);
             }
             break;
     }
 }