Skip to content
Snippets Groups Projects
Commit 88c07343 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 27711ee3
Branches
Tags
3 merge requests!1759Issue #3356778: Release 5.1.1,!1679Issue #3349074: Fix the OpenStack Project create and edit form in SPA that "Member" cannot be saved due to a validation error,!1607Issue #3343582: Add the function to preview OpenStack stack in the SPA
......@@ -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,
......
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;
......@@ -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;
}
......
......@@ -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:
......
......@@ -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;
......
......@@ -364,10 +364,12 @@ interface ApiControllerInterface {
*
* @param string $cloud_context
* The cloud context.
* @param array $properties
* The properties of EntityTypeManager.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* The JSON response.
*/
public function getNetworkOptions($cloud_context): JsonResponse;
public function getNetworkOptions(string $cloud_context, array $properties): JsonResponse;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment