Add image user guide
Add an image user guide to replace the current placeholder. Also, add image examples and related tests to go along with the guide. Much of the content for the guide was pulled from [1]. [1] http://docs.openstack.org/image-guide/ Change-Id: I8b3a1618b09f3570f3b69d8c228bed56d4d1c151 Closes-Bug: #1466183
This commit is contained in:
parent
004bad9f1f
commit
003ff67dc8
@ -5,4 +5,43 @@ Before working with the Image service, you'll need to create a connection
|
||||
to your OpenStack cloud by following the :doc:`connect` user guide. This will
|
||||
provide you with the ``conn`` variable used in the examples below.
|
||||
|
||||
.. TODO(thowe): Implement this guide
|
||||
The primary resource of the Image service is the image.
|
||||
|
||||
List Images
|
||||
-----------
|
||||
|
||||
An **image** is a collection of files for a specific operating system
|
||||
that you use to create or rebuild a server. OpenStack provides
|
||||
`pre-built images <http://docs.openstack.org/image-guide/obtain-images.html>`_.
|
||||
You can also create custom images, or snapshots, from servers that you have
|
||||
launched. Images come in different formats and are sometimes called virtual
|
||||
machine images.
|
||||
|
||||
.. literalinclude:: ../examples/image/list.py
|
||||
:pyobject: list_images
|
||||
|
||||
Full example: `image resource list`_
|
||||
|
||||
Create Image
|
||||
------------
|
||||
|
||||
Create an image by uploading its data and setting its attributes.
|
||||
|
||||
.. literalinclude:: ../examples/image/create.py
|
||||
:pyobject: upload_image
|
||||
|
||||
Full example: `image resource create`_
|
||||
|
||||
Delete Image
|
||||
------------
|
||||
|
||||
Delete an image.
|
||||
|
||||
.. literalinclude:: ../examples/image/delete.py
|
||||
:pyobject: delete_image
|
||||
|
||||
Full example: `image resource delete`_
|
||||
|
||||
.. _image resource create: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/image/create.py
|
||||
.. _image resource delete: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/image/delete.py
|
||||
.. _image resource list: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/image/list.py
|
||||
|
@ -63,6 +63,8 @@ PRIVATE_KEYPAIR_FILE = _get_resource_value(
|
||||
'private_keypair_file', '{ssh_dir}/id_rsa.{key}'.format(
|
||||
ssh_dir=SSH_DIR, key=KEYPAIR_NAME))
|
||||
|
||||
EXAMPLE_IMAGE_NAME = 'openstacksdk-example-public-image'
|
||||
|
||||
|
||||
def create_connection_from_config():
|
||||
return connection.from_config(cloud_config=cloud, options=opts)
|
||||
|
0
examples/image/__init__.py
Normal file
0
examples/image/__init__.py
Normal file
37
examples/image/create.py
Normal file
37
examples/image/create.py
Normal file
@ -0,0 +1,37 @@
|
||||
# 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 examples.connect import EXAMPLE_IMAGE_NAME
|
||||
|
||||
"""
|
||||
Create resources with the Image service.
|
||||
|
||||
For a full guide see
|
||||
http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html
|
||||
"""
|
||||
|
||||
|
||||
def upload_image(conn):
|
||||
print("Upload Image:")
|
||||
|
||||
# Load fake image data for the example.
|
||||
data = 'This is fake image data.'
|
||||
|
||||
# Build the image attributes and upload the image.
|
||||
image_attrs = {
|
||||
'name': EXAMPLE_IMAGE_NAME,
|
||||
'data': data,
|
||||
'disk_format': 'raw',
|
||||
'container_format': 'bare',
|
||||
'visibility': 'public',
|
||||
}
|
||||
conn.image.upload_image(**image_attrs)
|
28
examples/image/delete.py
Normal file
28
examples/image/delete.py
Normal file
@ -0,0 +1,28 @@
|
||||
# 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 examples.connect import EXAMPLE_IMAGE_NAME
|
||||
|
||||
"""
|
||||
Delete resources with the Image service.
|
||||
|
||||
For a full guide see
|
||||
http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html
|
||||
"""
|
||||
|
||||
|
||||
def delete_image(conn):
|
||||
print("Delete Image:")
|
||||
|
||||
example_image = conn.image.find_image(EXAMPLE_IMAGE_NAME)
|
||||
|
||||
conn.image.delete_image(example_image, ignore_missing=False)
|
25
examples/image/list.py
Normal file
25
examples/image/list.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.
|
||||
|
||||
"""
|
||||
List resources from the Image service.
|
||||
|
||||
For a full guide see
|
||||
http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html
|
||||
"""
|
||||
|
||||
|
||||
def list_images(conn):
|
||||
print("List Images:")
|
||||
|
||||
for image in conn.image.images():
|
||||
print(image)
|
37
openstack/tests/examples/test_image.py
Normal file
37
openstack/tests/examples/test_image.py
Normal file
@ -0,0 +1,37 @@
|
||||
# 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 unittest
|
||||
|
||||
from examples import connect
|
||||
from examples.image import create as image_create
|
||||
from examples.image import delete as image_delete
|
||||
from examples.image import list as image_list
|
||||
|
||||
|
||||
class TestImage(unittest.TestCase):
|
||||
"""Test the image examples
|
||||
|
||||
The purpose of these tests is to ensure the examples run without erring
|
||||
out.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.conn = connect.create_connection_from_config()
|
||||
|
||||
def test_image(self):
|
||||
image_list.list_images(self.conn)
|
||||
|
||||
image_create.upload_image(self.conn)
|
||||
|
||||
image_delete.delete_image(self.conn)
|
Loading…
Reference in New Issue
Block a user