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

Issue #3303390 by baldwinlouie, yas: Add the function to create AWS Transit gateway in the SPA

parent effacabb
No related branches found
No related tags found
3 merge requests!1316Issue #3310263: Release 4.5.0,!1260Issue #3307397: Release 4.4.0,!1215Issue #3303390: Add the function to create AWS Transit gateway in the SPA
import EntityFormTemplate from 'model/EntityFormTemplate';
const AWS_CLOUD_TRANSIT_GATEWAY_TEMPLATE: EntityFormTemplate[] = [
{
cloudServiceProvider: 'aws_cloud',
entityName: 'transit_gateway',
actionType: 'create',
entityRecords: [
{
type: 'panel',
panelName: 'Transit gateway',
keyValueRecords: [
{ type: 'default', labelName: 'Name', name: 'name', defaultValue: '', required: true },
{ type: 'default', labelName: 'Description', name: 'description', defaultValue: '', required: true },
{ type: 'default', labelName: 'Amazon side ASN', name: 'amazon_side_asn', defaultValue: '', required: true },
{ type: 'boolean', labelName: 'DNS support', name: 'dns_support', defaultValue: true },
{ type: 'boolean', labelName: 'VPN ECMP support', name: 'vpn_ecmp_support', defaultValue: true },
{ type: 'boolean', labelName: 'Default route table association', name: 'default_route_table_association', defaultValue: true },
{ type: 'boolean', labelName: 'Default route table propagation', name: 'default_route_table_propagation', defaultValue: true },
{ type: 'boolean', labelName: 'Multicast support', name: 'multicast_support', defaultValue: false },
{ type: 'boolean', labelName: 'Auto accept shared attachments', name: 'auto_accept_shared_attachments', defaultValue: false },
]
}
]
}
]
export default AWS_CLOUD_TRANSIT_GATEWAY_TEMPLATE;
...@@ -4,6 +4,7 @@ import AWS_CLOUD_KEY_PAIR_TEMPLATE from 'constant/form_template/aws_cloud/key_pa ...@@ -4,6 +4,7 @@ import AWS_CLOUD_KEY_PAIR_TEMPLATE from 'constant/form_template/aws_cloud/key_pa
import AWS_CLOUD_SECURITY_GROUP_TEMPLATE from 'constant/form_template/aws_cloud/security_group'; import AWS_CLOUD_SECURITY_GROUP_TEMPLATE from 'constant/form_template/aws_cloud/security_group';
import AWS_CLOUD_CARRIER_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/carrier_gateway'; import AWS_CLOUD_CARRIER_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/carrier_gateway';
import AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/internet_gateway'; import AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/internet_gateway';
import AWS_CLOUD_TRANSIT_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/transit_gateway';
import K8S_DEPLOYMENT_TEMPLATE from 'constant/form_template/k8s/deployment'; import K8S_DEPLOYMENT_TEMPLATE from 'constant/form_template/k8s/deployment';
import K8S_NAMESPACE_TEMPLATE from 'constant/form_template/k8s/namespace'; import K8S_NAMESPACE_TEMPLATE from 'constant/form_template/k8s/namespace';
import K8S_OTHER_TEMPLATE from 'constant/form_template/k8s/other'; import K8S_OTHER_TEMPLATE from 'constant/form_template/k8s/other';
...@@ -26,6 +27,7 @@ const ENTITY_FORM_LIST = [ ...@@ -26,6 +27,7 @@ const ENTITY_FORM_LIST = [
...AWS_CLOUD_SECURITY_GROUP_TEMPLATE, ...AWS_CLOUD_SECURITY_GROUP_TEMPLATE,
...AWS_CLOUD_CARRIER_GATEWAY_TEMPLATE, ...AWS_CLOUD_CARRIER_GATEWAY_TEMPLATE,
...AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE, ...AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE,
...AWS_CLOUD_TRANSIT_GATEWAY_TEMPLATE,
...K8S_DEPLOYMENT_TEMPLATE, ...K8S_DEPLOYMENT_TEMPLATE,
...K8S_NAMESPACE_TEMPLATE, ...K8S_NAMESPACE_TEMPLATE,
...K8S_POD_TEMPLATE, ...K8S_POD_TEMPLATE,
......
...@@ -1151,3 +1151,14 @@ entity.aws_cloud_internet_gateway.create: ...@@ -1151,3 +1151,14 @@ entity.aws_cloud_internet_gateway.create:
methods: [ POST ] methods: [ POST ]
requirements: requirements:
_permission: 'add aws cloud internet gateway' _permission: 'add aws cloud internet gateway'
entity.aws_cloud_transit_gateway.create:
path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_transit_gateway/create'
defaults:
_controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
entity_type_id: aws_cloud_transit_gateway
entity_id: ''
command: create
methods: [ POST ]
requirements:
_permission: 'add aws cloud transit gateway'
...@@ -839,6 +839,21 @@ class ApiController extends ControllerBase implements ApiControllerInterface { ...@@ -839,6 +839,21 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
$method_name = 'createCarrierGateway'; $method_name = 'createCarrierGateway';
break; break;
case 'create_aws_cloud_transit_gateway':
/** @var \Drupal\aws_cloud\Entity\Vpc\TransitGatewayInterface $entity */
$entity->setName($request->get('name', ''));
$entity->setDescription($request->get('description', ''));
$entity->setAmazonSideAsn($request->get('amazon_side_asn', ''));
// Use filter_var() to convert from string to boolean.
$entity->setDnsSupport(filter_var($request->get('dns_support'), FILTER_VALIDATE_BOOLEAN));
$entity->setVpnEcmpSupport(filter_var($request->get('vpn_ecmp_support', FALSE), FILTER_VALIDATE_BOOLEAN));
$entity->setDefaultRouteTableAssociation(filter_var($request->get('default_route_table_association', FALSE), FILTER_VALIDATE_BOOLEAN));
$entity->setDefaultRouteTablePropagation(filter_var($request->get('default_route_table_propagation', FALSE), FILTER_VALIDATE_BOOLEAN));
$entity->setMulticastSupport(filter_var($request->get('multicast_support', FALSE), FILTER_VALIDATE_BOOLEAN));
$entity->setAutoAcceptSharedAttachments(filter_var($request->get('auto_accept_shared_attachments', FALSE), FILTER_VALIDATE_BOOLEAN));
$method_name = 'createTransitGateway';
break;
case 'create_aws_cloud_internet_gateway': case 'create_aws_cloud_internet_gateway':
/** @var \Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface $entity */ /** @var \Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface $entity */
$entity->setName($request->get('name', '')); $entity->setName($request->get('name', ''));
......
...@@ -3,8 +3,25 @@ ...@@ -3,8 +3,25 @@
namespace Drupal\aws_cloud\Form\Vpc; namespace Drupal\aws_cloud\Form\Vpc;
use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm;
use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface;
use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\cloud\Service\CloudServiceInterface;
use Drupal\cloud\Service\EntityLinkRendererInterface;
use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\cloud\Traits\CloudContentEntityTrait;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Form controller for the transit gateway entity create form. * Form controller for the transit gateway entity create form.
...@@ -15,6 +32,112 @@ class TransitGatewayCreateForm extends AwsCloudContentForm { ...@@ -15,6 +32,112 @@ class TransitGatewayCreateForm extends AwsCloudContentForm {
use CloudContentEntityTrait; use CloudContentEntityTrait;
/**
* The AWS Cloud Operations service.
*
* @var \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface
*/
protected $awsCloudOperationsService;
/**
* TransitGatewayCreateForm constructor.
*
* @param \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface $aws_cloud_operations_service
* The AWS Cloud Operations service.
* @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service
* The AWS Cloud or OpenStack EC2 Service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Messenger\Messenger $messenger
* The Messenger Service.
* @param \Drupal\cloud\Service\EntityLinkRendererInterface $entity_link_renderer
* The entity link render service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity Type Manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender
* A cache backend interface instance.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* A plugin cache clear instance.
* @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud service provider plugin manager (CloudConfigPluginManager).
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The general renderer.
* @param \Drupal\cloud\Service\CloudServiceInterface $cloud_service
* The Cloud service.
*/
public function __construct(
AwsCloudOperationsServiceInterface $aws_cloud_operations_service,
Ec2ServiceInterface $ec2_service,
EntityRepositoryInterface $entity_repository,
EntityTypeBundleInfoInterface $entity_type_bundle_info,
TimeInterface $time,
Messenger $messenger,
EntityLinkRendererInterface $entity_link_renderer,
EntityTypeManagerInterface $entity_type_manager,
CacheBackendInterface $cacheRender,
CachedDiscoveryClearerInterface $plugin_cache_clearer,
CloudConfigPluginManagerInterface $cloud_config_plugin_manager,
AccountInterface $current_user,
RouteMatchInterface $route_match,
DateFormatterInterface $date_formatter,
RendererInterface $renderer,
CloudServiceInterface $cloud_service
) {
parent::__construct(
$ec2_service,
$entity_repository,
$entity_type_bundle_info,
$time,
$messenger,
$entity_link_renderer,
$entity_type_manager,
$cacheRender,
$plugin_cache_clearer,
$cloud_config_plugin_manager,
$current_user,
$route_match,
$date_formatter,
$renderer,
$cloud_service
);
$this->awsCloudOperationsService = $aws_cloud_operations_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('aws_cloud.operations'),
$container->get('aws_cloud.ec2'),
$container->get('entity.repository'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time'),
$container->get('messenger'),
$container->get('entity.link_renderer'),
$container->get('entity_type.manager'),
$container->get('cache.render'),
$container->get('plugin.cache_clearer'),
$container->get('plugin.manager.cloud_config_plugin'),
$container->get('current_user'),
$container->get('current_route_match'),
$container->get('date.formatter'),
$container->get('renderer'),
$container->get('cloud')
);
}
/** /**
* Overrides Drupal\Core\Entity\EntityFormController::buildForm(). * Overrides Drupal\Core\Entity\EntityFormController::buildForm().
* *
...@@ -150,57 +273,7 @@ class TransitGatewayCreateForm extends AwsCloudContentForm { ...@@ -150,57 +273,7 @@ class TransitGatewayCreateForm extends AwsCloudContentForm {
* @throws \Drupal\aws_cloud\Service\Ec2\Ec2ServiceException * @throws \Drupal\aws_cloud\Service\Ec2\Ec2ServiceException
*/ */
public function save(array $form, FormStateInterface $form_state): void { public function save(array $form, FormStateInterface $form_state): void {
$this->trimTextfields($form, $form_state); $this->awsCloudOperationsService->createTransitGateway($this->entity, $form, $form_state);
$cloud_context = $this->routeMatch->getParameter('cloud_context');
$entity = $this->entity;
$entity->setCloudContext($cloud_context);
$params = [];
if (!empty($entity->getDescription())) {
$params['Description'] = $entity->getDescription();
}
if (!empty($entity->getAmazonSideAsn())) {
$params['Options']['AmazonSideAsn'] = $entity->getAmazonSideAsn();
}
$params['Options']['AutoAcceptSharedAttachments'] = $entity->isAutoAcceptSharedAttachments() ? 'enable' : 'disable';
$params['Options']['DefaultRouteTableAssociation'] = $entity->isDefaultRouteTableAssociation() ? 'enable' : 'disable';
$params['Options']['DefaultRouteTablePropagation'] = $entity->isDefaultRouteTablePropagation() ? 'enable' : 'disable';
$params['Options']['DnsSupport'] = $entity->isDnsSupport() ? 'enable' : 'disable';
$params['Options']['MulticastSupport'] = $entity->isMulticastSupport() ? 'enable' : 'disable';
$params['Options']['VpnEcmpSupport'] = $entity->isVpnEcmpSupport() ? 'enable' : 'disable';
$result = $this->ec2Service->createTransitGateway($params);
$form_state->setRedirect(
'view.aws_cloud_transit_gateway.list',
['cloud_context' => $entity->getCloudContext()]
);
if ($result === NULL) {
$this->processOperationErrorStatus($entity, 'created');
return;
}
if (!empty($result['SendToWorker'])) {
$this->processOperationStatus($entity, 'created remotely');
return;
}
$entity->setTransitGatewayId($result['TransitGateway']['TransitGatewayId']);
$entity->save();
$this->updateNameAndCreatedByTags($entity, $entity->getTransitGatewayId());
// Update the transit gateway.
$this->ec2Service->updateTransitGateways([
'TransitGatewayIds' => [$entity->getTransitGatewayId()],
], FALSE);
$this->processOperationStatus($entity, 'created');
$this->clearCacheValues($entity->getCacheTags());
$this->dispatchSaveEvent($entity);
} }
} }
...@@ -11,6 +11,7 @@ use Drupal\aws_cloud\Entity\Ec2\SecurityGroup; ...@@ -11,6 +11,7 @@ use Drupal\aws_cloud\Entity\Ec2\SecurityGroup;
use Drupal\aws_cloud\Entity\Ec2\SecurityGroupInterface; use Drupal\aws_cloud\Entity\Ec2\SecurityGroupInterface;
use Drupal\aws_cloud\Entity\Vpc\CarrierGatewayInterface; use Drupal\aws_cloud\Entity\Vpc\CarrierGatewayInterface;
use Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface; use Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface;
use Drupal\aws_cloud\Entity\Vpc\TransitGatewayInterface;
use Drupal\aws_cloud\Form\Ec2\InstanceEditForm; use Drupal\aws_cloud\Form\Ec2\InstanceEditForm;
use Drupal\aws_cloud\Plugin\Field\FieldType\IpPermission; use Drupal\aws_cloud\Plugin\Field\FieldType\IpPermission;
use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface;
...@@ -839,6 +840,66 @@ class AwsCloudOperationsService implements AwsCloudOperationsServiceInterface { ...@@ -839,6 +840,66 @@ class AwsCloudOperationsService implements AwsCloudOperationsServiceInterface {
} }
} }
/**
* {@inheritdoc}
*/
public function createTransitGateway(TransitGatewayInterface $entity, array &$form, FormStateInterface $form_state): bool {
try {
$this->trimTextfields($entity, $form, $form_state);
$this->ec2Service->setCloudContext($entity->getCloudContext());
$params = [];
if (!empty($entity->getDescription())) {
$params['Description'] = $entity->getDescription();
}
if (!empty($entity->getAmazonSideAsn())) {
$params['Options']['AmazonSideAsn'] = $entity->getAmazonSideAsn();
}
$params['Options']['AutoAcceptSharedAttachments'] = $entity->isAutoAcceptSharedAttachments() === TRUE ? 'enable' : 'disable';
$params['Options']['DefaultRouteTableAssociation'] = $entity->isDefaultRouteTableAssociation() === TRUE ? 'enable' : 'disable';
$params['Options']['DefaultRouteTablePropagation'] = $entity->isDefaultRouteTablePropagation() === TRUE ? 'enable' : 'disable';
$params['Options']['DnsSupport'] = $entity->isDnsSupport() === TRUE ? 'enable' : 'disable';
$params['Options']['MulticastSupport'] = $entity->isMulticastSupport() === TRUE ? 'enable' : 'disable';
$params['Options']['VpnEcmpSupport'] = $entity->isVpnEcmpSupport() === TRUE ? 'enable' : 'disable';
$result = $this->ec2Service->createTransitGateway($params);
$form_state->setRedirect(
'view.aws_cloud_transit_gateway.list',
['cloud_context' => $entity->getCloudContext()]
);
if ($result === NULL) {
$this->processOperationErrorStatus($entity, 'created');
return FALSE;
}
if (!empty($result['SendToWorker'])) {
$this->processOperationStatus($entity, 'created remotely');
return TRUE;
}
$entity->setTransitGatewayId($result['TransitGateway']['TransitGatewayId']);
$entity->save();
$this->updateNameAndCreatedByTags($entity, $entity->getTransitGatewayId());
// Update the transit gateway.
$this->ec2Service->updateTransitGateways([
'TransitGatewayIds' => [$entity->getTransitGatewayId()],
], FALSE);
$this->processOperationStatus($entity, 'created');
$this->clearCacheValues($entity->getCacheTags());
$this->dispatchSaveEvent($entity);
return TRUE;
}
catch (\Exception $e) {
$this->handleException($e);
$this->processOperationErrorStatus($entity, 'created');
return FALSE;
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -10,6 +10,7 @@ use Drupal\aws_cloud\Entity\Ec2\SecurityGroup; ...@@ -10,6 +10,7 @@ use Drupal\aws_cloud\Entity\Ec2\SecurityGroup;
use Drupal\aws_cloud\Entity\Ec2\SecurityGroupInterface; use Drupal\aws_cloud\Entity\Ec2\SecurityGroupInterface;
use Drupal\aws_cloud\Entity\Vpc\CarrierGatewayInterface; use Drupal\aws_cloud\Entity\Vpc\CarrierGatewayInterface;
use Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface; use Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface;
use Drupal\aws_cloud\Entity\Vpc\TransitGatewayInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldItemList; use Drupal\Core\Field\FieldItemList;
...@@ -256,6 +257,24 @@ interface AwsCloudOperationsServiceInterface { ...@@ -256,6 +257,24 @@ interface AwsCloudOperationsServiceInterface {
*/ */
public function createInternetGateway(InternetGatewayInterface $entity, array &$form, FormStateInterface $form_state): bool; public function createInternetGateway(InternetGatewayInterface $entity, array &$form, FormStateInterface $form_state): bool;
/**
* Create transit gateway.
*
* @param \Drupal\aws_cloud\Entity\Vpc\TransitGatewayInterface $entity
* TransitGateway entity.
* @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.
*
* @return bool
* Boolean status.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
public function createTransitGateway(TransitGatewayInterface $entity, array &$form, FormStateInterface $form_state): bool;
/** /**
* Create a KeyPair. * Create a KeyPair.
* *
......
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