From 393052c030041dafbad29787b4d9dedddf65c1a9 Mon Sep 17 00:00:00 2001 From: Steve Lewis Date: Fri, 8 Aug 2014 10:26:04 -0700 Subject: [PATCH] Introducing telemetry service Includes the Capabilities resource, available for list only. Change-Id: If8b9f54eaf97fc9de46b7d723ca15e4265469a34 --- openstack/telemetry/__init__.py | 0 openstack/telemetry/telemetry_service.py | 21 ++++++++++ openstack/telemetry/v2/__init__.py | 0 openstack/telemetry/v2/capabilities.py | 27 ++++++++++++ openstack/tests/telemetry/__init__.py | 0 .../tests/telemetry/test_telemetry_service.py | 25 +++++++++++ openstack/tests/telemetry/v2/__init__.py | 0 .../tests/telemetry/v2/test_capabilities.py | 42 +++++++++++++++++++ 8 files changed, 115 insertions(+) create mode 100644 openstack/telemetry/__init__.py create mode 100644 openstack/telemetry/telemetry_service.py create mode 100644 openstack/telemetry/v2/__init__.py create mode 100644 openstack/telemetry/v2/capabilities.py create mode 100644 openstack/tests/telemetry/__init__.py create mode 100644 openstack/tests/telemetry/test_telemetry_service.py create mode 100644 openstack/tests/telemetry/v2/__init__.py create mode 100644 openstack/tests/telemetry/v2/test_capabilities.py diff --git a/openstack/telemetry/__init__.py b/openstack/telemetry/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/telemetry/telemetry_service.py b/openstack/telemetry/telemetry_service.py new file mode 100644 index 000000000..7544cb45f --- /dev/null +++ b/openstack/telemetry/telemetry_service.py @@ -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. + +from openstack.auth import service_filter + + +class TelemetryService(service_filter.ServiceFilter): + """The telemetry service.""" + + def __init__(self): + """Create a telemetry service.""" + super(TelemetryService, self).__init__(service_type='telemetry') diff --git a/openstack/telemetry/v2/__init__.py b/openstack/telemetry/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/telemetry/v2/capabilities.py b/openstack/telemetry/v2/capabilities.py new file mode 100644 index 000000000..38af74c50 --- /dev/null +++ b/openstack/telemetry/v2/capabilities.py @@ -0,0 +1,27 @@ +# 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 +from openstack.telemetry import telemetry_service + + +class Capabilities(resource.Resource): + resource_key = 'capabilities' + resources_key = 'capabilities' + base_path = '/v2.0/capabilities' + service = telemetry_service.TelemetryService() + + # Supported Operations + allow_list = True + + # Properties + capabilities = resource.prop('api') diff --git a/openstack/tests/telemetry/__init__.py b/openstack/tests/telemetry/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/telemetry/test_telemetry_service.py b/openstack/tests/telemetry/test_telemetry_service.py new file mode 100644 index 000000000..11178a8cb --- /dev/null +++ b/openstack/tests/telemetry/test_telemetry_service.py @@ -0,0 +1,25 @@ +# 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. + +import testtools + +from openstack.telemetry import telemetry_service + + +class TestTelemetryService(testtools.TestCase): + + def test_service(self): + sot = telemetry_service.TelemetryService() + self.assertEqual('telemetry', sot.service_type) + self.assertEqual('public', sot.visibility) + self.assertIsNone(sot.region) + self.assertIsNone(sot.service_name) diff --git a/openstack/tests/telemetry/v2/__init__.py b/openstack/tests/telemetry/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/telemetry/v2/test_capabilities.py b/openstack/tests/telemetry/v2/test_capabilities.py new file mode 100644 index 000000000..9c4858c72 --- /dev/null +++ b/openstack/tests/telemetry/v2/test_capabilities.py @@ -0,0 +1,42 @@ +# 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. + +import testtools + +from openstack.telemetry.v2 import capabilities + +EXAMPLE = { + "api": {"123": False, + "135": True, + "246": True, }, +} + + +class TestMeter(testtools.TestCase): + def test_basic(self): + sot = capabilities.Capabilities() + self.assertEqual('capabilities', sot.resource_key) + self.assertEqual('capabilities', sot.resources_key) + self.assertEqual('/v2.0/capabilities', sot.base_path) + self.assertEqual('telemetry', sot.service.service_type) + self.assertFalse(sot.allow_create) + self.assertFalse(sot.allow_retrieve) + self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_delete) + self.assertTrue(sot.allow_list) + + def test_make_it(self): + sot = capabilities.Capabilities(EXAMPLE) + self.assertEqual(EXAMPLE['api'], sot.capabilities) + self.assertFalse(sot.capabilities['123']) + self.assertTrue(sot.capabilities['135']) + self.assertTrue(sot.capabilities['246'])