Determine flavor type from the public nova API.

Fixes bug 1078298

Previously the flavor name used in the flavor-specific instance meter
was available from the nova DB instance representation.

Now that we retrieve the on-host instances from the public nova
API as opposed to the DB, we need to retrieve and cache the flavor
name separately.

Change-Id: Ifd15eedd34e4128d5f9bdaa9318049e973dac9ed
This commit is contained in:
Eoghan Glynn
2012-11-13 14:01:58 +00:00
parent 171b1ce449
commit f3641de37f
3 changed files with 12 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ class InstancePollster(LibVirtPollster):
)
yield make_counter_from_instance(instance,
name='instance:%s' %
instance.instance_type.name,
instance.flavor['name'],
type=counter.TYPE_GAUGE,
volume=1,
)

View File

@@ -49,12 +49,20 @@ class Client(object):
auth_url=cfg.CONF.os_auth_url,
no_cache=True)
def _with_flavor(self, instances):
flavors = dict((f.id, f) for f in self.nova_client.flavors.list())
for instance in instances:
fid = instance.flavor['id']
instance.flavor['name'] = flavors[fid].name
return instances
@logged
def instance_get_all_by_host(self, hostname):
"""Returns list of instances on particular host"""
search_opts = {'host': hostname, 'all_tenants': True}
return self.nova_client.servers.list(detailed=True,
search_opts=search_opts)
return self._with_flavor(self.nova_client.servers.list(
detailed=True,
search_opts=search_opts))
@logged
def floating_ip_get_all(self):

View File

@@ -59,8 +59,7 @@ class TestLibvirtBase(test_base.TestCase):
setattr(self.instance, 'OS-EXT-SRV-ATTR:instance_name',
self.instance.name)
self.instance.id = 1
self.instance.instance_type = mock.MagicMock()
self.instance.instance_type.name = 'm1.small'
self.instance.flavor = {'name': 'm1.small', 'id': 2}
flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver'
flags.FLAGS.connection_type = 'libvirt'