【问题标题】:How to set image metadata with python API 0.11.0 in openstack grizzly?如何在 openstack grizzly 中使用 python API 0.11.0 设置图像元数据?
【发布时间】:2023-04-05 01:49:02
【问题描述】:

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

我使用 glance.images.create 并通过 properties 参数提供元数据。不幸的是,创建的图像没有元数据(属性)。 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

还有其他设置图片元数据的方法吗?

【问题讨论】:

    标签: python openstack


    【解决方案1】:

    自定义属性 != 元数据,因此 Horizo​​n 不显示它们并且 image.get 返回空哈希。

    要获取元数据,我需要使用 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
    

    【讨论】:

      猜你喜欢
      • 2014-07-06
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多