Manage images

Manage images

When working with images in the SDK, you will call bothglance and nova methods.

用SDK使用 image ,需要调用glance和nova的方法。

List images

To list the available images, call the glanceclient.v2.images.Controller.list method:

glanceclient.v2.images.Controller.list 调用此方法,列出镜像。此方法将返回一个生成器: <generator object list at 0x105e9c2d0>。

import glanceclient.v2.client as glclient
glance = glclient.Client(...)
images = glance.images.list()

Get image by ID

To retrieve an image object from its ID, call the glanceclient.v2.images.Controller.get method:

用镜像ID返回镜像对象,通过调用 glanceclient.v2.images.Controller.get 方法。

import glanceclient.v2.client as glclient
image_id = 'c002c82e-2cfa-4952-8461-2095b69c18a6'
glance = glclient.Client(...)
image = glance.images.get(image_id)

Get image by name

The Image service Python bindings do not support the retrieval of an image object by name. However, the Compute Python bindings enable you to get an image object by name. To get an image object by name, call the novaclient.v1_1.images.ImageManager.find method:

Image服务不支持通过名字检索镜像对象,但是Compute支持此项功能,可以通过novaclient.v1_1.images.ImageManager.find 方法通过名称得到镜像。


import novaclient.v1_1.client as nvclient
name = "cirros"
nova = nvclient.Client(...)
image = nova.images.find(name=name)

Upload an image

To upload an image, call the glanceclient.v2.images.ImageManager.create method:

上传镜像可以通过调用 glanceclient.v2.images.ImageManager.create方法。

import glanceclient.v2.client as glclient
imagefile = "/tmp/myimage.img" #上传镜像的路径
glance = glclient.Client(...)
with open(imagefile) as fimage:
  glance.images.create(name="myimage", is_public=False, disk_format="qcow2",
                       container_format="bare", data=fimage)


详情见:

http://docs.openstack.org/user-guide/sdk_manage_images.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值