getByConfigIdAndIndex() public static method

public static getByConfigIdAndIndex ( $configId, $serverIndex ) : boolean | Scalr\Farm\Role\FarmRoleStorageDevice
$configId
$serverIndex
return boolean | Scalr\Farm\Role\FarmRoleStorageDevice
Ejemplo n.º 1
0
 public function OnHostDown(\HostDownEvent $event)
 {
     $dbServer = $event->DBServer;
     if ($dbServer->farmRoleId != 0) {
         try {
             $dbFarmRole = $dbServer->GetFarmRoleObject();
         } catch (\Exception $e) {
             return false;
         }
         foreach (\Scalr_Role_Behavior::getListForFarmRole($dbFarmRole) as $bObj) {
             $bObj->onHostDown($dbServer, $event);
         }
         //Storage
         if (!$event->isSuspended) {
             try {
                 $storage = new FarmRoleStorage($dbFarmRole);
                 $storageConfigs = $storage->getConfigs();
                 if (empty($storageConfigs)) {
                     return true;
                 }
                 foreach ($storageConfigs as $config) {
                     //Check for existing volume
                     $dbVolume = FarmRoleStorageDevice::getByConfigIdAndIndex($config->id, $dbServer->index);
                     if ($dbVolume && !$config->reUse) {
                         $dbVolume->status = FarmRoleStorageDevice::STATUS_ZOMBY;
                         $dbVolume->save();
                     }
                 }
             } catch (\Exception $e) {
                 $this->logger->error(new \FarmLogMessage($dbServer, "Marking storage for disposal failed: {$e->getMessage()}"));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function xGetStorageConfigAction()
 {
     $farmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
     $this->user->getPermissions()->validate($farmRole);
     $device = \Scalr\Farm\Role\FarmRoleStorageDevice::getByConfigIdAndIndex($this->getParam('configId'), $this->getParam('serverIndex'));
     if ($device) {
         $this->response->data(array('config' => $device->config));
     } else {
         $this->response->failure('Config not found');
     }
 }
Ejemplo n.º 3
0
 public function getVolumesConfigs(DBServer $dbServer, $isHostInit = true)
 {
     $volumes = [];
     $configs = $this->getConfigs();
     foreach ($configs as $config) {
         //Check for existing volume
         $createFreshConfig = true;
         $volume = null;
         $dbVolume = FarmRoleStorageDevice::getByConfigIdAndIndex($config->id, $dbServer->index);
         if ($dbVolume) {
             $volume = $dbVolume->config;
             $createFreshConfig = false;
             $volume->mpoint = $config->mount == 1 ? $config->mountPoint : null;
         }
         if ($createFreshConfig || $config->rebuild) {
             $volumeConfigTemplate = new stdClass();
             $volumeConfigTemplate->scalrStorageId = $config->id;
             $volumeConfigTemplate->type = stristr($config->type, "raid.") ? FarmRoleStorageConfig::TYPE_RAID : $config->type;
             $volumeConfigTemplate->fstype = $config->fs;
             $volumeConfigTemplate->mpoint = $config->mount == 1 ? $config->mountPoint : null;
             if ($config->mount == 1) {
                 if ($config->fs == 'ntfs' && !empty($config->label)) {
                     $volumeConfigTemplate->label = $config->label;
                 }
                 if ($config->fs != 'ntfs' && !empty($config->mountOptions)) {
                     $volumeConfigTemplate->mount_options = array_map('trim', explode(',', $config->mountOptions));
                 }
             }
             switch ($config->type) {
                 case FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL:
                     $volumeConfigTemplate->name = $config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME];
                     $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_SIZE];
                     break;
                 case FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL:
                     $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_SIZE];
                     $volumeConfigTemplate->name = $config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME];
                     break;
                 case FarmRoleStorageConfig::TYPE_CINDER:
                     $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_CINDER_SIZE];
                     if (!empty($config->settings[FarmRoleStorageConfig::SETTING_CINDER_VOLUME_TYPE])) {
                         $volumeConfigTemplate->volumeType = $config->settings[FarmRoleStorageConfig::SETTING_CINDER_VOLUME_TYPE];
                     }
                     // SNAPSHOT
                     if ($config->settings[FarmRoleStorageConfig::SETTING_CINDER_SNAPSHOT] != '') {
                         $volumeConfigTemplate->snap = new stdClass();
                         $volumeConfigTemplate->snap->type = FarmRoleStorageConfig::TYPE_CINDER;
                         $volumeConfigTemplate->snap->id = $config->settings[FarmRoleStorageConfig::SETTING_CINDER_SNAPSHOT];
                     }
                     break;
                 case FarmRoleStorageConfig::TYPE_CSVOL:
                     $volumeConfigTemplate->diskOfferingId = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_DISK_OFFERING];
                     $volumeConfigTemplate->diskOfferingType = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_DISK_OFFERING_TYPE];
                     if ($volumeConfigTemplate->diskOfferingType == 'custom' || !$volumeConfigTemplate->diskOfferingId) {
                         $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_SIZE];
                     }
                     // SNAPSHOT
                     if ($config->settings[FarmRoleStorageConfig::SETTING_CSVOL_SNAPSHOT] != '') {
                         $volumeConfigTemplate->snap = new stdClass();
                         $volumeConfigTemplate->snap->type = FarmRoleStorageConfig::TYPE_CSVOL;
                         $volumeConfigTemplate->snap->id = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_SNAPSHOT];
                     }
                     break;
                 case FarmRoleStorageConfig::TYPE_GCE_PD:
                     $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_SIZE];
                     if (!empty($config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_TYPE])) {
                         $volumeConfigTemplate->diskType = $config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_TYPE];
                     }
                     // SNAPSHOT
                     if ($config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_SNAPSHOT] != '') {
                         $volumeConfigTemplate->snap = new stdClass();
                         $volumeConfigTemplate->snap->type = FarmRoleStorageConfig::TYPE_GCE_PD;
                         $volumeConfigTemplate->snap->id = $config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_SNAPSHOT];
                     }
                     break;
                 case FarmRoleStorageConfig::TYPE_EBS:
                     $volumeConfigTemplate->size = $config->settings[FarmRoleStorageConfig::SETTING_EBS_SIZE];
                     $volumeConfigTemplate->encrypted = !empty($config->settings[FarmRoleStorageConfig::SETTING_EBS_ENCRYPTED]) ? 1 : 0;
                     $volumeConfigTemplate->tags = $dbServer->getAwsTags();
                     // IOPS
                     $volumeConfigTemplate->volumeType = $config->settings[FarmRoleStorageConfig::SETTING_EBS_TYPE];
                     if ($volumeConfigTemplate->volumeType == 'io1') {
                         $volumeConfigTemplate->iops = $config->settings[FarmRoleStorageConfig::SETTING_EBS_IOPS];
                     }
                     if (!empty($config->settings[FarmRoleStorageConfig::SETTING_EBS_KMS_KEY_ID])) {
                         $volumeConfigTemplate->kmsKeyId = $config->settings[FarmRoleStorageConfig::SETTING_EBS_KMS_KEY_ID];
                     }
                     // SNAPSHOT
                     if ($config->settings[FarmRoleStorageConfig::SETTING_EBS_SNAPSHOT] != '') {
                         $volumeConfigTemplate->snap = new stdClass();
                         $volumeConfigTemplate->snap->type = FarmRoleStorageConfig::TYPE_EBS;
                         $volumeConfigTemplate->snap->id = $config->settings[FarmRoleStorageConfig::SETTING_EBS_SNAPSHOT];
                     }
                     break;
                 case FarmRoleStorageConfig::TYPE_RAID_CSVOL:
                 case FarmRoleStorageConfig::TYPE_RAID_CINDER:
                 case FarmRoleStorageConfig::TYPE_RAID_EBS:
                 case FarmRoleStorageConfig::TYPE_RAID_GCE_PD:
                     $volumeConfigTemplate->level = $config->settings[FarmRoleStorageConfig::SETTING_RAID_LEVEL];
                     $volumeConfigTemplate->vg = $config->id;
                     $volumeConfigTemplate->disks = [];
                     for ($i = 1; $i <= $config->settings[FarmRoleStorageConfig::SETTING_RAID_VOLUMES_COUNT]; $i++) {
                         $disk = new stdClass();
                         if ($config->type == FarmRoleStorageConfig::TYPE_RAID_EBS) {
                             $disk->size = $config->settings[FarmRoleStorageConfig::SETTING_EBS_SIZE];
                             $disk->encrypted = !empty($config->settings[FarmRoleStorageConfig::SETTING_EBS_ENCRYPTED]) ? 1 : 0;
                             $disk->type = FarmRoleStorageConfig::TYPE_EBS;
                             $disk->tags = $dbServer->getAwsTags();
                             // IOPS
                             $disk->volumeType = $config->settings[FarmRoleStorageConfig::SETTING_EBS_TYPE];
                             if ($disk->volumeType == 'io1') {
                                 $disk->iops = $config->settings[FarmRoleStorageConfig::SETTING_EBS_IOPS];
                             }
                             if (!empty($config->settings[FarmRoleStorageConfig::SETTING_EBS_KMS_KEY_ID])) {
                                 $disk->kmsKeyId = $config->settings[FarmRoleStorageConfig::SETTING_EBS_KMS_KEY_ID];
                             }
                         } elseif ($config->type == FarmRoleStorageConfig::TYPE_RAID_CSVOL) {
                             $disk->diskOfferingId = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_DISK_OFFERING];
                             $disk->diskOfferingType = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_DISK_OFFERING_TYPE];
                             if ($disk->diskOfferingType == 'custom' || !$disk->diskOfferingId) {
                                 $disk->size = $config->settings[FarmRoleStorageConfig::SETTING_CSVOL_SIZE];
                             }
                             $disk->type = FarmRoleStorageConfig::TYPE_CSVOL;
                         } elseif ($config->type == FarmRoleStorageConfig::TYPE_RAID_GCE_PD) {
                             $disk->size = $config->settings[FarmRoleStorageConfig::SETTING_GCE_PD_SIZE];
                             $disk->type = FarmRoleStorageConfig::TYPE_GCE_PD;
                         } elseif ($config->type == FarmRoleStorageConfig::TYPE_RAID_CINDER) {
                             $disk->size = $config->settings[FarmRoleStorageConfig::SETTING_CINDER_SIZE];
                             $disk->type = FarmRoleStorageConfig::TYPE_CINDER;
                             if (!empty($config->settings[FarmRoleStorageConfig::SETTING_CINDER_VOLUME_TYPE])) {
                                 $disk->volumeType = $config->settings[FarmRoleStorageConfig::SETTING_CINDER_VOLUME_TYPE];
                             }
                         }
                         $volumeConfigTemplate->disks[] = $disk;
                     }
                     break;
             }
         }
         if (!$volume) {
             $volume = $volumeConfigTemplate;
         } elseif ($config->rebuild && $volume->id) {
             $volume->template = $volumeConfigTemplate;
             $volume->fromTemplateIfMissing = 1;
         }
         $volumes[] = $volume;
     }
     return $volumes;
 }