Loading modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/entity_form_template.ts +2 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import K8S_OTHER_TEMPLATE from 'constant/form_template/k8s/other'; import K8S_POD_TEMPLATE from 'constant/form_template/k8s/pod'; import K8S_SCHEDULE_TEMPLATE from 'constant/form_template/k8s/schedule'; import OPENSTACK_IMAGE_TEMPLATE from 'constant/form_template/openstack/image'; import OPENSTACK_KEY_PAIR_TEMPLATE from 'constant/form_template/openstack/key_pair'; import VMWARE_VM_TEMPLATE from 'constant/form_template/vmware/vm'; const ENTITY_FORM_LIST = [ Loading @@ -14,6 +15,7 @@ const ENTITY_FORM_LIST = [ // K8S_OTHER_TEMPLATE must be registered after the other K8S_XXX_TEMPLATE. ...K8S_OTHER_TEMPLATE, ...OPENSTACK_IMAGE_TEMPLATE, ...OPENSTACK_KEY_PAIR_TEMPLATE, ...VMWARE_VM_TEMPLATE, ]; Loading modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/key_pair.ts 0 → 100644 +20 −0 Original line number Diff line number Diff line import EntityFormTemplate from 'model/EntityFormTemplate'; const OPENSTACK_KEY_PAIR_TEMPLATE: EntityFormTemplate[] = [ { cloudServiceProvider: 'openstack', entityName: 'key_pair', actionType: 'create', entityRecords: [ { type: 'panel', panelName: 'Key pair', keyValueRecords: [ { type: 'default', labelName: 'Key pair name', name: 'key_pair_name', defaultValue: '' } ] } ] } ] export default OPENSTACK_KEY_PAIR_TEMPLATE; modules/cloud_service_providers/openstack/openstack.routing.yml +15 −0 Original line number Diff line number Diff line Loading @@ -480,3 +480,18 @@ entity.openstack_image.create: _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access' options: perm: 'add openstack image' entity.openstack_key_pair.create: path: '/cloud_dashboard/openstack/{cloud_context}/openstack_key_pair/create' defaults: _controller: '\Drupal\openstack\Controller\ApiController::operateEntity' entity_type_id: openstack_key_pair 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 key pair' modules/cloud_service_providers/openstack/src/Controller/ApiController.php +8 −2 Original line number Diff line number Diff line Loading @@ -513,7 +513,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $original_entity = $entity; $form_state = new IntermediateFormState(); $method_name = ''; switch ($command . '.' . $entity_type_id) { switch ($command . '_' . $entity_type_id) { case 'create_openstack_image': $original_entity->setName($request->get('name', '')); $original_entity->setVisibility(!empty($request->get('visibility', '')) ? 'public' : 'private'); Loading @@ -531,14 +531,20 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $method_name = 'deleteOpenStackImage'; break; case 'create_openstack_key_pair': $original_entity->set('key_pair_name', $request->get('key_pair_name', '')); $method_name = 'createOpenStackKeyPair'; break; } // Execute the process. $result = NULL; if (method_exists($this->openStackOperationsService, $method_name)) { $form = []; $result = $this->openStackOperationsService->$method_name( $original_entity, [], $form, $form_state ); } Loading modules/cloud_service_providers/openstack/src/Form/OpenStackKeyPairCreateForm.php +16 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; /** Loading @@ -36,6 +37,13 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { */ protected $openStackServiceFactory; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackKeyPairCreateForm constructor. * Loading Loading @@ -71,6 +79,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { * The general renderer. * @param \Drupal\cloud\Service\CloudServiceInterface $cloud_service * The Cloud service. * @param \Drupal\openstack\Service\OpenStackOperationsServiceInterface $openstack_operations_service * The OpenStack Operations service. */ public function __construct(OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, Loading @@ -87,7 +97,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service) { CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, Loading @@ -108,6 +119,7 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; } /** Loading Loading @@ -136,7 +148,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud') $container->get('cloud'), $container->get('openstack.operations') ); } Loading Loading @@ -169,10 +182,7 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { * The current form state. */ public function save(array $form, FormStateInterface $form_state): void { $entity = $this->entity; // Switch OpenStack EC2 or REST service based on $entity->getCloudContext(). $this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext()); parent::save($form, $form_state); $this->openStackOperationsService->createOpenStackKeyPair($this->entity, $form, $form_state); } } Loading
modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/entity_form_template.ts +2 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import K8S_OTHER_TEMPLATE from 'constant/form_template/k8s/other'; import K8S_POD_TEMPLATE from 'constant/form_template/k8s/pod'; import K8S_SCHEDULE_TEMPLATE from 'constant/form_template/k8s/schedule'; import OPENSTACK_IMAGE_TEMPLATE from 'constant/form_template/openstack/image'; import OPENSTACK_KEY_PAIR_TEMPLATE from 'constant/form_template/openstack/key_pair'; import VMWARE_VM_TEMPLATE from 'constant/form_template/vmware/vm'; const ENTITY_FORM_LIST = [ Loading @@ -14,6 +15,7 @@ const ENTITY_FORM_LIST = [ // K8S_OTHER_TEMPLATE must be registered after the other K8S_XXX_TEMPLATE. ...K8S_OTHER_TEMPLATE, ...OPENSTACK_IMAGE_TEMPLATE, ...OPENSTACK_KEY_PAIR_TEMPLATE, ...VMWARE_VM_TEMPLATE, ]; Loading
modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/key_pair.ts 0 → 100644 +20 −0 Original line number Diff line number Diff line import EntityFormTemplate from 'model/EntityFormTemplate'; const OPENSTACK_KEY_PAIR_TEMPLATE: EntityFormTemplate[] = [ { cloudServiceProvider: 'openstack', entityName: 'key_pair', actionType: 'create', entityRecords: [ { type: 'panel', panelName: 'Key pair', keyValueRecords: [ { type: 'default', labelName: 'Key pair name', name: 'key_pair_name', defaultValue: '' } ] } ] } ] export default OPENSTACK_KEY_PAIR_TEMPLATE;
modules/cloud_service_providers/openstack/openstack.routing.yml +15 −0 Original line number Diff line number Diff line Loading @@ -480,3 +480,18 @@ entity.openstack_image.create: _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access' options: perm: 'add openstack image' entity.openstack_key_pair.create: path: '/cloud_dashboard/openstack/{cloud_context}/openstack_key_pair/create' defaults: _controller: '\Drupal\openstack\Controller\ApiController::operateEntity' entity_type_id: openstack_key_pair 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 key pair'
modules/cloud_service_providers/openstack/src/Controller/ApiController.php +8 −2 Original line number Diff line number Diff line Loading @@ -513,7 +513,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $original_entity = $entity; $form_state = new IntermediateFormState(); $method_name = ''; switch ($command . '.' . $entity_type_id) { switch ($command . '_' . $entity_type_id) { case 'create_openstack_image': $original_entity->setName($request->get('name', '')); $original_entity->setVisibility(!empty($request->get('visibility', '')) ? 'public' : 'private'); Loading @@ -531,14 +531,20 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $method_name = 'deleteOpenStackImage'; break; case 'create_openstack_key_pair': $original_entity->set('key_pair_name', $request->get('key_pair_name', '')); $method_name = 'createOpenStackKeyPair'; break; } // Execute the process. $result = NULL; if (method_exists($this->openStackOperationsService, $method_name)) { $form = []; $result = $this->openStackOperationsService->$method_name( $original_entity, [], $form, $form_state ); } Loading
modules/cloud_service_providers/openstack/src/Form/OpenStackKeyPairCreateForm.php +16 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; /** Loading @@ -36,6 +37,13 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { */ protected $openStackServiceFactory; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackKeyPairCreateForm constructor. * Loading Loading @@ -71,6 +79,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { * The general renderer. * @param \Drupal\cloud\Service\CloudServiceInterface $cloud_service * The Cloud service. * @param \Drupal\openstack\Service\OpenStackOperationsServiceInterface $openstack_operations_service * The OpenStack Operations service. */ public function __construct(OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, Loading @@ -87,7 +97,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service) { CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, Loading @@ -108,6 +119,7 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; } /** Loading Loading @@ -136,7 +148,8 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud') $container->get('cloud'), $container->get('openstack.operations') ); } Loading Loading @@ -169,10 +182,7 @@ class OpenStackKeyPairCreateForm extends KeyPairCreateForm { * The current form state. */ public function save(array $form, FormStateInterface $form_state): void { $entity = $this->entity; // Switch OpenStack EC2 or REST service based on $entity->getCloudContext(). $this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext()); parent::save($form, $form_state); $this->openStackOperationsService->createOpenStackKeyPair($this->entity, $form, $form_state); } }