[Openstack] How to get flavor extra specs from instance

Waqas Riaz waqas.riaz at xflowresearch.com
Mon Mar 17 22:00:48 UTC 2014


Hi,

I am trying to get flavor extra specs from "instance" parameter passed to
"get_guest_config" function defined in nova/virt/libvirt/driver.py . I
tried following code but it returned me the flavor without extra specs.

get_guest_config function in nova/virt/libvirt/driver.py is somewhat like
this.

 @myfile.custom_decorator
    def get_guest_config(self, instance, network_info, image_meta,
                         disk_info, rescue=None, block_device_info=None):
        inst_type = self.virtapi.instance_type_get(
            nova_context.get_admin_context(read_deleted='yes'),
            instance['instance_type_id'])
           ...
           ...
           .....
           return guest.

I was writing this custom decorator for above function, I needed flavor
extra specs in this decorator:

from nova.compute import flavors

def custom_decorator(get_guest_config):
    def wrapper(self, instance, network_info, image_meta,
                disk_info, rescue=None, block_device_info=None):

        guest= get_guest_config(self, instance, network_info, image_meta,
                         disk_info, rescue, block_device_info)

        #inst_type defined to extract flavor specs from instance
        inst_type = flavors.extract_flavor(instance)
        extra_specs = inst_type["extra_specs"]     #  I got Key Error  on
this  line
        ...
        ...
        .....

To verify it, I added a debug command to print inst_type and it logged
following.

2014-03-18 01:45:18.341 2532 DEBUG
nova.api.openstack.compute.contrib.myfile
[req-5ead8d10-2730-44f4-8048-6954b57be6f6 d2f66541559b46a88aa63e92b0532cc8
fb8d48a02dca4f98bdd24649c64dee6a] inst_type {'root_gb': 10, 'name':
'test_flavor', 'ephemeral_gb': 0, 'memory_mb': 1024, 'vcpus': 2, 'swap': 0,
'rxtx_factor': 1.0, 'flavorid': '99', 'vcpu_weight': None, 'id': 6} wrapper
/usr/lib/python2.6/site-packages/nova/api/openstack/compute/contrib/myfile.py:92

What is the right way of getting flavor extra specs from instance ??

Thanks,
Waqas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20140318/0162d856/attachment.html>


More information about the Openstack mailing list