openstacksdk - doc 翻譯(/doc/users/Image.rst)

Using OpenStack Image

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.

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.
(鏡像image是根據(jù)操作系統(tǒng)不同的一系列的文件集合,你可以使用它去創(chuàng)建和重建一個(gè)server。
openstack提供了預(yù)建的images,你也可以創(chuàng)建自定義的images,或者從運(yùn)行的server創(chuàng)建快照。
images有不同的格式,有時(shí)候也叫虛擬機(jī)鏡像。)
.. 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.
(上傳數(shù)據(jù)和設(shè)置屬性可以創(chuàng)建一個(gè)鏡像)
.. literalinclude:: ../examples/image/create.py
:pyobject: upload_image

Full example: image resource create_

.. _download_image-stream-true:

Downloading an Image with stream=True (下載鏡像)

As images are often very large pieces of data, storing their entire contents
in the memory of your application can be less than desirable. A more
efficient method may be to iterate over a stream of the response data.
(由于image是擁有很大的數(shù)據(jù),存儲(chǔ)它到你應(yīng)用的內(nèi)存是不可能的。一個(gè)更加有效率的的方式是循環(huán)迭代一個(gè)數(shù)據(jù)流)
By choosing to stream the response content, you determine the chunk_size
that is appropriate for your needs, meaning only that many bytes of data are
read for each iteration of the loop until all data has been consumed.
See :meth:requests.Response.iter_content for more information, as well
as Requests' :ref:body-content-workflow.
(在選擇去下載鏡像內(nèi)容的時(shí)候,你決定chunk_size,由你的需求決定。xxx)

When you choose to stream an image download, openstacksdk is no longer
able to compute the checksum of the response data for you. This example
shows how you might do that yourself, in a very similar manner to how
the library calculates checksums for non-streamed responses.
(當(dāng)你選擇去下載一個(gè)鏡像的數(shù)據(jù)流,openstacksdk不再有能力去計(jì)算下載的數(shù)據(jù)比例。下面的例子顯示如果你你想,你應(yīng)該怎么做,
使用一個(gè)很類似的方式庫怎么計(jì)算沒有下載的數(shù)據(jù)的校驗(yàn)和)
.. literalinclude:: ../examples/image/download.py
:pyobject: download_image_stream

Downloading an Image with stream=False

If you wish to download an image's contents all at once and to memory,
simply set stream=False, which is the default.
(如果你想去一次性下載一個(gè)鏡像的內(nèi)容,保存到內(nèi)存,那么你設(shè)置stream=False)
.. literalinclude:: ../examples/image/download.py
:pyobject: download_image

Full example: image resource download_

Delete Image

Delete an image.
(刪除一個(gè)鏡像)
.. 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
.. _image resource download: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/image/download.py

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容