Commit da78c249 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3255361 by Xiaohua Guan, yas: Create carrier gateway from Cloud...

Issue #3255361 by Xiaohua Guan, yas: Create carrier gateway from Cloud Orchestrator master to workers  (AWS Cloud)
parent e145253c
Loading
Loading
Loading
Loading
+36 −24
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\aws_cloud\Form\Vpc;

use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm;
use Drupal\aws_cloud\Traits\AwsCloudFormTrait;
use Drupal\cloud\Traits\CloudContentEntityTrait;
use Drupal\Core\Form\FormStateInterface;

@@ -13,6 +14,8 @@ use Drupal\Core\Form\FormStateInterface;
 */
class CarrierGatewayCreateForm extends AwsCloudContentForm {

  use AwsCloudFormTrait;

  use CloudContentEntityTrait;

  /**
@@ -49,12 +52,17 @@ class CarrierGatewayCreateForm extends AwsCloudContentForm {
      '#required'      => TRUE,
    ];

    $vpcs = $this->ec2Service->getVpcs();
    $vpcs = $this->getVpcOptions($cloud_context);
    ksort($vpcs);

    $result = $this->ec2Service->describeCarrierGateways();
    foreach ($result['CarrierGateways'] as $gateway) {
      unset($vpcs[$gateway['VpcId']]);
    $gateways = $this->entityTypeManager
      ->getStorage('aws_cloud_carrier_gateway')
      ->loadByProperties([
        'cloud_context' => $cloud_context,
      ]);

    foreach ($gateways as $gateway) {
      unset($vpcs[$gateway->getVpcId()]);
    }

    $form['carrier_gateway']['vpc_id'] = [
@@ -94,14 +102,27 @@ class CarrierGatewayCreateForm extends AwsCloudContentForm {
    $entity = $this->entity;
    $entity->setCloudContext($cloud_context);

    $form_state->setRedirect(
      'view.aws_cloud_carrier_gateway.list',
      ['cloud_context' => $entity->getCloudContext()]
    );

    $result = $this->ec2Service->createCarrierGateway([
      'VpcId' => $entity->getVpcId(),
    ]);

    if (isset($result['CarrierGateway'])
      && ($entity->setCarrierGatewayId($result['CarrierGateway']['CarrierGatewayId']))
      && ($entity->save())
    ) {
    if ($result === NULL) {
      $this->processOperationErrorStatus($entity, 'created');
      return;
    }

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

    $entity->setCarrierGatewayId($result['CarrierGateway']['CarrierGatewayId']);
    $entity->save();
    $this->updateNameAndCreatedByTags($entity, $entity->getCarrierGatewayId());

    // Update the carrier gateway.
@@ -112,15 +133,6 @@ class CarrierGatewayCreateForm extends AwsCloudContentForm {
    $this->processOperationStatus($entity, 'created');
    $this->clearCacheValues($entity->getCacheTags());
    $this->dispatchSaveEvent($entity);
      $form_state->setRedirect(
        'view.aws_cloud_carrier_gateway.list',
        ['cloud_context' => $entity->getCloudContext()]
      );
    }
    else {

      $this->processOperationErrorStatus($entity, 'created');
    }
  }

}
+17 −0
Original line number Diff line number Diff line
@@ -55,6 +55,14 @@ class CarrierGatewayTest extends AwsCloudTestBase {

    $vpc_ids = $this->updateVpcsMockData(self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT);

    // Create VPC.
    $vpc_data = $this->createVpcTestFormData(self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT);
    for ($i = 0; $i < self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT; $i++) {
      $vpc = $this->createVpcTestEntity($i, $vpc_ids[$i], $vpc_data[$i]['name'], $cloud_context);
      $vpc->setCidrBlock($vpc_data[$i]['cidr_block']);
      $vpc->save();
    }

    // Add a new Carrier Gateway.
    $add = $this->createCarrierGatewayTestFormData(self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT, $vpc_ids);
    $this->reloadMockData();
@@ -243,6 +251,15 @@ class CarrierGatewayTest extends AwsCloudTestBase {

    foreach ($cloud_configs ?: [] as $cloud_config) {
      $cloud_context = $cloud_config->getCloudContext();

      // Create VPC.
      $vpc_data = $this->createVpcTestFormData(self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT);
      for ($i = 0; $i < self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT; $i++) {
        $vpc = $this->createVpcTestEntity($i, $vpc_ids[$i], $vpc_data[$i]['name'], $cloud_context);
        $vpc->setCidrBlock($vpc_data[$i]['cidr_block']);
        $vpc->save();
      }

      // Add a new Carrier Gateway.
      $add = $this->createCarrierGatewayTestFormData(self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT, $vpc_ids);
      for ($i = 0; $i < self::AWS_CLOUD_CARRIER_GATEWAY_REPEAT_COUNT; $i++) {