diff --git a/openstack/compute/__init__.py b/openstack/compute/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/compute/compute_service.py b/openstack/compute/compute_service.py new file mode 100644 index 000000000..c8f1fd039 --- /dev/null +++ b/openstack/compute/compute_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 ComputeService(service_filter.ServiceFilter): + """The compute service.""" + + def __init__(self): + """Create an compute service.""" + super(ComputeService, self).__init__(service_type='compute') diff --git a/openstack/compute/v2/__init__.py b/openstack/compute/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/compute/v2/flavor.py b/openstack/compute/v2/flavor.py new file mode 100644 index 000000000..a5b22bdc4 --- /dev/null +++ b/openstack/compute/v2/flavor.py @@ -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') diff --git a/openstack/tests/compute/__init__.py b/openstack/tests/compute/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/compute/test_compute_service.py b/openstack/tests/compute/test_compute_service.py new file mode 100644 index 000000000..115cf9d8d --- /dev/null +++ b/openstack/tests/compute/test_compute_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.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) diff --git a/openstack/tests/compute/v2/__init__.py b/openstack/tests/compute/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/compute/v2/test_flavor.py b/openstack/tests/compute/v2/test_flavor.py new file mode 100644 index 000000000..ec88d623d --- /dev/null +++ b/openstack/tests/compute/v2/test_flavor.py @@ -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)