Introduce subnet pool prefix operations extension

This introduces a new extension that provides API's that enable
operations against the prefix list of a subnet pool to be more
explicit. In its current form, the subnetpool extension does not
clearly define how operations on the prefix list of a subnet pool
are to be performed and leaves unnecessary ambiguity to be handled
by implementers of the extension. This extension makes prefix
management for subnet pools explicit operations, while making support
for this discoverable for clients.

Change-Id: Ia84d767f582f28a2fc77799a58f6729a7fd42f34
Related-Bug: #1792901
This commit is contained in:
Ryan Tidwell 2019-02-08 11:59:37 -06:00
parent b39260e7c9
commit a6438f4279
13 changed files with 195 additions and 3 deletions

View File

@ -31,6 +31,7 @@ Layer 3 Networking
.. include:: fip-port-forwarding.inc
.. include:: routers.inc
.. include:: subnetpools.inc
.. include:: subnetpool_prefix_ops.inc
.. include:: subnets.inc
########
Security

View File

@ -4673,6 +4673,22 @@ prefixes:
in: body
required: true
type: array
prefixes-response:
description: |
A list of the subnet prefixes currently assigned to the subnet
pool. Adjacent prefixes are merged and treated as a single prefix.
in: body
required: true
type: array
prefixes_remove:
description: |
A list of subnet prefixes to remove from the subnet pool.
The API splits larger prefixes when a subset prefix is removed,
and merges any resulting adjacent prefixes to treat them as a single
prefix.
in: body
required: true
type: array
project_id:
description: |
The ID of the project.

View File

@ -0,0 +1,3 @@
{
"prefixes": ["192.168.0.0/24", "192.168.1.0/24", "172.16.0.0/21"]
}

View File

@ -0,0 +1,3 @@
{
"prefixes": ["192.168.0.0/23", "172.16.0.0/21"]
}

View File

@ -0,0 +1,3 @@
{
"prefixes": ["192.168.0.0/24"]
}

View File

@ -0,0 +1,3 @@
{
"prefixes": ["192.168.1.0/24", "172.16.0.0/21"]
}

View File

@ -0,0 +1,83 @@
.. -*- rst -*-
=====================================================
Subnet pool prefix operations (subnetpool-prefix-ops)
=====================================================
Add and remove prefixes from a subnet pool prefix list.
Add prefixes
============
.. rest_method:: PUT /v2.0/subnetpools/{subnetpool_id}/add_prefixes
Adds prefixes to a subnet pool.
Normal response codes: 200
Error response codes: 400, 401, 403, 404, 409, 412
Request
-------
.. rest_parameters:: parameters.yaml
- subnetpool_id: subnetpool_id
- prefixes: prefixes
Request Example
---------------
.. literalinclude:: samples/subnets/subnetpool-add-prefixes-request.json
:language: javascript
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- prefixes: prefixes-response
Response Example
----------------
.. literalinclude:: samples/subnets/subnetpool-add-prefixes-response.json
:language: javascript
Remove prefixes
===============
.. rest_method:: PUT /v2.0/subnetpools/{subnetpool_id}/remove_prefixes
Remove prefixes from a subnet pool.
Normal response codes: 200
Error response codes: 400, 401, 403, 404, 409, 412
Request
-------
.. rest_parameters:: parameters.yaml
- subnetpool_id: subnetpool_id
- prefixes: prefixes_remove
Request Example
---------------
.. literalinclude:: samples/subnets/subnetpool-remove-prefixes-request.json
:language: javascript
Response Parameters
-------------------
.. rest_parameters:: parameters.yaml
- prefixes: prefixes-response
Response Example
----------------
.. literalinclude:: samples/subnets/subnetpool-remove-prefixes-response.json
:language: javascript

View File

@ -100,6 +100,7 @@ from neutron_lib.api.definitions import subnet_onboard
from neutron_lib.api.definitions import subnet_segmentid_enforce
from neutron_lib.api.definitions import subnet_segmentid_writable
from neutron_lib.api.definitions import subnetpool
from neutron_lib.api.definitions import subnetpool_prefix_ops
from neutron_lib.api.definitions import trunk
from neutron_lib.api.definitions import trunk_details
from neutron_lib.api.definitions import uplink_status_propagation
@ -200,6 +201,7 @@ _ALL_API_DEFINITIONS = {
subnet_segmentid_enforce,
subnet_segmentid_writable,
subnetpool,
subnetpool_prefix_ops,
trunk,
trunk_details,
uplink_status_propagation,

View File

@ -137,6 +137,7 @@ KNOWN_EXTENSIONS = (
'standard-attr-timestamp',
'subnet_allocation',
'subnet_onboard',
'subnetpool-prefix-ops',
'subnet-segmentid-enforce',
'subnet-segmentid-writable',
'tag',

View File

@ -0,0 +1,53 @@
# (c) Copyright 2019 SUSE LLC
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.api.definitions import subnetpool as subnetpool_def
from neutron_lib import constants
ALIAS = "subnetpool-prefix-ops"
IS_SHIM_EXTENSION = False
IS_STANDARD_ATTR_EXTENSION = False
NAME = "Subnet Pool Prefix Operations"
DESCRIPTION = "Provides support for adjusting the prefix list of subnet pools"
UPDATED_TIMESTAMP = "2019-02-08T10:00:00-00:00"
RESOURCE_ATTRIBUTE_MAP = {
}
# The subresource attribute map for the extension. This extension has only
# top level resources, not child resources, so this is set to an empty dict.
SUB_RESOURCE_ATTRIBUTE_MAP = {
}
# The action map.
ACTION_MAP = {
subnetpool_def.RESOURCE_NAME: {
'add_prefixes': 'PUT',
'remove_prefixes': 'PUT'
}
}
# The action status.
ACTION_STATUS = {
}
# The list of required extensions.
REQUIRED_EXTENSIONS = [constants.SUBNET_ALLOCATION_EXT_ALIAS]
# The list of optional extensions.
OPTIONAL_EXTENSIONS = [
]

View File

@ -110,9 +110,9 @@ class DefinitionBaseTestCase(test_base.BaseTestCase):
def test_resource_map(self):
if (not self.resource_map and not self.subresource_map and
not self.is_shim_extension):
self.fail('Missing resource and subresource map, '
'what is this extension doing?')
not self.is_shim_extension and not self.action_map):
self.fail('Missing resource map, subresource map, '
'and action map, what is this extension doing?')
elif self.is_shim_extension:
self.skipTest('Shim extension with no API changes.')

View File

@ -0,0 +1,19 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.api.definitions import subnetpool_prefix_ops
from neutron_lib.tests.unit.api.definitions import base
class SubnetPoolPrefixOpsDefinitionTestCase(base.DefinitionBaseTestCase):
extension_module = subnetpool_prefix_ops
extension_attributes = ()

View File

@ -0,0 +1,5 @@
---
features:
- Adds ``subnetpool-prefix-ops`` API definition to neutron-lib. This
extension introduces API's that provide explicit support for removing
prefixes from a subnet pool and adding subnets to a subnet pool.