Skip to content
Snippets Groups Projects
Commit f8228527 authored by Masami  Suzuki's avatar Masami Suzuki Committed by Yas Naoi
Browse files

Issue #3285555 by Masami, yas, Ryo Yamashita: Add the function to delete...

Issue #3285555 by Masami, yas, Ryo Yamashita: Add the function to delete Openstack Floating IP in the SPA
parent f2d22503
Branches
Tags
3 merge requests!1759Issue #3356778: Release 5.1.1,!1679Issue #3349074: Fix the OpenStack Project create and edit form in SPA that "Member" cannot be saved due to a validation error,!1607Issue #3343582: Add the function to preview OpenStack stack in the SPA
......@@ -57,6 +57,18 @@ const OPENSTACK_FLOATING_IP_TEMPLATE: EntityFormTemplate[] = [
]
}
]
},
{
cloudServiceProvider: 'openstack',
entityName: 'floating_ip',
actionType: 'delete',
entityRecords: [
{
type: 'label',
text: 'Are you sure you want to delete the {{entityName}} {{name}}?'
},
],
submitButtonLabel: 'Delete'
}
]
......
......@@ -695,6 +695,20 @@ entity.openstack_floating_ip.edit:
options:
perm: 'edit any openstack floating ip+edit own openstack floating ip'
entity.openstack_floating_ip.delete:
path: '/cloud_dashboard/openstack/{cloud_context}/openstack_floating_ip/{entity_id}/delete'
defaults:
_controller: '\Drupal\openstack\Controller\ApiController::operateEntity'
entity_type_id: openstack_floating_ip
command: delete
methods: [POST]
requirements:
# Use custom access that will check for cloud_context and the desired permission.
# Desired permission is passed as an option in the "perm" variable
_custom_access: '\Drupal\cloud\Controller\CloudConfigController::access'
options:
perm: 'delete any openstack floating ip+delete own openstack floating ip'
entity.openstack_security_group.create:
path: '/cloud_dashboard/openstack/{cloud_context}/openstack_security_group/create'
defaults:
......
......@@ -591,6 +591,10 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
$method_name = 'editOpenStackFloatingIp';
break;
case 'delete_openstack_floating_ip':
$method_name = 'deleteOpenStackFloatingIp';
break;
case 'create_openstack_security_group':
$original_entity->setGroupName($request->get('group_name', ''));
$original_entity->setDescription($request->get('description', ''));
......
......@@ -1552,6 +1552,96 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface
$this->dispatchSaveEvent($this->entity);
}
/**
* {@inheritdoc}
*/
public function deleteOpenStackFloatingIp(ElasticIpInterface $entity, array &$form, FormStateInterface $form_state): bool {
$this->entity = $entity;
$this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext());
if ($this->ec2Service instanceof OpenStackEc2Service) {
return $this->deleteFloatingIp($form, $form_state);
}
$params = ['FloatingIpId' => $entity->getFloatingIpId()];
$form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);
if (empty($entity)
|| empty($params)
|| empty($this->ec2Service->releaseAddress($params))) {
$this->processOperationErrorStatus($entity, 'deleted');
return FALSE;
}
$entity->delete();
$this->messenger->addStatus($this->getDeletionMessage());
$this->logDeletionMessage();
$this->clearCacheValues($entity->getCacheTags());
return TRUE;
}
/**
* Delete an floating IP.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @throws \Drupal\Core\Entity\EntityMalformedException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
private function deleteFloatingIp(array $form, FormStateInterface $form_state): bool {
/** @var \Drupal\aws_cloud\Entity\Ec2\ElasticIp $entity */
$entity = $this->entity;
$this->ec2Service->setCloudContext($entity->getCloudContext());
$allocation_id = $entity->getAllocationId();
$public_ip = $entity->getPublicIp();
$params = [];
if ($entity->getDomain() === 'standard' && !empty($public_ip)) {
$params['PublicIp'] = $public_ip;
}
elseif ($entity->getDomain() === 'vpc' && !empty($allocation_id)) {
$params['AllocationId'] = $allocation_id;
$params['NetworkBorderGroup'] = $entity->getNetworkBorderGroup();
}
$form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);
$result = $this->ec2Service->releaseAddress($params);
// If $result is NULL, some error should have occurred
// when calling the AWS API.
if ($result === NULL) {
$this->processOperationErrorStatus($entity, 'deleted');
return FALSE;
}
if (!empty($result['SendToWorker'])) {
$this->messenger->addStatus($this->t('The @type @label has been deleted remotely.', [
'@type' => $entity->getEntityType()->getSingularLabel(),
'@label' => $entity->getName(),
]));
return TRUE;
}
// Update instances after the Elastic IP is deleted.
if ($entity->getEntityTypeId() === 'aws_cloud_elastic_ip') {
$this->ec2Service->updateInstances();
}
$entity->delete();
$this->messenger->addStatus($this->getDeletionMessage());
$this->logDeletionMessage();
$this->clearCacheValues($entity->getCacheTags());
$this->dispatchSubmitEvent($entity);
return TRUE;
}
/**
* {@inheritdoc}
*/
......
......@@ -240,6 +240,21 @@ interface OpenStackOperationsServiceInterface {
*/
public function editOpenStackFloatingIp(ElasticIpInterface $entity, array &$form, FormStateInterface $form_state): bool;
/**
* Delete an OpenStack floating IP.
*
* @param \Drupal\aws_cloud\Entity\Ec2\ElasticIpInterface $entity
* The OpenStack image entity.
* @param array $form
* Array of form object.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*
* @return bool
* TRUE when the process succeeds.
*/
public function deleteOpenStackFloatingIp(ElasticIpInterface $entity, array &$form, FormStateInterface $form_state): bool;
/**
* Create an OpenStack SecurityGroup.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment