Merge "Add the Type resource for the Volume service"

This commit is contained in:
Jenkins
2015-02-21 02:09:57 +00:00
committed by Gerrit Code Review
7 changed files with 104 additions and 0 deletions

View File

@@ -76,6 +76,7 @@ The following services have exposed *Resource* classes.
Database <resources/database/index>
Network <resources/network/index>
Object Store <resources/object_store/index>
Volume <resources/volume/index>
Low-Level Classes
*****************

View File

@@ -0,0 +1,7 @@
Volume Resources
================
.. toctree::
:maxdepth: 1
v2/type

View File

@@ -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:

View File

View File

@@ -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)

View File

View File

@@ -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)