Commit 015eb1a2 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3310642 by Xiaohua Guan, yas: Add the OpenStack Subnet list view

parent d0bf5749
Loading
Loading
Loading
Loading
+1444 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −0
Original line number Diff line number Diff line
@@ -1483,3 +1483,15 @@ function openstack_update_8262() {
function openstack_update_8263() {
  openstack_add_entity_type('openstack_subnet');
}

/**
 * Add openstack_subnet list view.
 */
function openstack_update_8264() {
  $files = [
    'views.view.openstack_subnet.yml',
  ];

  \Drupal::service('cloud')->updateYmlDefinitions($files, 'openstack');
  drupal_flush_all_caches();
}
+12 −0
Original line number Diff line number Diff line
@@ -114,6 +114,18 @@ openstack.local_tasks.network.all:
  base_route: 'openstack.local_tasks.all_resources'
  weight: 90

openstack.local_tasks.subnet:
  title: 'Subnets'
  route_name: 'view.openstack_subnet.list'
  base_route: 'openstack.local_tasks.cloud_context'
  weight: 90

openstack.local_tasks.subnet.all:
  title: 'Subnets'
  route_name: 'view.openstack_subnet.all'
  base_route: 'openstack.local_tasks.all_resources'
  weight: 90

# OpenStack Instance routing definition
openstack_instance.settings_tab:
  route_name: openstack_instance.settings
+11 −4
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\openstack\Entity;

use Drupal\cloud\Entity\CloudContentEntityBase;
use Drupal\cloud\Service\Util\EntityLinkWithNameHtmlGenerator;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@@ -295,11 +296,17 @@ class OpenStackSubnet extends CloudContentEntityBase implements OpenStackSubnetI
      ->setReadOnly(TRUE);

    $fields['network_id'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Network ID'))
      ->setDescription(t('The ID of the network.'))
      ->setLabel(t('Network'))
      ->setDescription(t('The network.'))
      ->setDisplayOptions('view', [
        'label' => 'inline',
        'type' => 'string',
        'type' => 'entity_link',
        'settings' => [
          'target_type' => 'openstack_network',
          'field_name' => 'network_id',
          'comma_separated' => TRUE,
          'html_generator_class' => EntityLinkWithNameHtmlGenerator::class,
        ],
        'weight' => -5,
      ])
      ->setReadOnly(TRUE);
@@ -356,7 +363,7 @@ class OpenStackSubnet extends CloudContentEntityBase implements OpenStackSubnetI
      ->setReadOnly(TRUE);

    $fields['enable_dhcp'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Admin State'))
      ->setLabel(t('Enable DHCP'))
      ->setDescription(t('Indicates whether dhcp is enabled or disabled for the subnet.'))
      ->setDisplayOptions('view', [
        'label' => 'inline',
+6 −2
Original line number Diff line number Diff line
@@ -3947,7 +3947,6 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter
    $response = $this->getClient($credentials);

    $subnets = $response['body']['subnets'] ?? [];

    $results['Subnets'] = [];
    foreach ($subnets ?: [] as $subnet) {
      $pools = [];
@@ -3955,6 +3954,11 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter
        $pools[] = $allocation_pool['start'] . ' - ' . $allocation_pool['end'];
      }

      $routes = [];
      foreach ($subnet['host_routes'] ?: [] as $host_route) {
        $routes[] = sprintf('nexthop: %s, destination: %s', $host_route['nexthop'], $host_route['destination']);
      }

      $results['Subnets'][] = [
        'SubnetId'           => $subnet['id'] ?? NULL,
        'Name'               => $subnet['name'] ?? NULL,
@@ -3967,7 +3971,7 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter
        'AllocationPools'    => $pools,
        'GatewayIp'          => $subnet['gateway_ip'],
        'EnableDhcp'         => $subnet['enable_dhcp'],
        'HostRoutes'         => $subnet['host_routes'],
        'HostRoutes'         => $routes,
        'DnsNameServers'     => $subnet['dns_nameservers'],
      ];
    }