XenAPI support: Changes for networking metrics
Implemented inspect_vnic_rates() to inspect the vNIC rate statistics for an instance. Change-Id: Ic8fb59904f5ff8fc05819b9414b7730b8746bfad Implements: blueprint xenapi-support
This commit is contained in:
parent
cca1987ab2
commit
83e216fe0d
@ -145,3 +145,25 @@ class XenapiInspector(virt_inspector.Inspector):
|
||||
# Stat provided from XenServer is in B, converting it to MB.
|
||||
memory = long(metrics_rec['memory_actual']) / units.Mi
|
||||
return virt_inspector.MemoryUsageStats(usage=memory)
|
||||
|
||||
def inspect_vnic_rates(self, instance, duration=None):
|
||||
instance_name = util.instance_name(instance)
|
||||
vm_ref = self._lookup_by_name(instance_name)
|
||||
vif_refs = self._call_xenapi("VM.get_VIFs", vm_ref)
|
||||
if vif_refs:
|
||||
for vif_ref in vif_refs:
|
||||
vif_rec = self._call_xenapi("VIF.get_record", vif_ref)
|
||||
vif_metrics_ref = self._call_xenapi(
|
||||
"VIF.get_metrics", vif_ref)
|
||||
vif_metrics_rec = self._call_xenapi(
|
||||
"VIF_metrics.get_record", vif_metrics_ref)
|
||||
|
||||
interface = virt_inspector.Interface(
|
||||
name=vif_rec['uuid'],
|
||||
mac=vif_rec['MAC'],
|
||||
fref=None,
|
||||
parameters=None)
|
||||
rx_rate = float(vif_metrics_rec['io_read_kbs']) * units.Ki
|
||||
tx_rate = float(vif_metrics_rec['io_write_kbs']) * units.Ki
|
||||
stats = virt_inspector.InterfaceRateStats(rx_rate, tx_rate)
|
||||
yield (interface, stats)
|
||||
|
@ -99,3 +99,43 @@ class TestXenapiInspection(base.BaseTestCase):
|
||||
side_effect=fake_xenapi_request):
|
||||
memory_stat = self.inspector.inspect_memory_usage(fake_instance)
|
||||
self.assertEqual(fake_stat, memory_stat)
|
||||
|
||||
def test_inspect_vnic_rates(self):
|
||||
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
|
||||
'id': 'fake_instance_id'}
|
||||
|
||||
def fake_xenapi_request(method, args):
|
||||
vif_rec = {
|
||||
'metrics': 'vif_metrics_ref',
|
||||
'uuid': 'vif_uuid',
|
||||
'MAC': 'vif_mac',
|
||||
}
|
||||
|
||||
vif_metrics_rec = {
|
||||
'io_read_kbs': '1',
|
||||
'io_write_kbs': '2',
|
||||
}
|
||||
if method == 'VM.get_by_name_label':
|
||||
return ['vm_ref']
|
||||
elif method == 'VM.get_VIFs':
|
||||
return ['vif_ref']
|
||||
elif method == 'VIF.get_record':
|
||||
return vif_rec
|
||||
elif method == 'VIF.get_metrics':
|
||||
return 'vif_metrics_ref'
|
||||
elif method == 'VIF_metrics.get_record':
|
||||
return vif_metrics_rec
|
||||
else:
|
||||
return None
|
||||
|
||||
session = self.inspector.session
|
||||
with mock.patch.object(session, 'xenapi_request',
|
||||
side_effect=fake_xenapi_request):
|
||||
interfaces = list(self.inspector.inspect_vnic_rates(fake_instance))
|
||||
|
||||
self.assertEqual(1, len(interfaces))
|
||||
vnic0, info0 = interfaces[0]
|
||||
self.assertEqual('vif_uuid', vnic0.name)
|
||||
self.assertEqual('vif_mac', vnic0.mac)
|
||||
self.assertEqual(1024, info0.rx_bytes_rate)
|
||||
self.assertEqual(2048, info0.tx_bytes_rate)
|
||||
|
Loading…
Reference in New Issue
Block a user