简体   繁体   English

如何在openstack中使用python API 0.11.0设置图像元数据?

[英]How to set image metadata with python API 0.11.0 in openstack grizzly?

I work with a DevStack -Grizzly installation. 我有一张DevStack -Grizzly安装。 I add an image with metadata [see the code] using Openstack python API . 我使用Openstack python API添加带元数据的图像[参见代码]。

I use glance.images.create and provide metadata by properties argument. 我使用glance.images.create并通过properties参数提供元数据。 Unfortunately, the created image has no metadata (properties). 不幸的是,创建的图像没有元数据(属性)。 image.get prints NONE . image.get打印NONE

import keystoneclient.v2_0.client as ksclient
import glanceclient

keystone = ksclient.Client(auth_url=credentials['auth-url'], username=credentials['username'],
                       password=credentials['password'], tenant_name=credentials['tenant'])

glance_endpoint = keystone.service_catalog.url_for(service_type='image',
                                                   endpoint_type='publicURL')

glance = glanceclient.Client('1',glance_endpoint, token=keystone.auth_token)
image_name="test-cirros"
image_file="cirros.img"

with open( image_file ) as fimage:
            image = glance.images.create(name=image_name, is_public=True, disk_format="qcow2", container_format="bare", data=fimage, properties =  {"aaaa": "13", "'bbbbbb": "12"} )
            print image.get() // prints NONE

Is there other way of setting image metadata? 还有其他设置图像元数据的方法吗?

Custom Properties != metadata, so the horizon does not display them and image.get returns empty hash. 自定义属性!=元数据,因此地平线不显示它们,image.get返回空哈希。

To grab the metadata, I need to use nova client (API version 1.1 --- nova.images.get(image.id).metadata ): 要获取元数据,我需要使用nova客户端(API版本1.1 --- nova.images.get(image.id).metadata ):

 # ...
 from novaclient import client as novaclient

 # ...

 nova = novaclient.Client("1.1", auth_url=credentials['auth-url'], username=credentials['username'], api_key=credentials['password'], project_id=credentials['tenant'])

 # ...

 with open( image_file ) as fimage:
            image = glance.images.create(name=image_name, is_public=True, disk_format="qcow2", container_format="bare", data=fimage, properties =  {"aaaa": "13", "'bbbbbb": "12"} )

             print nova.images.get(image.id).metadata # prints the correct metadata

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Openstack python API:如何使用python api从一瞥下载图像 - Openstack python API: how to download image from glance using the python api 如何使用Python API为azure blob创建/设置新元数据并获取元数据? - How do I create/set a new metadata to an azure blob and get the metadata by using Python API? 如何在Python(Boto lib)中像在Openstack Swift中那样获取Amazon S3存储桶的元数据/标头? - How to get metadata/headers of an Amazon S3 Bucket in Python (Boto lib) like in Openstack Swift? 如何列出具有完整信息的openstack服务。 使用python API - how to list openstack services with full info. using python api Openstack python api:如何使用应用程序凭据创建连接? - Openstack python api: How create a connection using Application Credentials? Openstack:如何在python API 中获取客户端的IP - Openstack: how to get client's IP in the python API Openstack Rest API将带有python的文件发送到openstack容器 - Openstack Rest API send a file with python to a openstack container 如何使用python从图像中提取元数据? - How to extract metadata from an image using python? 如何使用魔杖python删除图像元数据 - How to remove image metadata using wand python 如何在 python 中保留图像的 IPTC 元数据 - How to preserve IPTC metadata of an image in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM