Loading modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php +100 −20 Changes for modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php: 100 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -420,202 +420,282 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt $fields['instances'] = BaseFieldDefinition::create('integer') ->setLabel(t('Instances')) ->setDescription(t('The number of allowed servers for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['cores'] = BaseFieldDefinition::create('integer') ->setLabel(t('VCPUs')) ->setDescription(t('The number of allowed server cores for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['ram'] = BaseFieldDefinition::create('integer') ->setLabel(t('RAM(MiB)')) ->setDescription(t('The amount of allowed server RAM, in MiB, for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['metadata_items'] = BaseFieldDefinition::create('integer') ->setLabel(t('Metadata Items')) ->setDescription(t('The number of allowed metadata items for each server.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['key_pairs'] = BaseFieldDefinition::create('integer') ->setLabel(t('Key Pairs')) ->setDescription(t('The number of allowed key pairs for each user.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['server_groups'] = BaseFieldDefinition::create('integer') ->setLabel(t('Server Groups')) ->setDescription(t('The number of allowed server groups for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['server_group_members'] = BaseFieldDefinition::create('integer') ->setLabel(t('Server Group Members')) ->setDescription(t('The number of allowed members for each server group.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_files'] = BaseFieldDefinition::create('integer') ->setLabel(t('Injected Files')) ->setDescription(t('The number of allowed injected files for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_file_content_bytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Injected File Content(Bytes)')) ->setDescription(t('The number of allowed bytes for each injected file path.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_file_path_bytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Length of Injected File Path')) ->setDescription(t('The number of allowed bytes for each injected file path.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['volumes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Volumes')) ->setDescription(t('The number of volumes that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['snapshots'] = BaseFieldDefinition::create('integer') ->setLabel(t('Volume Snapshots')) ->setDescription(t('The number of snapshots that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['gigabytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Total Size of Volumes and Snapshots (GiB)')) ->setDescription(t('The size (GB) of volumes and snapshots that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['network'] = BaseFieldDefinition::create('integer') ->setLabel(t('Networks')) ->setDescription(t('The number of networks allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['subnet'] = BaseFieldDefinition::create('integer') ->setLabel(t('Subnets')) ->setDescription(t('The number of subnets allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['port'] = BaseFieldDefinition::create('integer') ->setLabel(t('Ports')) ->setDescription(t('The number of ports allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['router'] = BaseFieldDefinition::create('integer') ->setLabel(t('Routers')) ->setDescription(t('The number of routers allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['floatingip'] = BaseFieldDefinition::create('integer') ->setLabel(t('Floating IPs')) ->setDescription(t('The number of floating IP addresses allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['security_group'] = BaseFieldDefinition::create('integer') ->setLabel(t('Security Groups')) ->setDescription(t('The number of security groups allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['security_group_rule'] = BaseFieldDefinition::create('integer') ->setLabel(t('Security Group Rules')) ->setDescription(t('The number of security group rules allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) Loading modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php +270 Changes for modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php: 270 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\openstack\Form; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\aws_cloud\Traits\AwsCloudFormTrait; use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface; use Drupal\cloud\Service\EntityLinkRendererInterface; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Plugin\CachedDiscoveryClearerInterface; use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\openstack\Traits\OpenStackFormTrait; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Quota entity edit form. * * @ingroup openstack */ class OpenStackQuotaEditForm extends AwsCloudContentForm { use AwsCloudFormTrait; use CloudContentEntityTrait; use OpenStackFormTrait; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackQuotaEditForm constructor. * * @param \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface $aws_cloud_operations_service * The AWS Cloud Operations service. * @param \Drupal\openstack\Service\OpenStackServiceFactoryInterface $openstack_service_factory * Object for interfacing with OpenStack Service. * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service * The AWS Cloud or OpenStack EC2 Service. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository service. * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info * The entity type bundle service. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. * @param \Drupal\Core\Messenger\Messenger $messenger * The Messenger Service. * @param \Drupal\cloud\Service\EntityLinkRendererInterface $entity_link_renderer * The entity link render service. * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager * The Entity Type Manager. * @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender * A cache backend interface instance. * @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer * A plugin cache clear instance. * @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager * The cloud service provider plugin manager (CloudConfigPluginManager). * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter. * @param \Drupal\Core\Render\Renderer $renderer * 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( AwsCloudOperationsServiceInterface $aws_cloud_operations_service, OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, Messenger $messenger, EntityLinkRendererInterface $entity_link_renderer, EntityTypeManager $entity_type_manager, CacheBackendInterface $cacheRender, CachedDiscoveryClearerInterface $plugin_cache_clearer, CloudConfigPluginManagerInterface $cloud_config_plugin_manager, AccountInterface $current_user, RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, $entity_repository, $entity_type_bundle_info, $time, $messenger, $entity_link_renderer, $entity_type_manager, $cacheRender, $plugin_cache_clearer, $cloud_config_plugin_manager, $current_user, $route_match, $date_formatter, $renderer, $cloud_service ); $this->openStackOperationsService = $openstack_operations_service; } /** * Dependency Injection. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * Instance of ContainerInterface. * * @return \Drupal\openstack\Entity\OpenStackQuotaEditForm * return created object. */ public static function create(ContainerInterface $container) { return new static( $container->get('aws_cloud.operations'), $container->get('openstack.factory'), $container->get('openstack.ec2'), $container->get('entity.repository'), $container->get('entity_type.bundle.info'), $container->get('datetime.time'), $container->get('messenger'), $container->get('entity.link_renderer'), $container->get('entity_type.manager'), $container->get('cache.render'), $container->get('plugin.cache_clearer'), $container->get('plugin.manager.cloud_config_plugin'), $container->get('current_user'), $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud'), $container->get('openstack.operations') ); } /** * Overrides Drupal\Core\Entity\EntityFormController::buildForm(). * * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * @param string $cloud_context * A cloud_context string value from URL "path". * * @return array * Array of form object. */ public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = ''): array { $form = parent::buildForm($form, $form_state, $cloud_context); $entity = $this->entity; $entity = $this->entity; if (!$this->updateEntityBuildForm($entity)) { return $this->redirectUrl; } $weight = -50; $form['quota'] = [ '#type' => 'details', '#title' => $this->t('@title', ['@title' => $entity->getEntityType()->getSingularLabel()]), '#open' => TRUE, '#weight' => $weight++, ]; $form['quota']['name'] = [ '#type' => 'item', '#title' => $this->getItemTitle($this->t('Name')), '#markup' => $entity->getName(), ]; $field_sets = [ [ 'name' => 'quota_compute', 'title' => $this->t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => $this->t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => $this->t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; foreach ($field_sets as $field_set) { $form[$field_set['name']] = [ '#type' => 'details', '#title' => $field_set['title'], '#open' => TRUE, '#weight' => $weight++, ]; foreach ($field_set['fields'] as $field) { $form[$field_set['name']][$field] = $form[$field]; unset($form[$field]); } } $this->addOthersFieldset($form, $weight++, $cloud_context); return $form; } /** * Submit handler. * * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function save(array $form, FormStateInterface $form_state): void { $this->openStackOperationsService->editOpenStackQuota($this->entity, $form, $form_state); } } modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php +68 Changes for modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php: 68 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\openstack\Entity\OpenStackNetworkExInterface; use Drupal\openstack\Entity\OpenStackPortInterface; use Drupal\openstack\Entity\OpenStackQuotaInterface; use Drupal\openstack\Entity\OpenStackRouterInterface; use Drupal\openstack\Entity\OpenStackSubnetInterface; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; Loading Loading @@ -1584,6 +1585,73 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface return TRUE; } /** * {@inheritdoc} */ public function editOpenStackQuota(OpenStackQuotaInterface $entity, array &$form, FormStateInterface $form_state): bool { $this->entity = $entity; /** @var Drupal\openstack\Service\Rest\OpenStackService $ec2_service */ $ec2_service = $this->openStackServiceFactory->get($entity->getCloudContext()); $this->ec2Service = $ec2_service; $this->awsCloudOperationsService->setEc2Service($this->ec2Service); $this->awsCloudOperationsService->trimTextfields($entity, $form, $form_state); $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]); $this->ec2Service->setCloudContext($entity->getCloudContext()); $params = [ 'Name' => $entity->getName(), 'ProjectId' => $entity->getProjectId(), 'Instances' => $entity->getInstances(), 'Cores' => $entity->getCores(), 'Ram' => $entity->getRam(), 'MetadataItems' => $entity->getMetadataItems(), 'KeyPairs' => $entity->getKeyPairs(), 'ServerGroups' => $entity->getServerGroups(), 'ServerGroupMembers' => $entity->getServerGroupMembers(), 'InjectedFiles' => $entity->getInjectedFiles(), 'InjectedFileContentBytes' => $entity->getInjectedFileContentBytes(), 'InjectedFilePathBytes' => $entity->getInjectedFilePathBytes(), 'Volumes' => $entity->getVolumes(), 'Snapshots' => $entity->getSnapshots(), 'GigaBytes' => $entity->getGigaBytes(), 'Network' => $entity->getNetwork(), 'Subnet' => $entity->getSubnet(), 'Port' => $entity->getPort(), 'Router' => $entity->getRouter(), 'FloatingIp' => $entity->getFloatingIp(), 'SecurityGroup' => $entity->getSecurityGroup(), 'SecurityGroupRule' => $entity->getSecurityGroupRule(), ]; $result = $this->ec2Service->updateQuota($params); if ($result === NULL) { $this->processOperationErrorStatus($entity, 'updated'); return FALSE; } if (!empty($result['SendToWorker'])) { $this->processOperationStatus($entity, 'updated remotely'); return TRUE; } $entity->save(); // Update the Router entity. $this->ec2Service->updateQuotas(); $this->processOperationStatus($entity, 'updated'); $this->clearCacheValues($entity->getCacheTags()); $this->dispatchSaveEvent($entity); return TRUE; } /** * {@inheritdoc} */ Loading modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsServiceInterface.php +16 Changes for modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsServiceInterface.php: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use Drupal\cloud\Entity\CloudLaunchTemplateInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\openstack\Entity\OpenStackNetworkExInterface; use Drupal\openstack\Entity\OpenStackPortInterface; use Drupal\openstack\Entity\OpenStackQuotaInterface; use Drupal\openstack\Entity\OpenStackRouterInterface; use Drupal\openstack\Entity\OpenStackSubnetInterface; Loading Loading @@ -382,6 +383,21 @@ interface OpenStackOperationsServiceInterface { */ public function editOpenStackRouter(OpenStackRouterInterface $entity, array &$form, FormStateInterface $form_state): bool; /** * Edit an OpenStack Quota. * * @param \Drupal\openstack\Entity\OpenStackQuotaInterface $entity * The OpenStack quota entity. * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * * @return bool * TRUE when the process succeeds. */ public function editOpenStackQuota(OpenStackQuotaInterface $entity, array &$form, FormStateInterface $form_state): bool; /** * Delete an OpenStack Network. * Loading modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php +95 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php +100 −20 Changes for modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php: 100 added lines, 20 removed lines. Original line number Diff line number Diff line Loading @@ -420,202 +420,282 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt $fields['instances'] = BaseFieldDefinition::create('integer') ->setLabel(t('Instances')) ->setDescription(t('The number of allowed servers for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['cores'] = BaseFieldDefinition::create('integer') ->setLabel(t('VCPUs')) ->setDescription(t('The number of allowed server cores for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['ram'] = BaseFieldDefinition::create('integer') ->setLabel(t('RAM(MiB)')) ->setDescription(t('The amount of allowed server RAM, in MiB, for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['metadata_items'] = BaseFieldDefinition::create('integer') ->setLabel(t('Metadata Items')) ->setDescription(t('The number of allowed metadata items for each server.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['key_pairs'] = BaseFieldDefinition::create('integer') ->setLabel(t('Key Pairs')) ->setDescription(t('The number of allowed key pairs for each user.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['server_groups'] = BaseFieldDefinition::create('integer') ->setLabel(t('Server Groups')) ->setDescription(t('The number of allowed server groups for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['server_group_members'] = BaseFieldDefinition::create('integer') ->setLabel(t('Server Group Members')) ->setDescription(t('The number of allowed members for each server group.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_files'] = BaseFieldDefinition::create('integer') ->setLabel(t('Injected Files')) ->setDescription(t('The number of allowed injected files for each tenant.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_file_content_bytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Injected File Content(Bytes)')) ->setDescription(t('The number of allowed bytes for each injected file path.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['injected_file_path_bytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Length of Injected File Path')) ->setDescription(t('The number of allowed bytes for each injected file path.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['volumes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Volumes')) ->setDescription(t('The number of volumes that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['snapshots'] = BaseFieldDefinition::create('integer') ->setLabel(t('Volume Snapshots')) ->setDescription(t('The number of snapshots that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['gigabytes'] = BaseFieldDefinition::create('integer') ->setLabel(t('Total Size of Volumes and Snapshots (GiB)')) ->setDescription(t('The size (GB) of volumes and snapshots that are allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['network'] = BaseFieldDefinition::create('integer') ->setLabel(t('Networks')) ->setDescription(t('The number of networks allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['subnet'] = BaseFieldDefinition::create('integer') ->setLabel(t('Subnets')) ->setDescription(t('The number of subnets allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['port'] = BaseFieldDefinition::create('integer') ->setLabel(t('Ports')) ->setDescription(t('The number of ports allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['router'] = BaseFieldDefinition::create('integer') ->setLabel(t('Routers')) ->setDescription(t('The number of routers allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['floatingip'] = BaseFieldDefinition::create('integer') ->setLabel(t('Floating IPs')) ->setDescription(t('The number of floating IP addresses allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['security_group'] = BaseFieldDefinition::create('integer') ->setLabel(t('Security Groups')) ->setDescription(t('The number of security groups allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['security_group_rule'] = BaseFieldDefinition::create('integer') ->setLabel(t('Security Group Rules')) ->setDescription(t('The number of security group rules allowed for each project.')) ->setSetting('min', -1) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); ->setDisplayOptions('form', [ 'type' => 'number', 'weight' => -5, ]); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) Loading
modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php +270 Changes for modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php: 270 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\openstack\Form; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\aws_cloud\Traits\AwsCloudFormTrait; use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface; use Drupal\cloud\Service\EntityLinkRendererInterface; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Plugin\CachedDiscoveryClearerInterface; use Drupal\Core\Render\Renderer; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\openstack\Traits\OpenStackFormTrait; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the Quota entity edit form. * * @ingroup openstack */ class OpenStackQuotaEditForm extends AwsCloudContentForm { use AwsCloudFormTrait; use CloudContentEntityTrait; use OpenStackFormTrait; /** * The OpenStack operations Service. * * @var \Drupal\openstack\Service\OpenStackOperationsServiceInterface */ protected $openStackOperationsService; /** * OpenStackQuotaEditForm constructor. * * @param \Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface $aws_cloud_operations_service * The AWS Cloud Operations service. * @param \Drupal\openstack\Service\OpenStackServiceFactoryInterface $openstack_service_factory * Object for interfacing with OpenStack Service. * @param \Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface $ec2_service * The AWS Cloud or OpenStack EC2 Service. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository service. * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info * The entity type bundle service. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. * @param \Drupal\Core\Messenger\Messenger $messenger * The Messenger Service. * @param \Drupal\cloud\Service\EntityLinkRendererInterface $entity_link_renderer * The entity link render service. * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager * The Entity Type Manager. * @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender * A cache backend interface instance. * @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer * A plugin cache clear instance. * @param \Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface $cloud_config_plugin_manager * The cloud service provider plugin manager (CloudConfigPluginManager). * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter. * @param \Drupal\Core\Render\Renderer $renderer * 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( AwsCloudOperationsServiceInterface $aws_cloud_operations_service, OpenStackServiceFactoryInterface $openstack_service_factory, Ec2ServiceInterface $ec2_service, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, Messenger $messenger, EntityLinkRendererInterface $entity_link_renderer, EntityTypeManager $entity_type_manager, CacheBackendInterface $cacheRender, CachedDiscoveryClearerInterface $plugin_cache_clearer, CloudConfigPluginManagerInterface $cloud_config_plugin_manager, AccountInterface $current_user, RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, Renderer $renderer, CloudServiceInterface $cloud_service, OpenStackOperationsServiceInterface $openstack_operations_service) { parent::__construct( $ec2_service, $entity_repository, $entity_type_bundle_info, $time, $messenger, $entity_link_renderer, $entity_type_manager, $cacheRender, $plugin_cache_clearer, $cloud_config_plugin_manager, $current_user, $route_match, $date_formatter, $renderer, $cloud_service ); $this->openStackOperationsService = $openstack_operations_service; } /** * Dependency Injection. * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * Instance of ContainerInterface. * * @return \Drupal\openstack\Entity\OpenStackQuotaEditForm * return created object. */ public static function create(ContainerInterface $container) { return new static( $container->get('aws_cloud.operations'), $container->get('openstack.factory'), $container->get('openstack.ec2'), $container->get('entity.repository'), $container->get('entity_type.bundle.info'), $container->get('datetime.time'), $container->get('messenger'), $container->get('entity.link_renderer'), $container->get('entity_type.manager'), $container->get('cache.render'), $container->get('plugin.cache_clearer'), $container->get('plugin.manager.cloud_config_plugin'), $container->get('current_user'), $container->get('current_route_match'), $container->get('date.formatter'), $container->get('renderer'), $container->get('cloud'), $container->get('openstack.operations') ); } /** * Overrides Drupal\Core\Entity\EntityFormController::buildForm(). * * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * @param string $cloud_context * A cloud_context string value from URL "path". * * @return array * Array of form object. */ public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = ''): array { $form = parent::buildForm($form, $form_state, $cloud_context); $entity = $this->entity; $entity = $this->entity; if (!$this->updateEntityBuildForm($entity)) { return $this->redirectUrl; } $weight = -50; $form['quota'] = [ '#type' => 'details', '#title' => $this->t('@title', ['@title' => $entity->getEntityType()->getSingularLabel()]), '#open' => TRUE, '#weight' => $weight++, ]; $form['quota']['name'] = [ '#type' => 'item', '#title' => $this->getItemTitle($this->t('Name')), '#markup' => $entity->getName(), ]; $field_sets = [ [ 'name' => 'quota_compute', 'title' => $this->t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => $this->t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => $this->t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; foreach ($field_sets as $field_set) { $form[$field_set['name']] = [ '#type' => 'details', '#title' => $field_set['title'], '#open' => TRUE, '#weight' => $weight++, ]; foreach ($field_set['fields'] as $field) { $form[$field_set['name']][$field] = $form[$field]; unset($form[$field]); } } $this->addOthersFieldset($form, $weight++, $cloud_context); return $form; } /** * Submit handler. * * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function save(array $form, FormStateInterface $form_state): void { $this->openStackOperationsService->editOpenStackQuota($this->entity, $form, $form_state); } }
modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php +68 Changes for modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php: 68 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\openstack\Entity\OpenStackNetworkExInterface; use Drupal\openstack\Entity\OpenStackPortInterface; use Drupal\openstack\Entity\OpenStackQuotaInterface; use Drupal\openstack\Entity\OpenStackRouterInterface; use Drupal\openstack\Entity\OpenStackSubnetInterface; use Drupal\openstack\Service\Rest\OpenStackService as OpenStackRestService; Loading Loading @@ -1584,6 +1585,73 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface return TRUE; } /** * {@inheritdoc} */ public function editOpenStackQuota(OpenStackQuotaInterface $entity, array &$form, FormStateInterface $form_state): bool { $this->entity = $entity; /** @var Drupal\openstack\Service\Rest\OpenStackService $ec2_service */ $ec2_service = $this->openStackServiceFactory->get($entity->getCloudContext()); $this->ec2Service = $ec2_service; $this->awsCloudOperationsService->setEc2Service($this->ec2Service); $this->awsCloudOperationsService->trimTextfields($entity, $form, $form_state); $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]); $this->ec2Service->setCloudContext($entity->getCloudContext()); $params = [ 'Name' => $entity->getName(), 'ProjectId' => $entity->getProjectId(), 'Instances' => $entity->getInstances(), 'Cores' => $entity->getCores(), 'Ram' => $entity->getRam(), 'MetadataItems' => $entity->getMetadataItems(), 'KeyPairs' => $entity->getKeyPairs(), 'ServerGroups' => $entity->getServerGroups(), 'ServerGroupMembers' => $entity->getServerGroupMembers(), 'InjectedFiles' => $entity->getInjectedFiles(), 'InjectedFileContentBytes' => $entity->getInjectedFileContentBytes(), 'InjectedFilePathBytes' => $entity->getInjectedFilePathBytes(), 'Volumes' => $entity->getVolumes(), 'Snapshots' => $entity->getSnapshots(), 'GigaBytes' => $entity->getGigaBytes(), 'Network' => $entity->getNetwork(), 'Subnet' => $entity->getSubnet(), 'Port' => $entity->getPort(), 'Router' => $entity->getRouter(), 'FloatingIp' => $entity->getFloatingIp(), 'SecurityGroup' => $entity->getSecurityGroup(), 'SecurityGroupRule' => $entity->getSecurityGroupRule(), ]; $result = $this->ec2Service->updateQuota($params); if ($result === NULL) { $this->processOperationErrorStatus($entity, 'updated'); return FALSE; } if (!empty($result['SendToWorker'])) { $this->processOperationStatus($entity, 'updated remotely'); return TRUE; } $entity->save(); // Update the Router entity. $this->ec2Service->updateQuotas(); $this->processOperationStatus($entity, 'updated'); $this->clearCacheValues($entity->getCacheTags()); $this->dispatchSaveEvent($entity); return TRUE; } /** * {@inheritdoc} */ Loading
modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsServiceInterface.php +16 Changes for modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsServiceInterface.php: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use Drupal\cloud\Entity\CloudLaunchTemplateInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\openstack\Entity\OpenStackNetworkExInterface; use Drupal\openstack\Entity\OpenStackPortInterface; use Drupal\openstack\Entity\OpenStackQuotaInterface; use Drupal\openstack\Entity\OpenStackRouterInterface; use Drupal\openstack\Entity\OpenStackSubnetInterface; Loading Loading @@ -382,6 +383,21 @@ interface OpenStackOperationsServiceInterface { */ public function editOpenStackRouter(OpenStackRouterInterface $entity, array &$form, FormStateInterface $form_state): bool; /** * Edit an OpenStack Quota. * * @param \Drupal\openstack\Entity\OpenStackQuotaInterface $entity * The OpenStack quota entity. * @param array $form * Array of form object. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * * @return bool * TRUE when the process succeeds. */ public function editOpenStackQuota(OpenStackQuotaInterface $entity, array &$form, FormStateInterface $form_state): bool; /** * Delete an OpenStack Network. * Loading
modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php +95 File changed.Preview size limit exceeded, changes collapsed. Show changes