def inspect_vnics(self, instance): domain = self._get_domain_not_shut_off_or_raise(instance) tree = etree.fromstring(domain.XMLDesc(0)) for iface in tree.findall('devices/interface'): target = iface.find('target') if target is not None: name = target.get('dev') else: continue mac = iface.find('mac') if mac is not None: mac_address = mac.get('address') else: continue fref = iface.find('filterref') if fref is not None: fref = fref.get('filter') params = dict((p.get('name').lower(), p.get('value')) for p in iface.findall('filterref/parameter')) interface = virt_inspector.Interface(name=name, mac=mac_address, fref=fref, parameters=params) dom_stats = domain.interfaceStats(name) stats = virt_inspector.InterfaceStats(rx_bytes=dom_stats[0], rx_packets=dom_stats[1], rx_errors=dom_stats[2], rx_dropped=dom_stats[3], tx_bytes=dom_stats[4], tx_packets=dom_stats[5], tx_errors=dom_stats[6], tx_dropped=dom_stats[7]) yield (interface, stats)
def inspect_vnics(self, instance_name): domain = self._lookup_by_name(instance_name) state = domain.info()[0] if state == libvirt.VIR_DOMAIN_SHUTOFF: return tree = etree.fromstring(domain.XMLDesc(0)) for iface in tree.findall('devices/interface'): target = iface.find('target') if target is not None: name = target.get('dev') else: continue mac = iface.find('mac') if mac is not None: mac_address = mac.get('address') else: continue fref = iface.find('filterref') if fref is not None: fref = fref.get('filter') params = dict((p.get('name').lower(), p.get('value')) for p in iface.findall('filterref/parameter')) interface = virt_inspector.Interface(name=name, mac=mac_address, fref=fref, parameters=params) dom_stats = domain.interfaceStats(name) stats = virt_inspector.InterfaceStats(rx_bytes=dom_stats[0], rx_packets=dom_stats[1], tx_bytes=dom_stats[4], tx_packets=dom_stats[5]) yield (interface, stats)
def inspect_vnics(self, instance_name): for vnic_metrics in self._utils.get_vnic_metrics(instance_name): interface = virt_inspector.Interface( name=vnic_metrics["element_name"], mac=vnic_metrics["address"], fref=None, parameters=None) stats = virt_inspector.InterfaceStats( rx_bytes=vnic_metrics['rx_mb'] * units.Mi, rx_packets=0, tx_bytes=vnic_metrics['tx_mb'] * units.Mi, tx_packets=0) yield (interface, stats)