Skip to content
Snippets Groups Projects
Commit 5cebf6b8 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3172795 by baldwinlouie, yas: Display a warning message before...

Issue #3172795 by baldwinlouie, yas: Display a warning message before disassociating an EIP from Cloud Orchestrator itself
parent 8c63f9c9
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,13 @@ class ElasticIpDisassociateForm extends AwsDeleteForm {
public function getQuestion() {
/** @var \Drupal\aws_cloud\Entity\Ec2\ElasticIp $entity */
$entity = $this->entity;
if ($this->ec2Service->pingMetadataSecurityServer() && $entity->getInstanceId() === $this->ec2Service->getInstanceIdFromMetadata()) {
$this->messenger()->addWarning($this->t('Attempting to disassociate @ip_address from Cloud Orchestrator. Cloud Orchestrator will not be accessible if the IP address is disassociated.', [
'@ip_address' => $entity->getPublicIp(),
]));
}
return $this->t('Are you sure you want to disassociate this Elastic IP address (@ip_address)', [
'@ip_address' => $entity->getPublicIp(),
]);
......
......@@ -3,6 +3,7 @@
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\cloud\Entity\CloudContentEntityBase;
use Drupal\aws_cloud\Entity\Ec2\ElasticIp;
/**
* Provides an entities disassociate confirmation form.
......@@ -13,7 +14,7 @@ class ElasticIpDisassociateMultipleForm extends AwsCloudProcessMultipleForm {
* {@inheritdoc}
*/
public function getQuestion() {
$this->checkCloudOrchestratorIp();
return $this->formatPlural(count($this->selection),
'Are you sure you want to disassociate this @item?',
'Are you sure you want to disassociate these @items?', [
......@@ -23,6 +24,24 @@ class ElasticIpDisassociateMultipleForm extends AwsCloudProcessMultipleForm {
);
}
/**
* Check if Cloud Orchestrator IP is getting disassociated.
*
* Notify the user with a warning message if Cloud Orchestrator's IP
* is one of the selected IPs.
*/
private function checkCloudOrchestratorIp(): void {
foreach ($this->selection as $id => $selection) {
$elastic_ip = ElasticIp::load($id);
if ($this->ec2Service->pingMetadataSecurityServer() && $elastic_ip->getInstanceId() === $this->ec2Service->getInstanceIdFromMetadata()) {
$this->messenger()->addWarning($this->t('Attempting to disassociate @ip_address from Cloud Orchestrator. Cloud Orchestrator will not be accessible if the IP address is disassociated.', [
'@ip_address' => $elastic_ip->getPublicIp(),
]));
break;
}
}
}
/**
* {@inheritdoc}
*/
......
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