Skip to content
Snippets Groups Projects
Commit 02c93719 authored by LinDu's avatar LinDu Committed by Yas Naoi
Browse files

Issue #3064684 by yas, LinDu, Xiaohua Guan: Delete multiple Network Interfaces at once

parent ea4b27c7
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 14 deletions
...@@ -1026,6 +1026,20 @@ function aws_cloud_update_8159() { ...@@ -1026,6 +1026,20 @@ function aws_cloud_update_8159() {
cloud_update_yml_definitions($files, 'aws_cloud'); cloud_update_yml_definitions($files, 'aws_cloud');
} }
/**
* Add multiple Network Interface delete action.
*
* Update view aws_cloud_network_interface,
* aws_cloud_network_interface_delete_action.
*/
function aws_cloud_update_8160() {
$files = [
'views.view.aws_cloud_network_interface.yml',
'system.action.aws_cloud_network_interface_delete_action.yml',
];
cloud_update_yml_definitions($files, 'aws_cloud');
}
/** /**
* Helper function to add fields to the entity type. * Helper function to add fields to the entity type.
* *
......
langcode: en
status: true
dependencies:
module:
- aws_cloud
id: aws_cloud_network_interface_delete_action
label: 'Delete network_interface(s)'
type: aws_cloud_network_interface
plugin: entity:delete_action:aws_cloud_network_interface
configuration: { }
...@@ -319,6 +319,7 @@ display: ...@@ -319,6 +319,7 @@ display:
summary: '' summary: ''
description: '' description: ''
columns: columns:
network_interface_bulk_form: network_interface_bulk_form
name: name name: name
subnet_id: subnet_id subnet_id: subnet_id
vpc_id: vpc_id vpc_id: vpc_id
...@@ -328,6 +329,11 @@ display: ...@@ -328,6 +329,11 @@ display:
secondary_private_ips: secondary_private_ips secondary_private_ips: secondary_private_ips
operations: operations operations: operations
info: info:
network_interface_bulk_form:
align: ''
separator: ''
empty_column: false
responsive: ''
name: name:
sortable: true sortable: true
default_sort_order: asc default_sort_order: asc
...@@ -440,6 +446,59 @@ display: ...@@ -440,6 +446,59 @@ display:
plugin_id: string plugin_id: string
path: clouds/aws_cloud/%cloud_context/network_interface path: clouds/aws_cloud/%cloud_context/network_interface
fields: fields:
network_interface_bulk_form:
id: network_interface_bulk_form
table: aws_cloud_network_interface
field: network_interface_bulk_form
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
action_title: Action
include_exclude: exclude
selected_actions: { }
entity_type: aws_cloud_network_interface
plugin_id: network_interface_bulk_form
name: name:
id: name id: name
table: aws_cloud_network_interface table: aws_cloud_network_interface
......
...@@ -25,3 +25,7 @@ views.field.key_pair_bulk_form: ...@@ -25,3 +25,7 @@ views.field.key_pair_bulk_form:
views.field.vpc_bulk_form: views.field.vpc_bulk_form:
type: views_field_bulk_form type: views_field_bulk_form
label: 'vpc bulk form' label: 'vpc bulk form'
views.field.network_interface_bulk_form:
type: views_field_bulk_form
label: 'network interface bulk form'
...@@ -23,8 +23,12 @@ use Drupal\Core\Field\BaseFieldDefinition; ...@@ -23,8 +23,12 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "add" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceCreateForm", * "add" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceCreateForm",
* "edit" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceEditForm", * "edit" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceEditForm",
* "delete" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceDeleteForm", * "delete" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceDeleteForm",
* "delete-multiple-confirm" = "Drupal\aws_cloud\Form\Ec2\NetworkInterfaceDeleteMultipleForm",
* }, * },
* "access" = "Drupal\aws_cloud\Controller\Ec2\NetworkInterfaceAccessControlHandler", * "access" = "Drupal\aws_cloud\Controller\Ec2\NetworkInterfaceAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* }, * },
* base_table = "aws_cloud_network_interface", * base_table = "aws_cloud_network_interface",
* admin_permission = "administer aws cloud network interface", * admin_permission = "administer aws cloud network interface",
...@@ -39,6 +43,7 @@ use Drupal\Core\Field\BaseFieldDefinition; ...@@ -39,6 +43,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "edit-form" = "/clouds/aws_cloud/{cloud_context}/network_interface/{aws_cloud_network_interface}/edit", * "edit-form" = "/clouds/aws_cloud/{cloud_context}/network_interface/{aws_cloud_network_interface}/edit",
* "delete-form" = "/clouds/aws_cloud/{cloud_context}/network_interface/{aws_cloud_network_interface}/delete", * "delete-form" = "/clouds/aws_cloud/{cloud_context}/network_interface/{aws_cloud_network_interface}/delete",
* "collection" = "/clouds/aws_cloud/{cloud_context}/network_interface", * "collection" = "/clouds/aws_cloud/{cloud_context}/network_interface",
* "delete-multiple-form" = "/clouds/aws_cloud/{cloud_context}/network_interface/delete_multiple",
* }, * },
* field_ui_base_route = "aws_cloud_network_interface.settings" * field_ui_base_route = "aws_cloud_network_interface.settings"
* ) * )
......
...@@ -12,6 +12,15 @@ class NetworkInterfaceViewsData extends Ec2BaseViewsData { ...@@ -12,6 +12,15 @@ class NetworkInterfaceViewsData extends Ec2BaseViewsData {
*/ */
public function getViewsData() { public function getViewsData() {
$data = parent::getViewsData(); $data = parent::getViewsData();
$data['aws_cloud_network_interface']['network_interface_bulk_form'] = [
'title' => $this->t('Network Interface operations bulk form'),
'help' => $this->t('Add a form element that lets you run operations on multiple Network Interfaces.'),
'field' => [
'id' => 'network_interface_bulk_form',
],
];
$table_name = $this->storage->getEntityTypeId(); $table_name = $this->storage->getEntityTypeId();
$fields = $this->entityManager->getFieldStorageDefinitions($table_name); $fields = $this->entityManager->getFieldStorageDefinitions($table_name);
......
<?php
namespace Drupal\aws_cloud\Form\Ec2;
use Drupal\cloud\Entity\CloudContentEntityBase;
/**
* Provides an entities deletion confirmation form.
*/
class NetworkInterfaceDeleteMultipleForm extends AwsCloudDeleteMultipleForm {
/**
* {@inheritdoc}
*/
protected function processAwsResource(CloudContentEntityBase $entity) {
$this->awsEc2Service->setCloudContext($entity->getCloudContext());
return $this->awsEc2Service->deleteNetworkInterface(
['NetworkInterfaceId' => $entity->getNetworkInterfaceId()]
) != NULL;
}
}
<?php
namespace Drupal\aws_cloud\Plugin\Action;
use Drupal\Core\Action\Plugin\Action\DeleteAction;
/**
* Redirects to a Network Interface form.
*
* @Action(
* id = "entity:delete_action:aws_cloud_network_interface",
* label = @Translation("Delete Network Interface"),
* type = "aws_cloud_network_interface"
* )
*/
class DeleteNetworkInterface extends DeleteAction {
}
<?php
namespace Drupal\aws_cloud\Plugin\views\field;
use Drupal\views\Plugin\views\field\BulkForm;
/**
* Defines a network interface operations bulk form element.
*
* @ViewsField("network_interface_bulk_form")
*/
class NetworkInterfaceBulkForm extends BulkForm {
/**
* {@inheritdoc}
*/
protected function emptySelectedMessage() {
return $this->t('No network interface selected.');
}
}
...@@ -390,7 +390,7 @@ class ElasticIpTest extends AwsCloudTestCase { ...@@ -390,7 +390,7 @@ class ElasticIpTest extends AwsCloudTestCase {
$instance_id = $this->addInstanceMockData($instance->getName(), $instance->getKeyPairName(), $instance_id); $instance_id = $this->addInstanceMockData($instance->getName(), $instance->getKeyPairName(), $instance_id);
// Setup a test network interface. // Setup a test network interface.
$this->createTestNetworkInterface($i, $instance_id); $this->createTestNetworkInterface($i, $network_interface_id = '', $name = '', $instance_id);
$this->addNetworkInterfaceMockData($network_interface_data[$i]); $this->addNetworkInterfaceMockData($network_interface_data[$i]);
// Setup a test Elastic IP. // Setup a test Elastic IP.
...@@ -487,7 +487,7 @@ class ElasticIpTest extends AwsCloudTestCase { ...@@ -487,7 +487,7 @@ class ElasticIpTest extends AwsCloudTestCase {
$this->addInstanceMockData($instance->getName(), $instance->getKeyPairName(), $instance_id); $this->addInstanceMockData($instance->getName(), $instance->getKeyPairName(), $instance_id);
// Setup a test network interface. // Setup a test network interface.
$this->createTestNetworkInterface($i, $instance_id); $this->createTestNetworkInterface($i, $network_interface_id = '', $name = '', $instance_id);
$this->addNetworkInterfaceMockData($network_interface_data[$i]); $this->addNetworkInterfaceMockData($network_interface_data[$i]);
// Setup a test Elastic IP. // Setup a test Elastic IP.
......
...@@ -809,7 +809,7 @@ class InstanceTest extends AwsCloudTestCase { ...@@ -809,7 +809,7 @@ class InstanceTest extends AwsCloudTestCase {
$num = $i + 1; $num = $i + 1;
$this->createTestNetworkInterface($i, $add[$i]['instance_id']); $this->createTestNetworkInterface($i, $network_interface_id = '', $name = '', $add[$i]['instance_id']);
$this->createTestElasticIp($i); $this->createTestElasticIp($i);
// Change Instance Name in mock data. // Change Instance Name in mock data.
......
...@@ -167,6 +167,25 @@ class NetworkInterfaceTest extends AwsCloudTestCase { ...@@ -167,6 +167,25 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
} }
} }
/**
* Tests deleting network interfaces with bulk operation.
*/
public function testNetworkInterfaceBulk() {
$cloud_context = $this->cloudContext;
for ($i = 0; $i < self::AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT; $i++) {
// Create network interface.
$network_interfaces = $this->createRandomNetworkInterfacesData();
$index = 0;
foreach ($network_interfaces as $network_interface) {
$this->createTestNetworkInterface($index++, $network_interface['NetworkInterfaceId'], $network_interface['Name']);
}
$this->doTestEntityBulk('network_interface', $network_interfaces);
}
}
/** /**
* Create network interface test data. * Create network interface test data.
*/ */
......
...@@ -133,23 +133,27 @@ trait AwsCloudTestTrait { ...@@ -133,23 +133,27 @@ trait AwsCloudTestTrait {
/** /**
* Create network interface test entity. * Create network interface test entity.
* *
* @param int $num * @param int $index
* The index. * The Network Interface index.
* @param string $network_interface_id
* The Network Interface ID.
* @param string $name
* The Network Interface Name.
* @param string $instance_id * @param string $instance_id
* The instance id. * The Instance ID.
* *
* @return \Drupal\aws_cloud\Entity\Ec2\NetworkInterface * @return \Drupal\aws_cloud\Entity\Ec2\NetworkInterface
* The network interface entity. * The network interface entity.
*/ */
protected function createTestNetworkInterface($num = 0, $instance_id = '') { protected function createTestNetworkInterface($index = 0, $network_interface_id = '', $name = '', $instance_id = '') {
$timestamp = time(); $timestamp = time();
$private_ip = Utils::getRandomPrivateIp(); $private_ip = Utils::getRandomPrivateIp();
$secondary_private_ip = Utils::getRandomPrivateIp(); $secondary_private_ip = Utils::getRandomPrivateIp();
$network_interface = NetworkInterface::create([ $network_interface = NetworkInterface::create([
'cloud_context' => $this->cloudContext, 'cloud_context' => $this->cloudContext,
'name' => sprintf('NetworkInterface #%d - %s - %s', $num, date('Y/m/d H:i:s'), $this->random->name(8, TRUE)), 'name' => $name ?: sprintf('eni-entity #%d - %s - %s', $index + 1, date('Y/m/d H:i:s'), $this->random->name(8, TRUE)),
'network_interface_id' => 'eni-' . $this->getRandomAwsId(), 'network_interface_id' => $network_interface_id ?: 'eni-' . $this->getRandomAwsId(),
'vpc_id' => "vpc-" . $this->random->name(8, TRUE), 'vpc_id' => "vpc-" . $this->random->name(8, TRUE),
'mac_address' => NULL, 'mac_address' => NULL,
'security_groups' => "security_group-" . $this->random->name(8, TRUE), 'security_groups' => "security_group-" . $this->random->name(8, TRUE),
...@@ -167,7 +171,7 @@ trait AwsCloudTestTrait { ...@@ -167,7 +171,7 @@ trait AwsCloudTestTrait {
'description' => NULL, 'description' => NULL,
'public_ips' => NULL, 'public_ips' => NULL,
'source_dest_check' => NULL, 'source_dest_check' => NULL,
'instance_id' => $instance_id, 'instance_id' => $instance_id ?: 'i-' . $this->getRandomAwsId(),
'device_index' => NULL, 'device_index' => NULL,
'delete_on_termination' => NULL, 'delete_on_termination' => NULL,
'allocation_id' => NULL, 'allocation_id' => NULL,
...@@ -391,18 +395,18 @@ trait AwsCloudTestTrait { ...@@ -391,18 +395,18 @@ trait AwsCloudTestTrait {
} }
/** /**
* Create random network interfaces data. * Create random Network Interfaces data.
* *
* @return array * @return array
* Random network interfaces data. * Random network interfaces data.
*/ */
protected function createRandomNetworkInterfaceData() { protected function createRandomNetworkInterfacesData() {
$network_interfaces = []; $network_interfaces = [];
$count = rand(1, 10); $count = rand(1, 10);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$network_interfaces[] = [ $network_interfaces[] = [
'NetworkInterfaceId' => 'network_interface-' . $this->getRandomAwsId(), 'NetworkInterfaceId' => 'eni-' . $this->getRandomAwsId(),
'Name' => "network_interface-name #$i - " . $this->random->name(32, TRUE), 'Name' => sprintf('eni-random-data #%d - %s - %s', $i + 1, date('Y/m/d H:i:s'), $this->random->name(8, TRUE)),
]; ];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment