Skip to content
Snippets Groups Projects
Commit 02c9ae1a authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3063200 by Xiaohua Guan, yas: Expand the size of my volume

parent 791131e2
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface {
return $this->get('size')->value;
}
/**
* {@inheritdoc}
*/
public function setSize($size) {
return $this->set('size', $size);
}
/**
* {@inheritdoc}
*/
......@@ -113,6 +120,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface {
return $this->get('volume_type')->value;
}
/**
* {@inheritdoc}
*/
public function setVolumeType($volume_type) {
return $this->set('volume_type', $volume_type);
}
/**
* {@inheritdoc}
*/
......@@ -127,6 +141,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface {
return $this->get('iops')->value;
}
/**
* {@inheritdoc}
*/
public function setIops($iops) {
return $this->set('iops', $iops);
}
/**
* {@inheritdoc}
*/
......
......@@ -32,6 +32,11 @@ interface VolumeInterface extends ContentEntityInterface, EntityOwnerInterface {
*/
public function getSize();
/**
* {@inheritdoc}
*/
public function setSize($size);
/**
* {@inheritdoc}
*/
......@@ -57,6 +62,11 @@ interface VolumeInterface extends ContentEntityInterface, EntityOwnerInterface {
*/
public function getVolumeType();
/**
* {@inheritdoc}
*/
public function setVolumeType($volume_type);
/**
* {@inheritdoc}
*/
......@@ -67,6 +77,11 @@ interface VolumeInterface extends ContentEntityInterface, EntityOwnerInterface {
*/
public function getIops();
/**
* {@inheritdoc}
*/
public function setIops($iops);
/**
* {@inheritdoc}
*/
......
......@@ -205,6 +205,14 @@ class VolumeCreateForm extends AwsCloudContentForm {
$params['KmsKeyId'] = $entity->getKmsKeyId();
}
$params['TagSpecifications'] = [];
$params['TagSpecifications'][] = [
'ResourceType' => 'volume',
'Tags' => [
['Key' => 'Name', 'Value' => $entity->getName()],
],
];
$result = $this->awsEc2Service->createVolume($params);
if (isset($result['VolumeId'])
......
......@@ -139,6 +139,10 @@ class VolumeEditForm extends AwsCloudContentForm {
$this->awsEc2Service->setCloudContext($entity->getCloudContext());
$old_entity = $this->entityTypeManager
->getStorage('aws_cloud_volume')
->load($entity->id());
if ($entity->save()) {
// Update name.
$tag_map = [];
......@@ -146,17 +150,19 @@ class VolumeEditForm extends AwsCloudContentForm {
$this->setTagsInAws($entity->getVolumeId(), $tag_map);
// Update volume type.
if ($this->isVolumeChanged($entity)) {
if ($this->isVolumeChanged($entity, $old_entity)) {
$params = [
'VolumeId' => $entity->getVolumeId(),
'VolumeType' => $entity->getVolumeType(),
'Size' => $entity->getSize(),
];
if ($entity->getIops()) {
// Only if the type is io1, the iops can be modified.
if ($entity->getVolumeType == 'io1' && $entity->getIops()) {
$params['Iops'] = $entity->getIops();
}
$this->awsEc2Service->modifyVolume($params);
$result = $this->awsEc2Service->modifyVolume($params);
}
$message = $this->t('The @label "%label" has been saved.', [
......@@ -182,15 +188,13 @@ class VolumeEditForm extends AwsCloudContentForm {
*
* @param \Drupal\aws_cloud\Entity\Ec2\Volume $new_volume
* The new volume.
* @param \Drupal\aws_cloud\Entity\Ec2\Volume $old_volume
* The old volume.
*
* @return bool
* Whether the volume changed or not.
*/
private function isVolumeChanged(Volume $new_volume) {
$old_volume = $this->entityTypeManager
->getStorage('aws_cloud_volume')
->load($new_volume->id());
private function isVolumeChanged(Volume $new_volume, Volume $old_volume) {
return $old_volume->getVolumeType() != $new_volume->getVolumeType()
|| $old_volume->getSize() != $new_volume->getSize()
|| $old_volume->getIops() != $new_volume->getIops();
......
......@@ -793,6 +793,9 @@ class AwsCloudBatchOperations {
$entity->setSnapshotName(empty($volume['SnapshotId'])
? ''
: $snapshot_id_name_map[$volume['SnapshotId']]);
$entity->setSize($volume['Size']);
$entity->setVolumeType($volume['VolumeType']);
$entity->setIops($volume['Iops']);
if ($uid != 0) {
$entity->setOwnerById($uid);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment