Commit da4bd91c authored by Tomotaka Hosomi's avatar Tomotaka Hosomi Committed by Yas Naoi
Browse files

Issue #3325925 by hosomitm, yas, Ryo Yamashita: Add the function to create...

Issue #3325925 by hosomitm, yas, Ryo Yamashita: Add the function to create OpenStack router in the SPA
parent 474f70fd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import OPENSTACK_SNAPSHOT_TEMPLATE from 'constant/templates/form/openstack/snaps
import OPENSTACK_VOLUME_TEMPLATE from 'constant/templates/form/openstack/volume';
import OPENSTACK_NETWORK_TEMPLATE from 'constant/templates/form/openstack/network';
import OPENSTACK_SUBNET_TEMPLATE from 'constant/templates/form/openstack/subnet';
import OPENSTACK_ROUTER_TEMPLATE from 'constant/templates/form/openstack/router';
import VMWARE_VM_TEMPLATE from 'constant/templates/form/vmware/vm';

const ENTITY_FORM_LIST = [
@@ -62,6 +63,7 @@ const ENTITY_FORM_LIST = [
  ...OPENSTACK_VOLUME_TEMPLATE,
  ...OPENSTACK_NETWORK_TEMPLATE,
  ...OPENSTACK_SUBNET_TEMPLATE,
  ...OPENSTACK_ROUTER_TEMPLATE,
  ...OPENSTACK_CLOUD_LAUNCH_TEMPLATE,
  ...VMWARE_VM_TEMPLATE,
  ...AWS_CLOUD_LAUNCH_TEMPLATE,
+30 −0
Original line number Diff line number Diff line
import EntityFormTemplate from 'model/EntityFormTemplate';

const OPENSTACK_NETWORK_TEMPLATE: EntityFormTemplate[] = [
  {
    cloudServiceProvider: 'openstack',
    entityName: 'router',
    actionType: 'create',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Router',
        keyValueRecords: [
          { type: 'default', labelName: 'Name', name: 'name', defaultValue: '', required: true },
          { type: 'boolean', labelName: 'Admin state up', name: 'admin_state_up', defaultValue: true },
          { type: 'select', labelName: 'External Network', name: 'external_gateway_network_id',
            url: '/cloud_dashboard/openstack/{cloud_context}/external_gateway_network_ids',
            defaultValue: ''
          },
          { type: 'boolean', labelName: 'Enable SNAT', name: 'external_gateway_enable_snat', defaultValue: true },
          { type: 'multi-select', labelName: 'Availability Zone', name: 'availability_zone',
            url: '/cloud_dashboard/openstack/{cloud_context}/availability_zones',
            defaultValue: []
          },
        ]
      }
    ]
  }
]

export default OPENSTACK_NETWORK_TEMPLATE;
+11 −0
Original line number Diff line number Diff line
@@ -147,6 +147,17 @@ const showEntityFormBlockFlg = (
    }
  }

  // Create Openstack Router
  if (actionType === 'create'
    && cloudServiceProvider === 'openstack'
    && entityName === 'router') {
    if (entityFormColumn.type === 'boolean') {
      if (entityFormColumn.name === 'external_gateway_enable_snat') {
        return formData['external_gateway_network_id'] !== '';
      }
    }
  }

  return true;
}

+28 −0
Original line number Diff line number Diff line
@@ -1283,6 +1283,34 @@ entity.openstack_port.list_update.all:
    entity_type: 'openstack_port'

# OpenStack router's routes.
entity.openstack_router.create:
  path: '/cloud_dashboard/openstack/{cloud_context}/openstack_router/create'
  defaults:
    _controller: '\Drupal\openstack\Controller\ApiController::operateEntity'
    entity_type_id: openstack_router
    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 router'

entity.openstack_router.external_gateway_network_ids:
  path: '/cloud_dashboard/openstack/{cloud_context}/external_gateway_network_ids'
  defaults:
    _controller: '\Drupal\openstack\Controller\ApiController::getNetworkOptions'
    properties:
      external: 1
  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 router'

entity.openstack_router.add_form:
  path: '/clouds/openstack/{cloud_context}/router/add'
  defaults:
+11 −2
Original line number Diff line number Diff line
@@ -816,6 +816,16 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
        $method_name = 'editOpenStackSubnet';
        break;

      case 'create_openstack_router':
        /** @var \Drupal\openstack\Entity\OpenStackRouter $entity */
        $entity->setName($request->get('name', ''));
        $entity->setAdminStateUp($request->get('admin_state_up', '') === 'true');
        $entity->setExternalGatewayNetworkId($request->get('external_gateway_network_id', ''));
        $entity->setExternalGatewayEnableSnat($request->get('external_gateway_enable_snat', '') === 'true');
        $entity->setAvailabilityZones(json_decode($request->get('availability_zone', '[]'), TRUE));
        $method_name = 'createOpenStackRouter';
        break;

    }

    // Execute the process.
@@ -1260,8 +1270,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
  /**
   * {@inheritdoc}
   */
  public function getNetworkOptions($cloud_context): JsonResponse {
    $properties = [];
  public function getNetworkOptions(string $cloud_context, array $properties = []): JsonResponse {
    $properties['cloud_context'] = $cloud_context;

    $account = $this->currentUser;
Loading