Commit e9d6ea77 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3304580 by baldwinlouie, yas, Ryo Yamashita: Add the function to create...

Issue #3304580 by baldwinlouie, yas, Ryo Yamashita: Add the function to create AWS Subnet in the SPA
parent b842c5f3
Loading
Loading
Loading
Loading
+32 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/aws_cloud/subnet.ts: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
import EntityFormTemplate from 'model/EntityFormTemplate';

const AWS_CLOUD_SUBNET_TEMPLATE: EntityFormTemplate[] = [
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'subnet',
    actionType: 'create',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Subnet',
        keyValueRecords: [
          { type: 'default', labelName: 'Name', name: 'name', defaultValue: '', required: true },
          {
            type: 'select', labelName: 'VPC CIDR (ID)', name: 'vpc_id',
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/vpc_options',
            defaultValue: '',
            required: true,
          },
          {
            type: 'select', labelName: 'Availability Zone', name: 'availability_zone',
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/availability_zone',
            defaultValue: ''
          },
          { type: 'default', labelName: 'IPv4 CIDR block', name: 'cidr_block', defaultValue: '', required: true },
        ]
      }
    ]
  }
]

export default AWS_CLOUD_SUBNET_TEMPLATE;
+2 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/entity_form_template.ts: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,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_TRANSIT_GATEWAY_TEMPLATE from 'constant/form_template/aws_cloud/transit_gateway';
import AWS_CLOUD_VPC_TEMPLATE from 'constant/form_template/aws_cloud/vpc';
import AWS_CLOUD_SUBNET_TEMPLATE from 'constant/form_template/aws_cloud/subnet';
import K8S_DEPLOYMENT_TEMPLATE from 'constant/form_template/k8s/deployment';
import K8S_NAMESPACE_TEMPLATE from 'constant/form_template/k8s/namespace';
import K8S_OTHER_TEMPLATE from 'constant/form_template/k8s/other';
@@ -32,6 +33,7 @@ const ENTITY_FORM_LIST = [
  ...AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE,
  ...AWS_CLOUD_TRANSIT_GATEWAY_TEMPLATE,
  ...AWS_CLOUD_VPC_TEMPLATE,
  ...AWS_CLOUD_SUBNET_TEMPLATE,
  ...K8S_DEPLOYMENT_TEMPLATE,
  ...K8S_NAMESPACE_TEMPLATE,
  ...K8S_POD_TEMPLATE,
+23 −0
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.routing.yml: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1176,6 +1176,18 @@ entity.aws_cloud_security_group.vpc_options:
  options:
    perm: 'access dashboard'

entity.aws_cloud_subnet.availability_zone:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/availability_zone'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::getAvailabilityZones'
  methods: [GET]
  requirements:
    # Use custom access that will check for cloud_context and the desired permission.
    # Desired permission is passed as an option in the "perm" variable
    _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access'
  options:
    perm: 'access dashboard'

entity.aws_cloud_key_pair.create:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_key_pair/create'
  defaults:
@@ -1230,3 +1242,14 @@ entity.aws_cloud_vpc.create:
  methods: [ POST ]
  requirements:
    _permission: 'add aws cloud vpc'

entity.aws_cloud_subnet.create:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_subnet/create'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_subnet
    entity_id: ''
    command: create
  methods: [ POST ]
  requirements:
    _permission: 'add aws cloud subnet'
+24 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -874,6 +874,15 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
          $method_name = 'createVpc';
          break;

        case 'create_aws_cloud_subnet':
          /** @var \Drupal\aws_cloud\Entity\Vpc\SubnetInterface $entity */
          $entity->setName($request->get('name', ''));
          $entity->setVpcId($request->get('vpc_id', ''));
          $entity->setAvailabilityZone($request->get('availability_zone', ''));
          $entity->setCidrBlock($request->get('cidr_block', ''));
          $method_name = 'createSubnet';
          break;

        case 'create_aws_cloud_internet_gateway':
          /** @var \Drupal\aws_cloud\Entity\Vpc\InternetGatewayInterface $entity */
          $entity->setName($request->get('name', ''));
@@ -1238,4 +1247,19 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
    return new JsonResponse($output, 200);
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailabilityZones(string $cloud_context): JsonResponse {
    $zones = $this->getAvailabilityZoneOptions($cloud_context, 'aws_cloud', TRUE);
    $output = [];
    foreach ($zones ?: [] as $value => $label) {
      $output[] = [
        'value' => $value,
        'label' => $label,
      ];
    }
    return new JsonResponse($output, 200);
  }

}
+11 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiControllerInterface.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -236,4 +236,15 @@ interface ApiControllerInterface {
   */
  public function getNetworkBorderGroupOptions(string $cloud_context): JsonResponse;

  /**
   * Get availability zones.
   *
   * @param string $cloud_context
   *   The cloud context to query.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   */
  public function getAvailabilityZones(string $cloud_context): JsonResponse;

}
Loading