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

Issue #3187780 by yas, Xiaohua Guan: Manage Transit Gateways (Edit)

parent a13b020c
No related branches found
No related tags found
No related merge requests found
......@@ -725,7 +725,7 @@ entity.aws_cloud_transit_gateway.collection:
title: 'List AWS Cloud Transit Gateways'
appears_on:
- entity.aws_cloud_transit_gateway.add_form
# - entity.aws_cloud_transit_gateway.edit_form
- entity.aws_cloud_transit_gateway.edit_form
- entity.aws_cloud_transit_gateway.delete_form
- entity.aws_cloud_transit_gateway.canonical
......@@ -741,11 +741,11 @@ entity.aws_cloud_all_aws_cloud_transit_gateway.refresh:
appears_on:
- view.aws_cloud_transit_gateway.all
# entity.aws_cloud_transit_gateway.edit:
# route_name: entity.aws_cloud_transit_gateway.edit_form
# title: 'Edit'
# appears_on:
# - entity.aws_cloud_transit_gateway.canonical
entity.aws_cloud_transit_gateway.edit:
route_name: entity.aws_cloud_transit_gateway.edit_form
title: 'Edit'
appears_on:
- entity.aws_cloud_transit_gateway.canonical
entity.aws_cloud_transit_gateway.delete:
route_name: entity.aws_cloud_transit_gateway.delete_form
......
......@@ -23,14 +23,14 @@ class TransitGatewayViewBuilder extends AwsCloudViewBuilder {
'state',
'account_id',
'amazon_side_asn',
'association_default_route_table_id',
'dns_support',
'vpn_ecmp_support',
'auto_accept_shared_attachments',
'multicast_support',
'default_route_table_association',
'association_default_route_table_id',
'default_route_table_propagation',
'dns_support',
'multicast_support',
'propagation_default_route_table_id',
'vpn_ecmp_support',
'created',
],
],
......
<?php
namespace Drupal\aws_cloud\Form\Vpc;
use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm;
use Drupal\cloud\Traits\CloudContentEntityTrait;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for the Transit Gateway entity edit forms.
*
* @ingroup aws_cloud
*/
class TransitGatewayEditForm extends AwsCloudContentForm {
use CloudContentEntityTrait;
/**
* Overrides Drupal\Core\Entity\EntityFormController::buildForm().
*
* @param array $form
* Array of form object.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
* @param string $cloud_context
* A cloud_context string value from URL "path".
*
* @return array
* Array of form object.
*/
public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') {
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
if (!$this->updateEntityBuildForm($entity)) {
return $this->redirectUrl;
}
$this->ec2Service->setCloudContext($entity->getCloudContext());
$weight = -50;
$form['transit_gateway'] = [
'#type' => 'details',
'#title' => $this->t('Transit Gateway'),
'#open' => TRUE,
'#weight' => $weight++,
];
$form['transit_gateway']['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#maxlength' => 255,
'#size' => 60,
'#default_value' => $entity->label(),
'#required' => TRUE,
];
$form['transit_gateway']['description'] = [
'#type' => 'textfield',
'#title' => $this->t('Description'),
'#maxlength' => 255,
'#size' => 60,
'#default_value' => $entity->getDescription(),
];
$form['transit_gateway']['transit_gateway_id'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Transit Gateway ID')),
'#markup' => $entity->getTransitGatewayId(),
];
$form['transit_gateway']['state'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('State')),
'#markup' => $entity->getState(),
];
$form['transit_gateway']['amazon_side_asn'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Amazon side ASN')),
'#markup' => $entity->getAmazonSideAsn(),
];
$form['transit_gateway']['multicast_support'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Multicast support')),
'#markup' => $entity->isMulticastSupport() ? 'enable' : 'disable',
];
$form['transit_gateway']['created'] = [
'#type' => 'item',
'#title' => $this->getItemTitle($this->t('Created')),
'#markup' => $this->dateFormatter->format($entity->created(), 'short'),
];
$form['transit_gateway']['dns_support'] = [
'#type' => 'checkbox',
'#title' => $this->t('DNS support'),
'#description' => $this->t('Enable Domain Name System resolution for VPCs attached to this Transit Gateway.'),
'#default_value' => $entity->isDnsSupport(),
];
$form['transit_gateway']['vpn_ecmp_support'] = [
'#type' => 'checkbox',
'#title' => $this->t('VPN ECMP support'),
'#description' => $this->t('Equal-cost multi-path routing for VPN Connections that are attached to this Transit Gateway.'),
'#default_value' => $entity->isVpnEcmpSupport(),
];
$form['transit_gateway']['default_route_table_association'] = [
'#type' => 'checkbox',
'#title' => $this->t('Default route table association'),
'#description' => $this->t("Automatically associate Transit Gateway attachments with this Transit Gateway's default route table."),
'#default_value' => $entity->isDefaultRouteTableAssociation(),
];
$result = $this->ec2Service->describeTransitGatewayRouteTables([
'Filters' => [
[
'Name' => 'transit-gateway-id',
'Values' => [$entity->getTransitGatewayId()],
],
],
]);
$options = [];
foreach ($result['TransitGatewayRouteTables'] as $route_table) {
$options[$route_table['TransitGatewayRouteTableId']] = $route_table['TransitGatewayRouteTableId'];
}
$form['transit_gateway']['association_default_route_table_id'] = [
'#type' => 'select',
'#title' => $this->t('Association Default Route Table ID'),
'#options' => $options,
'#default_value' => $entity->getAssociationDefaultRouteTableId(),
'#states' => [
'visible' => [
':input[name="default_route_table_association"]' => ['checked' => TRUE],
],
],
];
$form['transit_gateway']['default_route_table_propagation'] = [
'#type' => 'checkbox',
'#title' => $this->t('Default route table propagation'),
'#description' => $this->t("Automatically propagate Transit Gateway attachments with this Transit Gateway's default route table."),
'#default_value' => $entity->isDefaultRouteTablePropagation(),
];
$form['transit_gateway']['propagation_default_route_table_id'] = [
'#type' => 'select',
'#title' => $this->t('Propagation Default Route Table ID'),
'#options' => $options,
'#default_value' => $entity->getPropagationDefaultRouteTableId(),
'#states' => [
'visible' => [
':input[name="default_route_table_propagation"]' => ['checked' => TRUE],
],
],
];
$form['transit_gateway']['auto_accept_shared_attachments'] = [
'#type' => 'checkbox',
'#title' => $this->t('Auto accept shared attachments'),
'#description' => $this->t('Automatically accept cross account attachments that are attached to this Transit Gateway.'),
'#default_value' => $entity->isAutoAcceptSharedAttachments(),
];
$form['fieldset_tags'] = [
'#type' => 'details',
'#title' => $this->t('Tags'),
'#open' => TRUE,
'#weight' => $weight++,
];
$form['fieldset_tags'][] = $form['tags'];
unset($form['tags']);
$this->addOthersFieldset($form, $weight++, $cloud_context);
$form['actions'] = $this->actions($form, $form_state, $cloud_context);
$form['actions']['#weight'] = $weight++;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
// Call copyFormItemValues() to ensure the form array is intact.
$this->copyFormItemValues($form);
$this->trimTextfields($form, $form_state);
$entity = $this->entity;
$old_transit_gateway = $this->entityTypeManager
->getStorage('aws_cloud_transit_gateway')
->load($entity->id());
$this->ec2Service->setCloudContext($entity->getCloudContext());
if (!empty($old_transit_gateway) && $entity->save()) {
// Modify transit gateway.
$params = [
'Description' => $entity->getDescription(),
'TransitGatewayId' => $entity->getTransitGatewayId(),
'Options' => [
'AutoAcceptSharedAttachments' => $entity->isAutoAcceptSharedAttachments() ? 'enable' : 'disable',
'DefaultRouteTableAssociation' => $entity->isDefaultRouteTableAssociation() ? 'enable' : 'disable',
'DefaultRouteTablePropagation' => $entity->isDefaultRouteTablePropagation() ? 'enable' : 'disable',
'DnsSupport' => $entity->isDnsSupport() ? 'enable' : 'disable',
'VpnEcmpSupport' => $entity->isVpnEcmpSupport() ? 'enable' : 'disable',
],
];
if ($entity->isDefaultRouteTableAssociation()) {
$params['Options']['AssociationDefaultRouteTableId'] = $entity->getAssociationDefaultRouteTableId();
}
if ($entity->isDefaultRouteTablePropagation()) {
$params['Options']['PropagationDefaultRouteTableId'] = $entity->getPropagationDefaultRouteTableId();
}
$this->ec2Service->modifyTransitGateway($params);
// Update tags.
$tag_map = [];
foreach ($entity->getTags() ?: [] as $tag) {
$tag_map[$tag['item_key']] = $tag['item_value'];
}
$this->setTagsInAws($entity->getTransitGatewayId(), $tag_map);
$this->updateNameAndCreatedByTags($entity, $entity->getTransitGatewayId());
// Update the transit gateway.
$this->ec2Service->updateTransitGateways([
'TransitGatewayId' => $entity->getTransitGatewayId(),
], FALSE);
$this->processOperationStatus($entity, 'updated');
$this->clearCacheValues();
}
else {
$this->messenger->addError($this->t('Unable to update @label.', [
'@label' => $entity->getEntityType()->getSingularLabel(),
]));
}
$form_state->setRedirect('view.aws_cloud_transit_gateway.list', [
'cloud_context' => $entity->getCloudContext(),
]);
}
}
......@@ -518,6 +518,14 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface {
return $this->execute('ModifyImageAttribute', $params);
}
/**
* {@inheritdoc}
*/
public function modifyTransitGateway(array $params = []) {
$params += $this->getDefaultParameters();
return $this->execute('ModifyTransitGateway', $params);
}
/**
* {@inheritdoc}
*/
......@@ -816,6 +824,14 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface {
return $this->execute('DescribeTransitGateways', $params);
}
/**
* {@inheritdoc}
*/
public function describeTransitGatewayRouteTables(array $params = []) {
$params += $this->getDefaultParameters();
return $this->execute('DescribeTransitGatewayRouteTables', $params);
}
/**
* {@inheritdoc}
*/
......
......@@ -144,6 +144,14 @@ interface Ec2ServiceInterface {
*/
public function modifyImageAttribute(array $params = []);
/**
* Modifies transit gateway.
*
* @param array $params
* Parameters array to send to API.
*/
public function modifyTransitGateway(array $params = []);
/**
* Calls the Amazon EC2 API endpoint Create Key Pair.
*
......@@ -651,6 +659,20 @@ interface Ec2ServiceInterface {
*/
public function describeTransitGateways(array $params = []);
/**
* Calls the Amazon EC2 API endpoint DescribeTransitGatewayRouteTables.
*
* @param array $params
* Parameters array to send to API.
*
* @return array
* Array of VPCs or NULL if there is an error.
*
* @throws \Drupal\aws_cloud\Service\Ec2\Ec2ServiceException
* If the $params is empty or $ec2_client (Ec2Client) is NULL.
*/
public function describeTransitGatewayRouteTables(array $params = []);
/**
* Calls the Amazon EC2 API endpoint AssociateVpcCidrBlock.
*
......
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