如何在openstack grizzly中用pythonapi0.11.0设置图像元数据?

2024-06-01 01:19:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用DevStack-Grizzly安装。我使用Openstack python API添加带有元数据的图像[请参阅代码]。在

我用glass.images.create并通过属性参数提供元数据。不幸的是,创建的映像没有元数据(属性)。在图像.get打印。在

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

有没有其他方法可以设置图像元数据?在


Tags: 数据name图像imageimportauthurlget
1条回答
网友
1楼 · 发布于 2024-06-01 01:19:44

自定义属性!=元数据,因此地平线不显示它们,并且图像.get返回空哈希。在

为了获取元数据,我需要使用nova客户端(API版本1.1-nova.images.get(图像.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

相关问题 更多 >