Search code examples
openstackpython-novaclient

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?


Solution

  • 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.

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

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