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

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

Issue #3284776 by Masami, Ryo Yamashita, yas: Add the function to create Openstack Floating IP in the SPA
parent c9ca5353
Loading
Loading
Loading
Loading
+1 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/entity_form_template.ts: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ const ENTITY_FORM_LIST = [
  ...K8S_SCHEDULE_TEMPLATE,
  // K8S_OTHER_TEMPLATE must be registered after the other K8S_XXX_TEMPLATE.
  ...K8S_OTHER_TEMPLATE,
  ...OPENSTACK_FLOATING_IP_TEMPLATE,
  ...OPENSTACK_INSTANCE_TEMPLATE,
  ...OPENSTACK_IMAGE_TEMPLATE,
  ...OPENSTACK_KEY_PAIR_TEMPLATE,
+24 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/floating_ip.ts: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
import EntityFormTemplate from 'model/EntityFormTemplate';

const OPENSTACK_FLOATING_IP_TEMPLATE: EntityFormTemplate[] = [
  {
    cloudServiceProvider: 'openstack',
    entityName: 'floating_ip',
    actionType: 'create',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Floating IP',
        keyValueRecords: [
          { type: 'default', labelName: 'Name', name: 'name', defaultValue: '' },
          { type: 'select', labelName: 'Floating network ID', name: 'floating_network_id',
            url: '/cloud_dashboard/openstack/{cloud_context}/floating_network_ids',
            defaultValue: '', required: true
          },
        ]
      }
    ]
  }
]

export default OPENSTACK_FLOATING_IP_TEMPLATE;
+26 −0
Changes for modules/cloud_service_providers/openstack/openstack.routing.yml: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -640,3 +640,29 @@ entity.openstack_network_interface.delete:
    _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access'
  options:
      perm: 'delete any openstack network interface+delete own openstack network interface'

entity.openstack_floating_ip.create:
  path: '/cloud_dashboard/openstack/{cloud_context}/openstack_floating_ip/create'
  defaults:
    _controller: '\Drupal\openstack\Controller\ApiController::operateEntity'
    entity_type_id: openstack_floating_ip
    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 openstack floating ip'

entity.openstack_floating_ip.floating_network_ids:
  path: '/cloud_dashboard/openstack/{cloud_context}/floating_network_ids'
  defaults:
    _controller: '\Drupal\openstack\Controller\ApiController::getNetworkInterfaceOptions'
  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 openstack floating ip'
+28 −0
Changes for modules/cloud_service_providers/openstack/src/Controller/ApiController.php: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -574,6 +574,12 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
        $method_name = 'deleteOpenStackNetworkInterface';
        break;

      case 'create_openstack_floating_ip':
        $original_entity->setName($request->get('name', ''));
        $form_state->setValue('floating_network_id', $request->get('floating_network_id', ''));
        $method_name = 'createOpenStackFloatingIp';
        break;

    }

    // Execute the process.
@@ -597,4 +603,26 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
      ], 500);
  }

  /**
   * {@inheritdoc}
   */
  public function getNetworkInterfaceOptions(string $cloud_context): JsonResponse {
    $options = [];
    $network_interfaces = $this->entityTypeManager
      ->getStorage('openstack_network_interface')
      ->loadByProperties([
        'cloud_context' => $cloud_context,
        'external' => TRUE,
      ]);

    foreach ($network_interfaces ?: [] as $network_interface) {
      $options[] = [
        'value' => $network_interface->getNetworkInterfaceId(),
        'label' => $network_interface->getName(),
      ];
    }

    return new JsonResponse($options);
  }

}
+11 −0
Changes for modules/cloud_service_providers/openstack/src/Controller/ApiControllerInterface.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -139,4 +139,15 @@ interface ApiControllerInterface {
   */
  public function operateEntity(Request $request, string $cloud_context, string $entity_type_id, string $entity_id, string $command): JsonResponse;

  /**
   * Get options of network interface.
   *
   * @param string $cloud_context
   *   Cloud context.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   */
  public function getNetworkInterfaceOptions(string $cloud_context): JsonResponse;

}
Loading