<div dir="ltr"><div class="gmail_default"><font face="arial, helvetica, sans-serif" color="#3d85c6">Hi, </font></div><div class="gmail_default"><font face="verdana, sans-serif" color="#3d85c6"><br></font></div><div class="gmail_default">
<font face="verdana, sans-serif" color="#3d85c6">I am trying to get flavor extra specs from "instance" parameter passed to "get_guest_config" function defined in nova/virt/libvirt/driver.py . </font><span style="color:rgb(61,133,198);font-family:verdana,sans-serif">I tried following code but it returned me the flavor without extra specs.</span></div>
<div class="gmail_default"><font face="verdana, sans-serif" color="#3d85c6"><br></font></div><div class="gmail_default"><font color="#3d85c6">get_guest_config function in nova/virt/libvirt/driver.py is somewhat like this.</font></div>
<div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif"> @myfile.custom_decorator</font></div><div class="gmail_default">
<font face="arial, helvetica, sans-serif"> def get_guest_config(self, instance, network_info, image_meta,</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> disk_info, rescue=None, block_device_info=None):</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> inst_type = self.virtapi.instance_type_get(</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> nova_context.get_admin_context(read_deleted='yes'),</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> instance['instance_type_id'])</font></div><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif"> ...</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> ... </font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> ..... </font></div><div class="gmail_default">
<font face="arial, helvetica, sans-serif"> return guest. </font></div><div><br></div></div><div class="gmail_default"><font face="verdana, sans-serif" color="#3d85c6">I was writing this custom decorator for above function, I needed flavor extra specs in this decorator:</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">from nova.compute import flavors<br></font></div><div class="gmail_default">
<font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif">def custom_decorator(get_guest_config):</font></div><div class="gmail_default">
<font face="arial, helvetica, sans-serif"> def wrapper(self, instance, network_info, image_meta,</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> disk_info, rescue=None, block_device_info=None):</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> guest= get_guest_config(self, instance, network_info, image_meta,</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> disk_info, rescue, block_device_info)</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> #inst_type defined to extract flavor specs from instance</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> inst_type = flavors.extract_flavor(instance)</font></div>
</div></div><div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> extra_specs = inst_type["extra_specs"] # I got Key Error on this line </font></div></div><div class="gmail_default">
<font face="arial, helvetica, sans-serif"> ...</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> ...</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"> ..... </font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div></div><div class="gmail_default"><font face="verdana, sans-serif" color="#3d85c6">To verify it, I added a debug command to print inst_type and it logged following.</font></div>
<div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">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</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"> </font></div><div class="gmail_default"><span style="color:rgb(61,133,198);font-family:verdana,sans-serif">What is the right way of getting flavor extra specs from instance ??</span></div>
<div class="gmail_default"><span style="color:rgb(61,133,198);font-family:verdana,sans-serif"><br></span></div><div class="gmail_default"><font face="verdana, sans-serif" color="#3d85c6">Thanks, </font></div><div class="gmail_default">
<font face="verdana, sans-serif" color="#3d85c6">Waqas</font></div></div>