diff --git a/examples/list.py b/examples/list.py new file mode 100644 index 00000000..ed94c58e --- /dev/null +++ b/examples/list.py @@ -0,0 +1,39 @@ +# 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 sys + +from examples import common +from examples import session + + +def make_resource(opts): + argument = opts.argument + args = argument.rpartition('.') + from_str = args[0] + class_str = args[2] + __import__(from_str) + mod = sys.modules[from_str] + return getattr(mod, class_str) + + +def run_list(opts): + sess = session.make_session(opts) + cls = make_resource(opts) + for obj in cls.list(sess): + print(str(obj)) + return + + +if __name__ == "__main__": + opts = common.setup() + sys.exit(common.main(opts, run_list)) diff --git a/openstack/image/__init__.py b/openstack/image/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/image/image_service.py b/openstack/image/image_service.py new file mode 100644 index 00000000..94e8560e --- /dev/null +++ b/openstack/image/image_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 ImageService(service_filter.ServiceFilter): + """The image service.""" + + def __init__(self): + """Create an image service.""" + super(ImageService, self).__init__(service_type='image') diff --git a/openstack/image/v1/__init__.py b/openstack/image/v1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/image/v1/image.py b/openstack/image/v1/image.py new file mode 100644 index 00000000..f5fc38a2 --- /dev/null +++ b/openstack/image/v1/image.py @@ -0,0 +1,46 @@ +# 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.image import image_service +from openstack import resource + + +class Image(resource.Resource): + resource_key = 'image' + resources_key = 'images' + base_path = '/images' + service = image_service.ImageService() + + # capabilities + allow_create = True + allow_retrieve = True + allow_update = True + allow_delete = True + allow_list = True + + # Properties + checksum = resource.prop('checksum') + container_format = resource.prop('container_format') + copy_from = resource.prop('copy_from') + disk_format = resource.prop('disk_format') + is_public = resource.prop('is_public') + location = resource.prop('location') + min_disk = resource.prop('min_disk') + min_ram = resource.prop('min_ram') + name = resource.prop('name') + owner = resource.prop('owner') + properties = resource.prop('properties') + protected = resource.prop('protected') + size = resource.prop('size') + status = resource.prop('status') + created_at = resource.prop('created_at') + updated_at = resource.prop('updated_at') diff --git a/openstack/tests/image/__init__.py b/openstack/tests/image/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/tests/image/test_image_service.py b/openstack/tests/image/test_image_service.py new file mode 100644 index 00000000..cfe76321 --- /dev/null +++ b/openstack/tests/image/test_image_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.image import image_service + + +class TestImageService(testtools.TestCase): + + def test_service(self): + sot = image_service.ImageService() + self.assertEqual('image', sot.service_type) + self.assertEqual('public', sot.visibility) + self.assertIsNone(sot.region) + self.assertIsNone(sot.service_name) diff --git a/openstack/tests/image/v1/__init__.py b/openstack/tests/image/v1/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack/tests/image/v1/test_image.py b/openstack/tests/image/v1/test_image.py new file mode 100644 index 00000000..87f2e8fc --- /dev/null +++ b/openstack/tests/image/v1/test_image.py @@ -0,0 +1,71 @@ +# 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.image.v1 import image + +IDENTIFIER = 'IDENTIFIER' +EXAMPLE = { + 'checksum': '1', + 'container_format': '2', + 'copy_from': '3', + 'disk_format': '4', + 'id': IDENTIFIER, + 'is_public': '5', + 'location': '6', + 'min_disk': '7', + 'min_ram': '8', + 'name': '9', + 'owner': '10', + 'properties': '11', + 'protected': '12', + 'size': '13', + 'status': '14', + 'created_at': '2014-06-15 14:18:37.794540', + 'updated_at': '2014-06-16 14:18:37.794540', +} + + +class TestImage(testtools.TestCase): + + def test_basic(self): + sot = image.Image() + self.assertEqual('image', sot.resource_key) + self.assertEqual('images', sot.resources_key) + self.assertEqual('/images', sot.base_path) + self.assertEqual('image', 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 = image.Image(EXAMPLE) + self.assertEqual(EXAMPLE['checksum'], sot.checksum) + self.assertEqual(EXAMPLE['container_format'], sot.container_format) + self.assertEqual(EXAMPLE['copy_from'], sot.copy_from) + self.assertEqual(EXAMPLE['disk_format'], sot.disk_format) + self.assertEqual(IDENTIFIER, sot.id) + self.assertEqual(EXAMPLE['is_public'], sot.is_public) + self.assertEqual(EXAMPLE['location'], sot.location) + self.assertEqual(EXAMPLE['min_disk'], sot.min_disk) + self.assertEqual(EXAMPLE['min_ram'], sot.min_ram) + self.assertEqual(EXAMPLE['name'], sot.name) + self.assertEqual(EXAMPLE['owner'], sot.owner) + self.assertEqual(EXAMPLE['properties'], sot.properties) + self.assertEqual(EXAMPLE['protected'], sot.protected) + self.assertEqual(EXAMPLE['size'], sot.size) + self.assertEqual(EXAMPLE['status'], sot.status) + self.assertEqual(EXAMPLE['created_at'], sot.created_at) + self.assertEqual(EXAMPLE['updated_at'], sot.updated_at)