Skip to content

Commit

Permalink
Add query operations for public/target VPC endpoint services (#492)
Browse files Browse the repository at this point in the history
Add query operations for public/target VPC endpoint services

Add query operations for public VPC endpoint services and target VPC endpoint service

Reviewed-by: Vineet Pruthi
Reviewed-by: Anton Sidelnikov
  • Loading branch information
wuebbels authored Nov 19, 2024
1 parent 224e82e commit 5cb6910
Showing 10 changed files with 349 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/source/sdk/proxies/vpcep.rst
Original file line number Diff line number Diff line change
@@ -39,6 +39,20 @@ Service WhiteList Operations
:noindex:
:members: service_whitelist, manage_service_whitelist

Public Service Operations
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.vpcep.v1._proxy.Proxy
:noindex:
:members: public_services

Target Service Operations
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.vpcep.v1._proxy.Proxy
:noindex:
:members: get_target_service

Quota Operations
^^^^^^^^^^^^^^^^

20 changes: 20 additions & 0 deletions examples/vpcep/get_public_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.
#
"""Get Public VPC Endpoint Services."""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

public_services = list(conn.vpcep.public_services())
print(public_services)
21 changes: 21 additions & 0 deletions examples/vpcep/get_target_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.
#
"""Get Target VPC Endpoint Service."""
import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')

endpoint_service = 'endpoint-service'
endpoint_service = conn.vpcep.get_target_service(endpoint_service)
print(endpoint_service)
63 changes: 63 additions & 0 deletions otcextensions/sdk/vpcep/v1/_proxy.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
from otcextensions.sdk.vpcep.v1 import endpoint as _endpoint
from otcextensions.sdk.vpcep.v1 import quota as _quota
from otcextensions.sdk.vpcep.v1 import service as _service
from otcextensions.sdk.vpcep.v1 import public_service as _public_service
from otcextensions.sdk.vpcep.v1 import target_service as _target_service
from otcextensions.sdk.vpcep.v1 import whitelist as _whitelist


@@ -266,6 +268,67 @@ def manage_service_whitelist(self, service, action, domains=[]):
"Value of action can be 'add' or 'remove'."
)

# ======== VPCEP Public Service ========

def public_services(self, **query):
"""Return a generator of public endpoint services
:param dict query: Optional query parameters to be sent to limit
the resources being returned. Valid parameters are:
:returns: A generator of public endpoint service objects
:rtype: :class:`~otcextensions.sdk.vpcep.public_service.PublicService`
"""
if query.get('limit'):
query.update(paginated=False)
return self._list(_public_service.PublicService, **query)

# ======== VPCEP Target Service ========

