Add Tap Services and Flows to SDK

Change-Id: I631379e4711148a5a470a91b069d8b58019c0eef
Related-Bug: #1999774
This commit is contained in:
elajkat 2023-01-20 15:52:28 +01:00 committed by Artem Goncharov
parent 395a1b6cc8
commit 71dcfba0ca
11 changed files with 431 additions and 0 deletions

View File

@ -305,3 +305,12 @@ BGP Operations
get_bgp_dragents_hosting_speaker, add_bgp_speaker_to_dragent,
get_bgp_speakers_hosted_by_dragent,
remove_bgp_speaker_from_dragent
Tap As A Service Operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: openstack.network.v2._proxy.Proxy
:noindex:
:members: create_tap_flow, delete_tap_flow, find_tap_flow, get_tap_flow,
update_tap_flow, tap_flows, create_tap_service, delete_tap_service,
find_tap_service, update_tap_service, tap_services

View File

@ -44,4 +44,6 @@ Network Resources
v2/service_provider
v2/subnet
v2/subnet_pool
v2/tap_flow
v2/tap_service
v2/vpn/index

View File

@ -0,0 +1,12 @@
openstack.network.v2.tap_flow
=============================
.. automodule:: openstack.network.v2.tap_flow
The TapFlow Class
-----------------
The ``TapFlow`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.network.v2.tap_flow.TapFlow
:members:

View File

@ -0,0 +1,12 @@
openstack.network.v2.tap_service
================================
.. automodule:: openstack.network.v2.tap_service
The TapService Class
--------------------
The ``TapService`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.network.v2.tap_service.TapService
:members:

View File

