Very basic image resource
All I've tried with this resource is listing so far. I don't see why some other operations wouldn't work, but I want to get this in to get things rolling. To run the example: python -m examples.list openstack.image.v1.image.Image Change-Id: Ia341c8bc2a914e38b96a67a21efb40ad8cf4e93c
This commit is contained in:
39
examples/list.py
Normal file
39
examples/list.py
Normal file
@@ -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))
|
0
openstack/image/__init__.py
Normal file
0
openstack/image/__init__.py
Normal file
21
openstack/image/image_service.py
Normal file
21
openstack/image/image_service.py
Normal 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 ImageService(service_filter.ServiceFilter):
|
||||
"""The image service."""
|
||||
|
||||
def __init__(self):
|
||||
"""Create an image service."""
|
||||
super(ImageService, self).__init__(service_type='image')
|
0
openstack/image/v1/__init__.py
Normal file
0
openstack/image/v1/__init__.py
Normal file
46
openstack/image/v1/image.py
Normal file
46
openstack/image/v1/image.py
Normal file
@@ -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')
|
0
openstack/tests/image/__init__.py
Normal file
0
openstack/tests/image/__init__.py
Normal file
25
openstack/tests/image/test_image_service.py
Normal file
25
openstack/tests/image/test_image_service.py
Normal 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.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)
|
0
openstack/tests/image/v1/__init__.py
Normal file
0
openstack/tests/image/v1/__init__.py
Normal file
71
openstack/tests/image/v1/test_image.py
Normal file
71
openstack/tests/image/v1/test_image.py
Normal file
@@ -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)
|
Reference in New Issue
Block a user