Loading modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/snapshot.ts +21 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,27 @@ const OPENSTACK_SNAPSHOT_TEMPLATE: EntityFormTemplate[] = [ ], submitButtonLabel: 'Delete' }, { cloudServiceProvider: 'openstack', entityName: 'snapshot', actionType: 'edit', entityRecords: [ { type: 'panel', panelName: 'Snapshot', keyValueRecords: [ { type: 'default', labelName: 'Name', name: 'name', defaultValue: '' }, { type: 'default', labelName: 'Description', name: 'description', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Snapshot ID', name: 'snapshot_id', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Volume ID', name: 'volume_id', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Size (GB)', name: 'size', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Status', name: 'status', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Progress', name: 'Progress', defaultValue: '', readOnly: true }, { type: 'datetime', labelName: 'Created', name: 'created', defaultValue: 0, readOnly: true }, ] } ] }, ] export default OPENSTACK_SNAPSHOT_TEMPLATE; modules/cloud_service_providers/openstack/openstack.routing.yml +14 −0 Original line number Diff line number Diff line Loading @@ -817,3 +817,17 @@ entity.openstack_snapshot.delete: _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access' options: perm: 'delete any openstack snapshot+delete own openstack snapshot' entity.openstack_snapshot.edit: path: '/cloud_dashboard/openstack/{cloud_context}/openstack_snapshot/{entity_id}/edit' defaults: _controller: '\Drupal\openstack\Controller\ApiController::operateEntity' entity_type_id: openstack_snapshot command: edit 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: 'edit any openstack snapshot+edit own openstack snapshot' modules/cloud_service_providers/openstack/src/Controller/ApiController.php +6 −0 Original line number Diff line number Diff line Loading @@ -677,6 +677,12 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $method_name = 'deleteOpenStackSnapshot'; break; case 'edit_openstack_snapshot': /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */ $entity->setName($request->get('name', '')); $method_name = 'editOpenStackSnapshot'; break; } // Execute the process. Loading modules/cloud_service_providers/openstack/src/Form/OpenStackSnapshotEditForm.php +16 −17 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\openstack\Form; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; use Drupal\aws_cloud\Form\Ec2\SnapshotEditForm; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface; Loading @@ -20,6 +19,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; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -37,6 +37,13 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { */ protected $openStackServiceFactory; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackSnapshotEditForm constructor. * Loading Loading @@ -72,6 +79,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { * 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 @@ -88,7 +97,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service) { CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, Loading @@ -109,6 +119,7 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; } /** Loading Loading @@ -137,7 +148,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud') $container->get('cloud'), $container->get('openstack.operations') ); } Loading Loading @@ -173,20 +185,7 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { * 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); // Update Snapshot of OpenStack REST API. if ($this->ec2Service instanceof OpenStackRestService) { $this->ec2Service->updateSnapshot([ 'SnapshotId' => $entity->getSnapshotId(), 'Name' => $entity->getName(), 'Description' => $entity->getDescription(), ]); } $this->openStackOperationsService->editOpenStackSnapshot($this->entity, $form, $form_state); } } modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php +47 −0 Original line number Diff line number Diff line Loading @@ -2218,6 +2218,53 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface return TRUE; } /** * {@inheritdoc} */ public function editOpenStackSnapshot(SnapshotInterface $entity, array &$form, FormStateInterface $form_state): bool { $this->entity = $entity; // Switch OpenStack EC2 or REST service based on $entity->getCloudContext(). $this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext()); $this->awsCloudOperationsService->setEc2Service($this->ec2Service); $this->saveSnapshot($form, $form_state); // Update Snapshot of OpenStack REST API. if ($this->ec2Service instanceof OpenStackRestService) { $this->ec2Service->updateSnapshot([ 'SnapshotId' => $entity->getSnapshotId(), 'Name' => $entity->getName(), 'Description' => $entity->getDescription(), ]); } return TRUE; } /** * Save an Snapshot. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @throws \Drupal\Core\Entity\EntityMalformedException * @throws \Drupal\Core\Entity\EntityStorageException */ private function saveSnapshot(array $form, FormStateInterface $form_state): void { /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */ $entity = $this->entity; $this->awsCloudOperationsService->copyFormItemValues($entity, $form, $form_state); $this->awsCloudOperationsService->trimTextfields($entity, $form, $form_state); $entity->save(); $this->processOperationStatus($entity, 'updated'); $this->awsCloudOperationsService->updateNameAndCreatedByTags($entity, $entity->getSnapshotId()); $this->clearCacheValues($entity->getCacheTags()); $this->dispatchSaveEvent($entity); } /** * Helper method to load instance by ID. * Loading Loading
modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/openstack/snapshot.ts +21 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,27 @@ const OPENSTACK_SNAPSHOT_TEMPLATE: EntityFormTemplate[] = [ ], submitButtonLabel: 'Delete' }, { cloudServiceProvider: 'openstack', entityName: 'snapshot', actionType: 'edit', entityRecords: [ { type: 'panel', panelName: 'Snapshot', keyValueRecords: [ { type: 'default', labelName: 'Name', name: 'name', defaultValue: '' }, { type: 'default', labelName: 'Description', name: 'description', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Snapshot ID', name: 'snapshot_id', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Volume ID', name: 'volume_id', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Size (GB)', name: 'size', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Status', name: 'status', defaultValue: '', readOnly: true }, { type: 'default', labelName: 'Progress', name: 'Progress', defaultValue: '', readOnly: true }, { type: 'datetime', labelName: 'Created', name: 'created', defaultValue: 0, readOnly: true }, ] } ] }, ] export default OPENSTACK_SNAPSHOT_TEMPLATE;
modules/cloud_service_providers/openstack/openstack.routing.yml +14 −0 Original line number Diff line number Diff line Loading @@ -817,3 +817,17 @@ entity.openstack_snapshot.delete: _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access' options: perm: 'delete any openstack snapshot+delete own openstack snapshot' entity.openstack_snapshot.edit: path: '/cloud_dashboard/openstack/{cloud_context}/openstack_snapshot/{entity_id}/edit' defaults: _controller: '\Drupal\openstack\Controller\ApiController::operateEntity' entity_type_id: openstack_snapshot command: edit 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: 'edit any openstack snapshot+edit own openstack snapshot'
modules/cloud_service_providers/openstack/src/Controller/ApiController.php +6 −0 Original line number Diff line number Diff line Loading @@ -677,6 +677,12 @@ class ApiController extends ControllerBase implements ApiControllerInterface { $method_name = 'deleteOpenStackSnapshot'; break; case 'edit_openstack_snapshot': /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */ $entity->setName($request->get('name', '')); $method_name = 'editOpenStackSnapshot'; break; } // Execute the process. Loading
modules/cloud_service_providers/openstack/src/Form/OpenStackSnapshotEditForm.php +16 −17 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\openstack\Form; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; use Drupal\aws_cloud\Form\Ec2\SnapshotEditForm; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface; Loading @@ -20,6 +19,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; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -37,6 +37,13 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { */ protected $openStackServiceFactory; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackSnapshotEditForm constructor. * Loading Loading @@ -72,6 +79,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { * 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 @@ -88,7 +97,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service) { CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, Loading @@ -109,6 +119,7 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { ); $this->openStackServiceFactory = $openstack_service_factory; $this->openStackOperationsService = $openstack_operations_service; } /** Loading Loading @@ -137,7 +148,8 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud') $container->get('cloud'), $container->get('openstack.operations') ); } Loading Loading @@ -173,20 +185,7 @@ class OpenStackSnapshotEditForm extends SnapshotEditForm { * 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); // Update Snapshot of OpenStack REST API. if ($this->ec2Service instanceof OpenStackRestService) { $this->ec2Service->updateSnapshot([ 'SnapshotId' => $entity->getSnapshotId(), 'Name' => $entity->getName(), 'Description' => $entity->getDescription(), ]); } $this->openStackOperationsService->editOpenStackSnapshot($this->entity, $form, $form_state); } }
modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php +47 −0 Original line number Diff line number Diff line Loading @@ -2218,6 +2218,53 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface return TRUE; } /** * {@inheritdoc} */ public function editOpenStackSnapshot(SnapshotInterface $entity, array &$form, FormStateInterface $form_state): bool { $this->entity = $entity; // Switch OpenStack EC2 or REST service based on $entity->getCloudContext(). $this->ec2Service = $this->openStackServiceFactory->get($entity->getCloudContext()); $this->awsCloudOperationsService->setEc2Service($this->ec2Service); $this->saveSnapshot($form, $form_state); // Update Snapshot of OpenStack REST API. if ($this->ec2Service instanceof OpenStackRestService) { $this->ec2Service->updateSnapshot([ 'SnapshotId' => $entity->getSnapshotId(), 'Name' => $entity->getName(), 'Description' => $entity->getDescription(), ]); } return TRUE; } /** * Save an Snapshot. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @throws \Drupal\Core\Entity\EntityMalformedException * @throws \Drupal\Core\Entity\EntityStorageException */ private function saveSnapshot(array $form, FormStateInterface $form_state): void { /** @var \Drupal\aws_cloud\Entity\Ec2\SnapshotInterface $entity */ $entity = $this->entity; $this->awsCloudOperationsService->copyFormItemValues($entity, $form, $form_state); $this->awsCloudOperationsService->trimTextfields($entity, $form, $form_state); $entity->save(); $this->processOperationStatus($entity, 'updated'); $this->awsCloudOperationsService->updateNameAndCreatedByTags($entity, $entity->getSnapshotId()); $this->clearCacheValues($entity->getCacheTags()); $this->dispatchSaveEvent($entity); } /** * Helper method to load instance by ID. * Loading