def get_target_service(self, name_or_id, ignore_missing=False):
"""Get a single target endpoint service
:param name_or_id: The value can be the ID of a endpoint service,
name of a endpoint service or a
:class:`~otcextensions.sdk.vpcep.target_service.TargetService`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: One
:class:`~otcextensions.sdk.vpcep.target_service.TargetService`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
try:
base_path = _target_service.TargetService.base_path + \
'?id={}'.format(name_or_id)
return self._get(
_target_service.TargetService,
base_path=base_path,
requires_id=False
)
except exceptions.ResourceNotFound:
pass

try:
base_path = _target_service.TargetService.base_path + \
'?endpoint_service_name={}'.format(name_or_id)
return self._get(
_target_service.TargetService,
base_path=base_path,
requires_id=False
)
except exceptions.ResourceNotFound:
if ignore_missing:
return None
else:
raise

# ======== VPCEP Resource Quota ========

def resource_quota(self, type=None):
49 changes: 49 additions & 0 deletions otcextensions/sdk/vpcep/v1/public_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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 PublicService(resource.Resource):
base_path = '/vpc-endpoint-services/public'
resources_key = 'endpoint_services'

_query_mapping = resource.QueryParameters(
'id',
'limit',
'name',
'offset',
'sort_key',
'sort_dir',
name='endpoint_service_name',
)

# capabilities
allow_create = False
allow_fetch = False
allow_commit = False
allow_delete = False
allow_list = True

# Properties
#: ID of the VPC endpoint service.
id = resource.Body('id')
#: Owner of the VPC endpoint service.
owner = resource.Body('owner')
#: Name of the VPC endpoint service.
service_name = resource.Body('service_name')
#: Type of the VPC endpoint service.
service_type = resource.Body('service_type')
#: Creation time of the VPC endpoint service.
created_at = resource.Body('created_at')
#: If the usage of the VPC endpoint service will be charged.
is_charge = resource.Body('is_charge')
44 changes: 44 additions & 0 deletions otcextensions/sdk/vpcep/v1/target_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 TargetService(resource.Resource):
base_path = '/vpc-endpoint-services/describe'

_query_mapping = resource.QueryParameters(
'id',
'name',
name='endpoint_service_name',
)

# capabilities
allow_create = False
allow_fetch = True
allow_commit = False
allow_delete = False
allow_list = True

requires_id = False

# Properties
#: ID of the VPC endpoint service.
id = resource.Body('id')
#: Name of the VPC endpoint service.
service_name = resource.Body('service_name')
#: Type of the VPC endpoint service.
service_type = resource.Body('service_type')
#: Creation time of the VPC endpoint service.
created_at = resource.Body('created_at')
#: If the usage of the VPC endpoint service will be charged.
is_charge = resource.Body('is_charge')
27 changes: 27 additions & 0 deletions otcextensions/tests/unit/sdk/vpcep/v1/test_proxy.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
from otcextensions.sdk.vpcep.v1 import quota
from otcextensions.sdk.vpcep.v1 import service
from otcextensions.sdk.vpcep.v1 import whitelist
from otcextensions.sdk.vpcep.v1 import public_service
from otcextensions.sdk.vpcep.v1 import target_service


class TestVpcepProxy(test_proxy_base.TestProxyBase):
@@ -156,3 +158,28 @@ def test_manage_service_connections_reject(self):
class TestQuota(TestVpcepProxy):
def test_resource_quota(self):
self.verify_list(self.proxy.resource_quota, quota.Quota)


class TestPublicService(TestVpcepProxy):
def test_public_services(self):
self.verify_list(
self.proxy.public_services, public_service.PublicService
)


class TestTargetService(TestVpcepProxy):
def test_get_target_service(self):
resource_id = 'resource_id'
base_path_id = target_service.TargetService.base_path + \
'?id={}'.format(resource_id)

self._verify(
'otcextensions.sdk.vpcep.v1._proxy.Proxy._get',
self.proxy.get_target_service,
method_args=[resource_id],
expected_args=[target_service.TargetService],
expected_kwargs={
'base_path': base_path_id,
'requires_id': False,
}
)
55 changes: 55 additions & 0 deletions otcextensions/tests/unit/sdk/vpcep/v1/test_public_service.py
Original file line number Diff line number Diff line change
@@ -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.tests.unit import base
from otcextensions.sdk.vpcep.v1 import public_service
from otcextensions.tests.unit.sdk.utils import assert_attributes_equal


EXAMPLE = {
"id": "b0e22f6f-26f4-461c-b140-d873464d4fa0",
"owner": "example",
"service_name": "test123",
"service_type": "interface",
"created_at": "2018-09-10T13:13:23Z",
"is_charge": "true"
}


class TestPublicService(base.TestCase):
def test_basic(self):
sot = public_service.PublicService()
self.assertEqual('endpoint_services', sot.resources_key)
self.assertEqual(None, sot.resource_key)
self.assertEqual('/vpc-endpoint-services/public', sot.base_path)
self.assertTrue(sot.allow_list)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_fetch)
self.assertFalse(sot.allow_commit)
self.assertFalse(sot.allow_delete)

self.assertDictEqual(
{
'id': 'id',
'limit': 'limit',
'marker': 'marker',
'offset': 'offset',
'name': 'endpoint_service_name',
'sort_key': 'sort_key',
'sort_dir': 'sort_dir',
},
sot._query_mapping._mapping,
)

def test_make_it(self):
sot = public_service.PublicService(**EXAMPLE)
assert_attributes_equal(self, sot, EXAMPLE)
52 changes: 52 additions & 0 deletions otcextensions/tests/unit/sdk/vpcep/v1/test_target_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.tests.unit import base
from otcextensions.sdk.vpcep.v1 import target_service
from otcextensions.tests.unit.sdk.utils import assert_attributes_equal


EXAMPLE = {
"id": "9d4c1028-1336-4556-9881-b5d807c1b8a8",
"service_name": "test123",
"service_type": "interface",
"created_at": "2018-09-17T07:28:31Z",
"is_charge": "true"
}


class TestTargetService(base.TestCase):

def test_basic(self):
sot = target_service.TargetService()
self.assertEqual(None, sot.resources_key)
self.assertEqual(None, sot.resource_key)
self.assertEqual('/vpc-endpoint-services/describe', sot.base_path)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.allow_fetch)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_commit)
self.assertFalse(sot.allow_delete)

self.assertDictEqual(
{
'id': 'id',
'limit': 'limit',
'marker': 'marker',
'name': 'endpoint_service_name',
},
sot._query_mapping._mapping,
)

def test_make_it(self):
sot = target_service.TargetService(**EXAMPLE)
assert_attributes_equal(self, sot, EXAMPLE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Add query operations for public VPC endpoint services and target VPC endpoint service.

0 comments on commit 5cb6910

Please sign in to comment.