Python API v2

这些身份验证服务凭据可用于身份验证

* auth_url: Identity Service endpoint for authorization
* username: name of user
* password: user's password
* project_{name|id}: name or ID of project

在使用 Identity API v3 时,还需要以下参数

* user_domain_{name|id}: name or ID of a domain the user belongs to
* project_domain_{name|id}: name or ID for a domain the project belongs to

创建客户端

from keystoneauth1 import loading
from keystoneauth1 import session
from glanceclient import Client

loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(
    auth_url=AUTH_URL,
    username=USERNAME,
    password=PASSWORD,
    project_id=PROJECT_ID)
session = session.Session(auth=auth)

glance = Client('2', session=session)

创建

创建新镜像

image = glance.images.create(name="myNewImage")
glance.images.upload(image.id, open('/tmp/myimage.iso', 'rb'))

显示

描述特定镜像

glance.images.get(image.id)

更新

更新特定镜像

# update with a list of image attribute names and their new values
glance.images.update(image.id, name="myNewImageName")

自定义属性

为镜像设置自定义属性

# set an arbitrary property on an image
glance.images.update(image.id, my_custom_property='value')

从镜像中移除自定义属性

# remove the custom property 'my_custom_property'
glance.images.update(image.id, remove_props=['my_custom_property'])

删除

删除指定的镜像

glance.images.delete(image.id)

列出

列出您可以访问的镜像

for image in glance.images.list():
   print image

下载

下载特定镜像

d = glance.images.data(image.id)

共享镜像

与租户共享特定镜像

glance.image_members.create(image_id, member_id)

移除共享

从租户中移除共享镜像

glance.image_members.delete(image_id, member_id)

列出共享

按镜像或租户描述共享权限

glance.image_members.list(image_id)