Commit 0fbcace3 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3327042 by sekinet, yas: Add the OpenStack Server Group delete form

parent 2b40d2ed
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -3227,6 +3227,38 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface
   * {@inheritdoc}
   */
  public function deleteOpenStackServerGroup(OpenStackServerGroupInterface $entity, array &$form, FormStateInterface $form_state): bool {
    $this->entity = $entity;

    /** @var Drupal\openstack\Service\Rest\OpenStackService $ec2_service */
    $ec2_service = $this->openStackServiceFactory->get($entity->getCloudContext());
    $this->ec2Service = $ec2_service;
    $this->awsCloudOperationsService->setEc2Service($this->ec2Service);

    $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);

    $this->ec2Service->setCloudContext($entity->getCloudContext());
    $result = $this->ec2Service->deleteServerGroup([
      'ServerGroupId' => $entity->getServerGroupId(),
    ]);

    if ($result === NULL) {
      $this->processOperationErrorStatus($entity, 'deleted');
      return FALSE;
    }

    if (!empty($result['SendToWorker'])) {
      $this->processOperationStatus($entity, 'deleted remotely');
      return TRUE;
    }

    $entity->delete();

    $this->messenger->addStatus($this->getDeletionMessage());
    $this->logDeletionMessage();

    $this->clearCacheValues($entity->getCacheTags());
    $this->dispatchSaveEvent($entity);

    return TRUE;
  }

+26 −0
Original line number Diff line number Diff line
@@ -6027,6 +6027,32 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter
    return $updated;
  }

  /**
   * Delete server group.
   *
   * @param array $params
   *   Parameters to pass to the API.
   *
   * @return array|null
   *   Succeeded or failed.
   */
  public function deleteServerGroup(array $params = []): ?array {
    if ($this->isWorkerResource()) {
      $this->saveOperation(__FUNCTION__, [$params], 'updateServerGroups');

      return ['SendToWorker' => TRUE];
    }

    $credentials = [
      'http_method' => 'delete',
      'endpoint' => $this->getEndpoint(OpenStackServiceInterface::COMPUTE_SERVICE, "/os-server-groups/{$params['ServerGroupId']}"),
    ];

    $response = $this->getClient($credentials);

    return $response['status_code'] === 204 ? ['Success' => TRUE] : NULL;
  }

  /**
   * {@inheritdoc}
   */