Loading modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/image.ts +11 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,17 @@ const OPENSTACK_IMAGE_TEMPLATE: EntityFormTemplate[] = [ ] } ] }, { cloudServiceProvider: 'openstack', entityName: 'image', actionType: 'delete', entityRecords: [ { type: 'label', text: 'Are you sure you want to delete the {{name}} {{entityName}}?' }, ] } ] Loading modules/cloud_service_providers/openstack/openstack.services.yml +5 −1 Original line number Diff line number Diff line Loading @@ -19,5 +19,9 @@ services: arguments: ['@entity_type.manager', '@plugin.manager.cloud_config_plugin', '@http_client_factory', '@lock', '@queue', '@entity_field.manager', '@plugin.manager.field.field_type', '@config.factory', '@cloud', '@twig'] openstack.ec2_operations: class: Drupal\openstack\Service\Ec2\OpenStackOperationsService class: Drupal\openstack\Service\Ec2\OpenStackEc2OperationsService arguments: ['@entity_type.manager', '@openstack.ec2', '@plugin.manager.cloud_config_plugin', '@cloud', '@openstack.factory'] openstack.operations: class: Drupal\openstack\Service\OpenStackOperationsService arguments: ['@plugin.manager.cloud_config_plugin', '@cloud', '@openstack.ec2', '@entity_type.manager', '@messenger', '@openstack.factory'] modules/cloud_service_providers/openstack/src/Controller/ApiController.php +44 −11 Original line number Diff line number Diff line Loading @@ -11,7 +11,9 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\openstack\Service\Ec2\OpenStackOperationsService; use Drupal\openstack\Entity\IntermediateFormState; use Drupal\openstack\Service\Ec2\OpenStackEc2OperationsService; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -85,6 +87,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface { */ protected $currentUser; /** * The OpenStack Operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * ApiController constructor. * Loading @@ -104,15 +113,20 @@ class ApiController extends ControllerBase implements ApiControllerInterface { * Cloud service. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\openstack\Service\OpenStackOperationsServiceInterface $openstack_operations_service * The OpenStack Operations service. */ public function __construct(OpenStackServiceFactoryInterface $openstack_service_factory, public function __construct( OpenStackServiceFactoryInterface $openstack_service_factory, EntityTypeManagerInterface $entityTypeManager, Messenger $messenger, RequestStack $request_stack, CloudConfigPluginManagerInterface $cloud_config_plugin_manager, RendererInterface $renderer, CloudServiceInterface $cloud_service, AccountInterface $current_user) { AccountInterface $current_user, OpenStackOperationsServiceInterface $openstack_operations_service ) { $this->openStackServiceFactory = $openstack_service_factory; $this->entityTypeManager = $entityTypeManager; $this->messenger = $messenger; Loading @@ -122,6 +136,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $this->cloudService = $cloud_service; $this->currentUser = $current_user; $this->configuration = ['cloud_context' => '']; $this->openStackOperationsService = $openstack_operations_service; } /** Loading @@ -142,7 +157,8 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $container->get('plugin.manager.cloud_config_plugin'), $container->get('renderer'), $container->get('cloud'), $container->get('current_user') $container->get('current_user'), $container->get('openstack.operations') ); } Loading Loading @@ -487,6 +503,23 @@ class ApiController extends ControllerBase implements ApiControllerInterface { ], 404); } if ($command === 'delete' && $entity_type_id === 'openstack_image') { $form_state = new IntermediateFormState(); $result = $this->openStackOperationsService->deleteOpenStackImage( $entity, [], $form_state ); return !empty($result) ? new JsonResponse([ 'result' => 'OK', ], 200) : new JsonResponse([ 'result' => 'NG', 'reason' => 'Internal Server Error', ], 500); } $method_name = ''; $parameter = []; switch ($command) { Loading Loading @@ -519,7 +552,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $result = FALSE; if (!empty($method_name)) { $service = new OpenStackOperationsService( $service = new OpenStackEc2OperationsService( $this->entityTypeManager, \Drupal::service('aws_cloud.ec2'), $this->cloudConfigPluginManager, Loading modules/cloud_service_providers/openstack/src/Entity/IntermediateFormState.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php namespace Drupal\openstack\Entity; use Drupal\Core\Form\FormState; /** * Stores information about the dummy state of a form. */ class IntermediateFormState extends FormState { /** * {@inheritdoc} */ public function setRedirect($route_name, array $route_parameters = [], array $options = []) { return $this; } } modules/cloud_service_providers/openstack/src/Form/OpenStackImageCreateForm.php +8 −8 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ use Drupal\Core\Plugin\CachedDiscoveryClearerInterface; use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -41,9 +41,9 @@ class OpenStackImageCreateForm extends ImageCreateForm { /** * The OpenStack operation service. * * @var \Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface * @var \Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface */ private $openStackOperationsService; private $openStackEc2OperationsService; /** * OpenStackImageCreateForm constructor. Loading @@ -52,7 +52,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { * Object for interfacing with OpenStack Service. * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service * The AWS Cloud or OpenStack EC2 Service. * @param \Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface $openstack_operations_service * @param \Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface $openstack_operations_service * The OpenStack operation service. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository service. Loading Loading @@ -86,7 +86,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { public function __construct( OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, OpenStackOperationsServiceInterface $openstack_operations_service, OpenStackEc2OperationsServiceInterface $openstack_operations_service, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, Loading Loading @@ -122,7 +122,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; $this->openStackEc2OperationsService = $openstack_operations_service; } /** Loading Loading @@ -216,8 +216,8 @@ class OpenStackImageCreateForm extends ImageCreateForm { $cloudContext = $entity->getCloudContext(); $ec2Service = $this->openStackServiceFactory->get($cloudContext); $this->openStackOperationsService->setEc2Service($ec2Service); if ($this->openStackOperationsService->createImage($this->entity, [ $this->openStackEc2OperationsService->setEc2Service($ec2Service); if ($this->openStackEc2OperationsService->createImage($this->entity, [ 'name' => $form_state->getValue('name'), ])) { $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]); Loading Loading
modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/image.ts +11 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,17 @@ const OPENSTACK_IMAGE_TEMPLATE: EntityFormTemplate[] = [ ] } ] }, { cloudServiceProvider: 'openstack', entityName: 'image', actionType: 'delete', entityRecords: [ { type: 'label', text: 'Are you sure you want to delete the {{name}} {{entityName}}?' }, ] } ] Loading
modules/cloud_service_providers/openstack/openstack.services.yml +5 −1 Original line number Diff line number Diff line Loading @@ -19,5 +19,9 @@ services: arguments: ['@entity_type.manager', '@plugin.manager.cloud_config_plugin', '@http_client_factory', '@lock', '@queue', '@entity_field.manager', '@plugin.manager.field.field_type', '@config.factory', '@cloud', '@twig'] openstack.ec2_operations: class: Drupal\openstack\Service\Ec2\OpenStackOperationsService class: Drupal\openstack\Service\Ec2\OpenStackEc2OperationsService arguments: ['@entity_type.manager', '@openstack.ec2', '@plugin.manager.cloud_config_plugin', '@cloud', '@openstack.factory'] openstack.operations: class: Drupal\openstack\Service\OpenStackOperationsService arguments: ['@plugin.manager.cloud_config_plugin', '@cloud', '@openstack.ec2', '@entity_type.manager', '@messenger', '@openstack.factory']
modules/cloud_service_providers/openstack/src/Controller/ApiController.php +44 −11 Original line number Diff line number Diff line Loading @@ -11,7 +11,9 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\openstack\Service\Ec2\OpenStackOperationsService; use Drupal\openstack\Entity\IntermediateFormState; use Drupal\openstack\Service\Ec2\OpenStackEc2OperationsService; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -85,6 +87,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface { */ protected $currentUser; /** * The OpenStack Operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * ApiController constructor. * Loading @@ -104,15 +113,20 @@ class ApiController extends ControllerBase implements ApiControllerInterface { * Cloud service. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\openstack\Service\OpenStackOperationsServiceInterface $openstack_operations_service * The OpenStack Operations service. */ public function __construct(OpenStackServiceFactoryInterface $openstack_service_factory, public function __construct( OpenStackServiceFactoryInterface $openstack_service_factory, EntityTypeManagerInterface $entityTypeManager, Messenger $messenger, RequestStack $request_stack, CloudConfigPluginManagerInterface $cloud_config_plugin_manager, RendererInterface $renderer, CloudServiceInterface $cloud_service, AccountInterface $current_user) { AccountInterface $current_user, OpenStackOperationsServiceInterface $openstack_operations_service ) { $this->openStackServiceFactory = $openstack_service_factory; $this->entityTypeManager = $entityTypeManager; $this->messenger = $messenger; Loading @@ -122,6 +136,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $this->cloudService = $cloud_service; $this->currentUser = $current_user; $this->configuration = ['cloud_context' => '']; $this->openStackOperationsService = $openstack_operations_service; } /** Loading @@ -142,7 +157,8 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $container->get('plugin.manager.cloud_config_plugin'), $container->get('renderer'), $container->get('cloud'), $container->get('current_user') $container->get('current_user'), $container->get('openstack.operations') ); } Loading Loading @@ -487,6 +503,23 @@ class ApiController extends ControllerBase implements ApiControllerInterface { ], 404); } if ($command === 'delete' && $entity_type_id === 'openstack_image') { $form_state = new IntermediateFormState(); $result = $this->openStackOperationsService->deleteOpenStackImage( $entity, [], $form_state ); return !empty($result) ? new JsonResponse([ 'result' => 'OK', ], 200) : new JsonResponse([ 'result' => 'NG', 'reason' => 'Internal Server Error', ], 500); } $method_name = ''; $parameter = []; switch ($command) { Loading Loading @@ -519,7 +552,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $result = FALSE; if (!empty($method_name)) { $service = new OpenStackOperationsService( $service = new OpenStackEc2OperationsService( $this->entityTypeManager, \Drupal::service('aws_cloud.ec2'), $this->cloudConfigPluginManager, Loading
modules/cloud_service_providers/openstack/src/Entity/IntermediateFormState.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php namespace Drupal\openstack\Entity; use Drupal\Core\Form\FormState; /** * Stores information about the dummy state of a form. */ class IntermediateFormState extends FormState { /** * {@inheritdoc} */ public function setRedirect($route_name, array $route_parameters = [], array $options = []) { return $this; } }
modules/cloud_service_providers/openstack/src/Form/OpenStackImageCreateForm.php +8 −8 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ use Drupal\Core\Plugin\CachedDiscoveryClearerInterface; use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -41,9 +41,9 @@ class OpenStackImageCreateForm extends ImageCreateForm { /** * The OpenStack operation service. * * @var \Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface * @var \Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface */ private $openStackOperationsService; private $openStackEc2OperationsService; /** * OpenStackImageCreateForm constructor. Loading @@ -52,7 +52,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { * Object for interfacing with OpenStack Service. * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service * The AWS Cloud or OpenStack EC2 Service. * @param \Drupal\openstack\Service\Ec2\OpenStackOperationsServiceInterface $openstack_operations_service * @param \Drupal\openstack\Service\Ec2\OpenStackEc2OperationsServiceInterface $openstack_operations_service * The OpenStack operation service. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository service. Loading Loading @@ -86,7 +86,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { public function __construct( OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, OpenStackOperationsServiceInterface $openstack_operations_service, OpenStackEc2OperationsServiceInterface $openstack_operations_service, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, Loading Loading @@ -122,7 +122,7 @@ class OpenStackImageCreateForm extends ImageCreateForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; $this->openStackEc2OperationsService = $openstack_operations_service; } /** Loading Loading @@ -216,8 +216,8 @@ class OpenStackImageCreateForm extends ImageCreateForm { $cloudContext = $entity->getCloudContext(); $ec2Service = $this->openStackServiceFactory->get($cloudContext); $this->openStackOperationsService->setEc2Service($ec2Service); if ($this->openStackOperationsService->createImage($this->entity, [ $this->openStackEc2OperationsService->setEc2Service($ec2Service); if ($this->openStackEc2OperationsService->createImage($this->entity, [ 'name' => $form_state->getValue('name'), ])) { $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]); Loading