简体   繁体   中英

How to update metadata flavor openstack using python novaclient?

I can list and create flavor using this code:

flavors_list = nova_client.flavors.list()
print_flavors(flavors_list)

print(nova_client.servers.list())
nova_client.flavors.create(name = 'test2', ram = 512, vcpus = 1, 
                       disk = 1000, 
                       flavorid='auto', ephemeral=0, swap=0, 
                       rxtx_factor=1.0, is_public=True)

But I can find method for update metadata flavor.

Anybody know which method updates metadata flavor?

There is the method "set_keys(metadata)" in novaclient.v2.flavors.Flavor class.

I think you can use it to update metadata

new_flavor = nova_client.flavors.create(name='test2',
                                        ram=512,
                                        vcpus=1,
                                        disk=1000,
                                        flavorid='auto',
                                        ephemeral=0,
                                        swap=0,
                                        rxtx_factor=1.0,
                                        is_public=True)
new_flavor.set_keys(metadata)

where metadata is a dict of key/value pairs to be set.

ps The method "create( )" will return the Flavor object.

reference : http://docs.openstack.org/developer/python-novaclient/ref/v2/flavors.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM