Commit afe461de authored by Masami  Suzuki's avatar Masami Suzuki Committed by Yas Naoi
Browse files

Issue #3307733 by Masami, yas, Ryo Yamashita: Add the function to...

Issue #3307733 by Masami, yas, Ryo Yamashita: Add the function to create/delete/edit AWS Snapshot in the SPA 
parent 0377a24f
Loading
Loading
Loading
Loading
+59 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/aws_cloud/snapshot.ts: 59 added lines, 0 removed lines.
Original line number Diff line number Diff line
import EntityFormTemplate from 'model/EntityFormTemplate';

const AWS_CLOUD_SNAPSHOT_TEMPLATE: EntityFormTemplate[] = [
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'snapshot',
    actionType: 'create',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Snapshot',
        keyValueRecords: [
          { type: 'default', labelName: 'Name', name: 'name', defaultValue: '' },
          { type: 'select', labelName: 'Volume ID', name: 'volume_id',
            url: '/cloud_dashboard/aws_cloud/{cloud_context}/snapshot_volume_ids',
            defaultValue: '', required: true
          },
          { type: 'default', labelName: 'Description', name: 'description', defaultValue: '' },
        ]
      }
    ]
  },
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'snapshot',
    actionType: 'delete',
    entityRecords: [
      {
        type: 'label',
        text: 'Are you sure you want to delete the {{entityName}} {{name}}?'
      },
    ],
    submitButtonLabel: 'Delete'
  },
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'snapshot',
    actionType: 'edit',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Snapshot',
	      keyValueRecords: [
          { type: 'default', labelName: 'Name', name: 'name', defaultValue: '' },
          { type: 'default', labelName: 'Description', name: 'description', defaultValue: '', readOnly: true },
          { type: 'default', labelName: 'Snapshot ID', name: 'snapshot_id', defaultValue: '', readOnly: true },
          { type: 'default', labelName: 'Volume ID', name: 'volume_id', defaultValue: '', readOnly: true },
          { type: 'default', labelName: 'Size (GB)', name: 'size', defaultValue: '', readOnly: true },
          { type: 'default', labelName: 'Status', name: 'status', defaultValue: '', readOnly: true },
          { type: 'default', labelName: 'Progress', name: 'Progress', defaultValue: '', readOnly: true },
          { type: 'boolean', labelName: 'Encrypted', name: 'encrypted_value', defaultValue: false },
          { type: 'datetime', labelName: 'Created', name: 'created', defaultValue: 0, readOnly: true },
	      ]
      }
    ]
  },
]

export default AWS_CLOUD_SNAPSHOT_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
@@ -6,6 +6,7 @@ import AWS_CLOUD_INTERNET_GATEWAY_TEMPLATE from 'constant/form_template/aws_clou
import AWS_CLOUD_KEY_PAIR_TEMPLATE from 'constant/form_template/aws_cloud/key_pair';
import AWS_CLOUD_NETWORK_INTERFACE_TEMPLATE from 'constant/form_template/aws_cloud/network_interface';
import AWS_CLOUD_SECURITY_GROUP_TEMPLATE from 'constant/form_template/aws_cloud/security_group';
import AWS_CLOUD_SNAPSHOT from 'constant/form_template/aws_cloud/snapshot';
import AWS_CLOUD_SUBNET_TEMPLATE from 'constant/form_template/aws_cloud/subnet';
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';
@@ -38,6 +39,7 @@ const ENTITY_FORM_LIST = [
  ...AWS_CLOUD_VPC_TEMPLATE,
  ...AWS_CLOUD_VPC_PEERING_CONNECTION,
  ...AWS_CLOUD_SUBNET_TEMPLATE,
  ...AWS_CLOUD_SNAPSHOT,
  ...K8S_DEPLOYMENT_TEMPLATE,
  ...K8S_NAMESPACE_TEMPLATE,
  ...K8S_POD_TEMPLATE,
+54 −0
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.routing.yml: 54 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1512,3 +1512,57 @@ entity.aws_cloud_vpc_peering_connection.create:
  methods: [ POST ]
  requirements:
    _permission: 'add aws cloud vpc peering connection'

entity.aws_cloud_snapshot.create:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_snapshot/create'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_snapshot
    entity_id: ''
    command: create
  methods: [POST]
  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: 'add aws cloud snapshot'

entity.aws_cloud_snapshot.edit:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_snapshot/{entity_id}/edit'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_snapshot
    command: edit
  methods: [POST]
  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: 'edit any aws cloud snapshot+edit own aws cloud snapshot'

entity.aws_cloud_snapshot.snapshot_volume_ids:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/snapshot_volume_ids'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::getVolumeOptions'
  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: 'add aws cloud snapshot'

entity.aws_cloud_snapshot.delete:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_snapshot/{entity_id}/delete'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_snapshot
    command: delete
  methods: [POST]
  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: 'delete any aws cloud snapshot+delete own aws cloud snapshot'
+48 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -930,6 +930,14 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
          $method_name = 'createVpcPeeringConnection';
          break;

        case 'create_aws_cloud_snapshot':
          /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */
          $entity->setName($request->get('name', ''));
          $entity->set('volume_id', $request->get('volume_id', ''));
          $entity->set('description', $request->get('description', ''));
          $method_name = 'createSnapshot';
          break;

        case 'delete_aws_cloud_elastic_ip':
          $method_name = 'deleteElasticIp';
          break;
@@ -950,6 +958,10 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
          $method_name = 'deleteNetworkInterface';
          break;

        case 'delete_aws_cloud_snapshot':
          $method_name = 'deleteSnapshot';
          break;

        case 'disassociate_aws_cloud_elastic_ip':
          $method_name = 'disassociateElasticIp';
          break;
@@ -1011,6 +1023,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
          $method_name = 'editSecurityGroup';
          break;

        case 'edit_aws_cloud_snapshot':
          /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */
          $entity->setName($request->get('name', ''));
          $entity->setEncrypted(empty(filter_var($request->get('encrypted_value', FALSE), FILTER_VALIDATE_BOOLEAN)) ? 'Not Encrypted' : 'Encrypted');
          $method_name = 'editSnapshot';
          break;

        case 'import_aws_cloud_key_pair':
          /** @var \Drupal\aws_cloud\Entity\Ec2\KeyPairInterface $entity */
          $entity->set('key_pair_name', $request->get('key_pair_name', ''));
@@ -1683,4 +1702,33 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
    return new JsonResponse($options);
  }

  /**
   * {@inheritdoc}
   */
  public function getVolumeOptions($cloud_context): JsonResponse {
    $options = [];
    $params = [
      'cloud_context' => $cloud_context,
    ];

    if (!$this->currentUser->hasPermission("view any aws cloud volume")) {
      $params['uid'] = $this->currentUser->id();
    }

    $volumes = $this->entityTypeManager
      ->getStorage("aws_cloud_volume")
      ->loadByProperties($params);

    foreach ($volumes ?: [] as $volume) {
      $options[] = [
        'value' => $volume->getVolumeId(),
        'label' => $volume->getName() !== $volume->getVolumeId()
          ? "{$volume->getName()} ({$volume->getVolumeId()})"
          : $volume->getVolumeId(),
      ];
    }

    return new JsonResponse($options);
  }

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

  /**
   * Helper function to get volume options.
   *
   * @param string $cloud_context
   *   Cloud context to use in the query.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function getVolumeOptions($cloud_context): JsonResponse;

}
Loading