Loading modules/cloud_service_providers/aws_cloud/src/Form/Vpc/CarrierGatewayCreateForm.php +36 −24 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -13,6 +14,8 @@ use Drupal\Core\Form\FormStateInterface; */ class CarrierGatewayCreateForm extends AwsCloudContentForm { use AwsCloudFormTrait; use CloudContentEntityTrait; /** Loading Loading @@ -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'] = [ Loading Loading @@ -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. Loading @@ -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'); } } } modules/cloud_service_providers/aws_cloud/tests/src/Functional/Vpc/CarrierGatewayTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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++) { Loading Loading
modules/cloud_service_providers/aws_cloud/src/Form/Vpc/CarrierGatewayCreateForm.php +36 −24 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -13,6 +14,8 @@ use Drupal\Core\Form\FormStateInterface; */ class CarrierGatewayCreateForm extends AwsCloudContentForm { use AwsCloudFormTrait; use CloudContentEntityTrait; /** Loading Loading @@ -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'] = [ Loading Loading @@ -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. Loading @@ -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'); } } }
modules/cloud_service_providers/aws_cloud/tests/src/Functional/Vpc/CarrierGatewayTest.php +17 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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++) { Loading