@ -66,6 +66,8 @@ from openstack.network.v2 import service_profile as _service_profile
from openstack.network.v2 import service_provider as _service_provider
from openstack.network.v2 import subnet as _subnet
from openstack.network.v2 import subnet_pool as _subnet_pool
from openstack.network.v2 import tap_flow as _tap_flow
from openstack.network.v2 import tap_service as _tap_service
from openstack.network.v2 import trunk as _trunk
from openstack.network.v2 import vpn_endpoint_group as _vpn_endpoint_group
from openstack.network.v2 import vpn_ike_policy as _ike_policy
@ -130,6 +132,8 @@ class Proxy(proxy.Proxy, Generic[T]):
"service_provider": _service_provider.ServiceProvider,
"subnet": _subnet.Subnet,
"subnet_pool": _subnet_pool.SubnetPool,
"tap_flow": _tap_flow.TapFlow,
"tap_service": _tap_service.TapService,
"trunk": _trunk.Trunk,
"vpn_endpoint_group": _vpn_endpoint_group.VpnEndpointGroup,
"vpn_ike_policy": _ike_policy.VpnIkePolicy,
@ -5242,6 +5246,58 @@ class Proxy(proxy.Proxy, Generic[T]):
conntrack_helper, router_id=router.id,
ignore_missing=ignore_missing)
def create_tap_flow(self, **attrs):
"""Create a new Tap Flow from attributes"""
return self._create(_tap_flow.TapFlow, **attrs)
def delete_tap_flow(self, tap_flow, ignore_missing=True):
"""Delete a Tap Flow"""
self._delete(_tap_flow.TapFlow, tap_flow,
ignore_missing=ignore_missing)
def find_tap_flow(self, name_or_id, ignore_missing=True, **query):
""""Find a single Tap Service"""
return self._find(_tap_flow.TapFlow, name_or_id,
ignore_missing=ignore_missing, **query)
def get_tap_flow(self, tap_flow):
"""Get a signle Tap Flow"""
return self._get(_tap_flow.TapFlow, tap_flow)
def update_tap_flow(self, tap_flow, **attrs):
"""Update a Tap Flow"""
return self._update(_tap_flow.TapFlow, tap_flow, **attrs)
def tap_flows(self, **query):
"""Return a generator of Tap Flows"""
return self._list(_tap_flow.TapFlow, **query)
def create_tap_service(self, **attrs):
"""Create a new Tap Service from attributes"""
return self._create(_tap_service.TapService, **attrs)
def delete_tap_service(self, tap_service, ignore_missing=True):
"""Delete a Tap Service"""
self._delete(_tap_service.TapService, tap_service,
ignore_missing=ignore_missing)
def find_tap_service(self, name_or_id, ignore_missing=True, **query):
""""Find a single Tap Service"""
return self._find(_tap_service.TapService, name_or_id,
ignore_missing=ignore_missing, **query)
def get_tap_service(self, tap_service):
"""Get a signle Tap Service"""
return self._get(_tap_service.TapService, tap_service)
def update_tap_service(self, tap_service, **attrs):
"""Update a Tap Service"""
return self._update(_tap_service.TapService, tap_service, **attrs)
def tap_services(self, **query):
"""Return a generator of Tap Services"""
return self._list(_tap_service.TapService, **query)
def _get_cleanup_dependencies(self):
return {
'network': {

View File

@ -0,0 +1,55 @@
# 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 openstack import resource
class TapFlow(resource.Resource):
"""Tap Flow"""
resource_key = 'tap_flow'
resources_key = 'tap_flows'
base_path = '/taas/tap_flows'
# capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
_allow_unknown_attrs_in_body = True
_query_mapping = resource.QueryParameters(
"sort_key", "sort_dir",
'name', 'project_id'
)
# Properties
#: The ID of the tap flow.
id = resource.Body('id')
#: The tap flow's name.
name = resource.Body('name')
#: The tap flow's description.
description = resource.Body('description')
#: The ID of the project that owns the tap flow.
project_id = resource.Body('project_id', alias='tenant_id')
#: Tenant_id (deprecated attribute).
tenant_id = resource.Body('tenant_id', deprecated=True)
#: The id of the tap_service with which the tap flow is associated
tap_service_id = resource.Body('tap_service_id')
#: The direction of the tap flow.
direction = resource.Body('direction')
#: The status for the tap flow.
status = resource.Body('status')
#: The id of the port the tap flow is associated with
source_port = resource.Body('source_port')

View File

@ -0,0 +1,51 @@
# 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 openstack import resource
class TapService(resource.Resource):
"""Tap Service"""
resource_key = 'tap_service'
resources_key = 'tap_services'
base_path = '/taas/tap_services'
# capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
_allow_unknown_attrs_in_body = True
_query_mapping = resource.QueryParameters(
"sort_key", "sort_dir",
'name', 'project_id'
)
# Properties
#: The ID of the tap service.
id = resource.Body('id')
#: The tap service name.
name = resource.Body('name')
#: The tap service description.
description = resource.Body('description')
#: The ID of the project that owns the tap service.
project_id = resource.Body('project_id', alias='tenant_id')
#: Tenant_id (deprecated attribute).
tenant_id = resource.Body('tenant_id', deprecated=True)
#: The id of the port the tap service is associated with
port_id = resource.Body('port_id')
#: The status for the tap service.
status = resource.Body('status')

View File

@ -0,0 +1,119 @@
# 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 openstack.network.v2 import network as _network
from openstack.network.v2 import port as _port
from openstack.network.v2 import tap_flow as _tap_flow
from openstack.network.v2 import tap_service as _tap_service
from openstack.tests.functional import base
class TestTapService(base.BaseFunctionalTest):
def setUp(self):
super().setUp()
if not self.user_cloud.network.find_extension("taas"):
self.skipTest("Neutron Tap-as-a-service Extension disabled")
self.TAP_S_NAME = 'my_service' + self.getUniqueString()
self.TAP_F_NAME = 'my_flow' + self.getUniqueString()
net = self.user_cloud.network.create_network()
assert isinstance(net, _network.Network)
self.SERVICE_NET_ID = net.id
net = self.user_cloud.network.create_network()
assert isinstance(net, _network.Network)
self.FLOW_NET_ID = net.id
port = self.user_cloud.network.create_port(
network_id=self.SERVICE_NET_ID)
assert isinstance(port, _port.Port)
self.SERVICE_PORT_ID = port.id
port = self.user_cloud.network.create_port(
network_id=self.FLOW_NET_ID)
assert isinstance(port, _port.Port)
self.FLOW_PORT_ID = port.id
tap_service = self.user_cloud.network.create_tap_service(
name=self.TAP_S_NAME, port_id=self.SERVICE_PORT_ID)
assert isinstance(tap_service, _tap_service.TapService)
self.TAP_SERVICE = tap_service
tap_flow = self.user_cloud.network.create_tap_flow(
name=self.TAP_F_NAME, tap_service_id=self.TAP_SERVICE.id,
source_port=self.FLOW_PORT_ID, direction='BOTH')
assert isinstance(tap_flow, _tap_flow.TapFlow)
self.TAP_FLOW = tap_flow
def tearDown(self):
sot = self.user_cloud.network.delete_tap_flow(self.TAP_FLOW.id,
ignore_missing=False)
self.assertIsNone(sot)
sot = self.user_cloud.network.delete_tap_service(self.TAP_SERVICE.id,
ignore_missing=False)
self.assertIsNone(sot)
sot = self.user_cloud.network.delete_port(self.SERVICE_PORT_ID)
self.assertIsNone(sot)
sot = self.user_cloud.network.delete_port(self.FLOW_PORT_ID)
self.assertIsNone(sot)
sot = self.user_cloud.network.delete_network(self.SERVICE_NET_ID)
self.assertIsNone(sot)
sot = self.user_cloud.network.delete_network(self.FLOW_NET_ID)
self.assertIsNone(sot)
super().tearDown()
def test_find_tap_service(self):
sot = self.user_cloud.network.find_tap_service(self.TAP_SERVICE.name)
self.assertEqual(self.SERVICE_PORT_ID, sot.port_id)
self.assertEqual(self.TAP_S_NAME, sot.name)
def test_get_tap_service(self):
sot = self.user_cloud.network.get_tap_service(self.TAP_SERVICE.id)
self.assertEqual(self.SERVICE_PORT_ID, sot.port_id)
self.assertEqual(self.TAP_S_NAME, sot.name)
def test_list_tap_services(self):
tap_service_ids = [ts.id for ts in
self.user_cloud.network.tap_services()]
self.assertIn(self.TAP_SERVICE.id, tap_service_ids)
def test_update_tap_service(self):
description = 'My tap service'
sot = self.user_cloud.network.update_tap_service(
self.TAP_SERVICE.id, description=description)
self.assertEqual(description, sot.description)
def test_find_tap_flow(self):
sot = self.user_cloud.network.find_tap_flow(self.TAP_FLOW.name)
self.assertEqual(self.FLOW_PORT_ID, sot.source_port)
self.assertEqual(self.TAP_SERVICE.id, sot.tap_service_id)
self.assertEqual('BOTH', sot.direction)
self.assertEqual(self.TAP_F_NAME, sot.name)
def test_get_tap_flow(self):
sot = self.user_cloud.network.get_tap_flow(self.TAP_FLOW.id)
self.assertEqual(self.FLOW_PORT_ID, sot.source_port)
self.assertEqual(self.TAP_F_NAME, sot.name)
self.assertEqual(self.TAP_SERVICE.id, sot.tap_service_id)
self.assertEqual('BOTH', sot.direction)
def test_list_tap_flows(self):
tap_flow_ids = [tf.id for tf in
self.user_cloud.network.tap_flows()]
self.assertIn(self.TAP_FLOW.id, tap_flow_ids)
def test_update_tap_flow(self):
description = 'My tap flow'
sot = self.user_cloud.network.update_tap_flow(
self.TAP_FLOW.id, description=description)
self.assertEqual(description, sot.description)

View File

@ -0,0 +1,56 @@
# 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 openstack.network.v2 import tap_flow
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
'name': 'my_tap_flow',
'source_port': '1234',
'tap_service_id': '4321',
'id': IDENTIFIER,
'project_id': '42'
}
class TestTapFlow(base.TestCase):
def test_basic(self):
sot = tap_flow.TapFlow()
self.assertEqual('tap_flow', sot.resource_key)
self.assertEqual('tap_flows', sot.resources_key)
self.assertEqual('/taas/tap_flows', sot.base_path)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_commit)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = tap_flow.TapFlow(**EXAMPLE)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['source_port'], sot.source_port)
self.assertEqual(EXAMPLE['tap_service_id'], sot.tap_service_id)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
self.assertDictEqual(
{'limit': 'limit',
'marker': 'marker',
'name': 'name',
'project_id': 'project_id',
'sort_key': 'sort_key',
'sort_dir': 'sort_dir',
},
sot._query_mapping._mapping)

View File

@ -0,0 +1,54 @@
# 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 openstack.network.v2 import tap_service
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
'name': 'my_tap_service',
'port_id': '1234',
'id': IDENTIFIER,
'project_id': '42'
}
class TestTapService(base.TestCase):
def test_basic(self):
sot = tap_service.TapService()
self.assertEqual('tap_service', sot.resource_key)
self.assertEqual('tap_services', sot.resources_key)
self.assertEqual('/taas/tap_services', sot.base_path)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_commit)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = tap_service.TapService(**EXAMPLE)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['port_id'], sot.port_id)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['project_id'], sot.project_id)
self.assertDictEqual(
{'limit': 'limit',
'marker': 'marker',
'name': 'name',
'project_id': 'project_id',
'sort_key': 'sort_key',
'sort_dir': 'sort_dir',
},
sot._query_mapping._mapping)

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``Tap Service`` and ``Tap Flow`` resources, and introduce support for
CRUD operations for these.