diff --git a/doc/source/users/index.rst b/doc/source/users/index.rst index 363dabab..1eb400bf 100644 --- a/doc/source/users/index.rst +++ b/doc/source/users/index.rst @@ -76,6 +76,7 @@ The following services have exposed *Resource* classes. Database Network Object Store + Volume Low-Level Classes ***************** diff --git a/doc/source/users/resources/volume/index.rst b/doc/source/users/resources/volume/index.rst new file mode 100644 index 00000000..ebf78763 --- /dev/null +++ b/doc/source/users/resources/volume/index.rst @@ -0,0 +1,7 @@ +Volume Resources +================ + +.. toctree:: + :maxdepth: 1 + + v2/type diff --git a/doc/source/users/resources/volume/v2/type.rst b/doc/source/users/resources/volume/v2/type.rst new file mode 100644 index 00000000..d5a6bc74 --- /dev/null +++ b/doc/source/users/resources/volume/v2/type.rst @@ -0,0 +1,13 @@ +openstack.volume.v2.type +======================== + +.. automodule:: openstack.volume.v2.type + +The Type Class +-------------- + +The ``Type`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.volume.v2.type.Type + :members: + diff --git a/openstack/tests/volume/v2/__init__.py b/openstack/tests/volume/v2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/tests/volume/v2/test_type.py b/openstack/tests/volume/v2/test_type.py new file mode 100644 index 00000000..8a440517 --- /dev/null +++ b/openstack/tests/volume/v2/test_type.py @@ -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. + +import testtools + +from openstack.volume.v2 import type + +FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff" +TYPE = { + "extra_specs": { + "capabilities": "gpu" + }, + "id": FAKE_ID, + "name": "SSD" +} + + +class TestType(testtools.TestCase): + + def test_basic(self): + sot = type.Type(TYPE) + self.assertEqual("volume_type", sot.resource_key) + self.assertEqual("volume_types", sot.resources_key) + self.assertEqual("id", sot.id_attribute) + self.assertEqual("/types", sot.base_path) + self.assertEqual("volume", sot.service.service_type) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_retrieve) + self.assertTrue(sot.allow_delete) + self.assertFalse(sot.allow_list) + + def test_new(self): + sot = type.Type.new(id=FAKE_ID) + self.assertEqual(FAKE_ID, sot.id) + + def test_create(self): + sot = type.Type(TYPE) + self.assertEqual(TYPE["id"], sot.id) + self.assertEqual(TYPE["extra_specs"], sot.extra_specs) + self.assertEqual(TYPE["name"], sot.name) diff --git a/openstack/volume/v2/__init__.py b/openstack/volume/v2/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/volume/v2/type.py b/openstack/volume/v2/type.py new file mode 100644 index 00000000..b0fe0c8d --- /dev/null +++ b/openstack/volume/v2/type.py @@ -0,0 +1,34 @@ +# 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.volume import volume_service + + +class Type(resource.Resource): + resource_key = "volume_type" + resources_key = "volume_types" + base_path = "/types" + service = volume_service.VolumeService() + + # capabilities + allow_retrieve = True + allow_create = True + allow_delete = True + + # Properties + #: A UUID representing this volume. + id = resource.prop("id") + #: Name of the type. + name = resource.prop("name") + #: A dict of extra specifications. "capabilities" is a usual key. + extra_specs = resource.prop("extra_specs", type=dict)