/** * Loads VolumeData from simple xml object * * @param \SimpleXMLElement $v * @return VolumeData Returns VolumeData */ protected function _loadVolumeData(\SimpleXMLElement $v) { $item = null; if ($this->exist($v)) { $volumeId = (string) $v->volumeId; $item = $this->ec2->getEntityManagerEnabled() ? $this->ec2->volume->get($volumeId) : null; if ($item === null) { $item = new VolumeData(); $item->setEc2($this->ec2); $bAttach = true; } else { $item->resetObject(); $bAttach = false; } $item->volumeId = $volumeId; $item->volumeType = $this->exist($v->volumeType) ? (string) $v->volumeType : null; $item->iops = $this->exist($v->iops) ? (int) $v->iops : null; $item->availabilityZone = $this->exist($v->availabilityZone) ? (string) $v->availabilityZone : null; $item->createTime = $this->exist($v->createTime) ? new DateTime((string) $v->createTime, new DateTimeZone('UTC')) : null; $item->size = $this->exist($v->size) ? (string) $v->size : null; $item->snapshotId = $this->exist($v->snapshotId) ? (string) $v->snapshotId : null; $item->status = $this->exist($v->status) ? (string) $v->status : null; $item->encrypted = $this->exist($v->encrypted) ? (string) $v->encrypted == 'true' : null; $item->setTagSet($this->_loadResourceTagSetList($v->tagSet))->setAttachmentSet($this->_loadAttachmentSetResponseList($v->attachmentSet)); if ($bAttach && $this->ec2->getEntityManagerEnabled()) { $this->getEntityManager()->attach($item); } } return $item; }
/** * Attaches volume to server * * It uses request params and can't be used without UI request * * @param VolumeData $info AWS EBS Volume info * @throws Exception */ protected function attachVolumeToServer(VolumeData $info) { $dBServer = DBServer::LoadByID($this->getParam('serverId')); //Check access permission to specified server $this->request->checkPermissions($dBServer->GetFarmObject()->__getNewFarmObject(), Acl::PERM_FARMS_SERVERS); $errmsg = null; try { $dbEbsVolume = DBEBSVolume::loadByVolumeId($this->getParam('volumeId')); if ($dbEbsVolume->isManual == 0) { $errmsg = sprintf(_("This volume was automatically created for role '%s' on farm '%s' and cannot be re-attahced manually."), $this->db->GetOne("\n SELECT name FROM roles\n JOIN farm_roles ON farm_roles.role_id = roles.id\n WHERE farm_roles.id=?\n LIMIT 1\n ", array($dbEbsVolume->farmRoleId)), $this->db->GetOne("SELECT name FROM farms WHERE id=? LIMIT 1", array($dbEbsVolume->farmId))); } } catch (Exception $e) { } if (!empty($errmsg)) { throw new Exception($errmsg); } $image = Image::findOne([['platform' => $dBServer->platform], ['id' => $dBServer->imageId], ['cloudLocation' => $dBServer->GetCloudLocation()]]); $device = $dBServer->GetFreeDeviceName($image->isEc2HvmImage()); $res = $info->attach($dBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $device); if ($this->getParam('attachOnBoot') == 'on') { $dbEbsVolume = new DBEBSVolume(); $dbEbsVolume->attachmentStatus = EC2_EBS_ATTACH_STATUS::ATTACHING; $dbEbsVolume->isManual = true; $dbEbsVolume->volumeId = $info->volumeId; $dbEbsVolume->ec2AvailZone = $info->availabilityZone; $dbEbsVolume->ec2Region = $this->getParam('cloudLocation'); $dbEbsVolume->deviceName = $device; $dbEbsVolume->farmId = $dBServer->farmId; $dbEbsVolume->farmRoleId = $dBServer->farmRoleId; $dbEbsVolume->serverId = $dBServer->serverId; $dbEbsVolume->serverIndex = $dBServer->index; $dbEbsVolume->size = $info->size; $dbEbsVolume->snapId = $info->snapshotId; $dbEbsVolume->mount = $this->getParam('mount') == 1; $dbEbsVolume->mountPoint = $this->getParam('mountPoint'); $dbEbsVolume->mountStatus = $this->getParam('mount') == 1 ? EC2_EBS_MOUNT_STATUS::AWAITING_ATTACHMENT : EC2_EBS_MOUNT_STATUS::NOT_MOUNTED; $dbEbsVolume->clientId = $this->user->getAccountId(); $dbEbsVolume->envId = $this->getEnvironmentId(); $dbEbsVolume->Save(); } //Updates/Creates AWS Tags of Volume $tags = []; foreach ($dBServer->getAwsTags() as $k => $v) { $tags[] = ['key' => $k, 'value' => $v]; } if (!empty($tags)) { $info->createTags($tags); } }