Full flavor CRUD

Flavor CRUD v2

To use the low level api for the resource:

    from openstack.compute.v2 import flavor
    resp = flavor.Flavor.get_data_by_id(sess, '102')

The resp will be a dictionary.

Change-Id: I3a835e4e7ea5dd6e62cdd91748589edf54c0dcf9
This commit is contained in:
Terry Howe 2014-07-08 21:21:49 -06:00
parent c873ef693b
commit f54ee50656
8 changed files with 133 additions and 0 deletions

View File

View File

@ -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 ComputeService(service_filter.ServiceFilter):
"""The compute service."""
def __init__(self):
"""Create an compute service."""
super(ComputeService, self).__init__(service_type='compute')

View File

View File

@ -0,0 +1,36 @@
# 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.compute import compute_service
from openstack import resource
class Flavor(resource.Resource):
resource_key = 'flavor'
resources_key = 'flavors'
base_path = '/flavors'
service = compute_service.ComputeService()
# capabilities
allow_create = True
allow_retrieve = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
disk = resource.prop('disk')
links = resource.prop('links')
is_public = resource.prop('os-flavor-access:is_public')
name = resource.prop('name')
ram = resource.prop('ram')
vcpus = resource.prop('vcpus')

View File

View File

@ -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.compute import compute_service
class TestComputeService(testtools.TestCase):
def test_service(self):
sot = compute_service.ComputeService()
self.assertEqual('compute', sot.service_type)
self.assertEqual('public', sot.visibility)
self.assertIsNone(sot.region)
self.assertIsNone(sot.service_name)

View File

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.
import testtools
from openstack.compute.v2 import flavor
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
'disk': '1',
'id': IDENTIFIER,
'links': '3',
'os-flavor-access:is_public': '4',
'name': '5',
'ram': '6',
'vcpus': '7',
}
class TestFlavor(testtools.TestCase):
def test_basic(self):
sot = flavor.Flavor()
self.assertEqual('flavor', sot.resource_key)
self.assertEqual('flavors', sot.resources_key)
self.assertEqual('/flavors', sot.base_path)
self.assertEqual('compute', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = flavor.Flavor(EXAMPLE)
self.assertEqual(EXAMPLE['disk'], sot.disk)
self.assertEqual(IDENTIFIER, sot.id)
self.assertEqual(EXAMPLE['links'], sot.links)
self.assertEqual(EXAMPLE['os-flavor-access:is_public'], sot.is_public)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['ram'], sot.ram)
self.assertEqual(EXAMPLE['vcpus'], sot.vcpus)