[libvirt] [python][RFC] more python bulk stats API

Francesco Romani fromani at redhat.com
Tue Feb 24 14:44:43 UTC 2015


Hi,

I was wondering if there is room in libvirt-python for a couple of new APIs
which could make life easier for python developers.
It is not just a theoretical thing, when developing VDSM, part of oVirt, I
found myself repeating these patterns long enough.

1. return dict from getAllDomainStats and domainListGetStats
both bulk stats API returns on success a list of tuples, each tuple being (DomainReference, DictOfStats) ,
and I often find myself in need to translate them into a dict like {VMUUID:DictOfStats} , using some code like

def _translate(bulk_stats):
    return dict((dom.UUIDString(), stats)
                for dom, stats in bulk_stats)

So I'd like to suggest new APIs:

  virConnection.getAllDomainStatsMap()
  virConnection.domainListGetStatsMap()

which directly return the dict()s above; arguments should be like getAllDomainStats and domainListGetStats,
respectively.

2. get all the bulk stats from a single VM
it is trival and efficient to do this in C, but to do that in python means to use throwaway temporary lists,
one for the domain and one for the result
No big deal, but again, why to waste? I'd like to have

  virDomain.getBulkStats(stats)  # stats is like in getAllDomainStats

that should return just the DictOfStats on success.

For performance reasons, all of the above should be done in C.

Just in case, I have proof of concept code for all the above. I can post a tentative patch if maintainers like
these ideas.

Thanks,

Thoughts welcome

-- 
Francesco Romani
RedHat Engineering Virtualization R & D
Phone: 8261328
IRC: fromani




More information about the libvir-list mailing list