[virt-tools-list] [RFC] virt-what as a reusable library
Richard W.M. Jones
rjones at redhat.com
Wed Nov 17 19:04:12 UTC 2010
On Wed, Nov 17, 2010 at 01:54:25PM -0500, Bryan Kearney wrote:
> I am working on a project which would like to know if the current
> machine is a guest, and if so what type of guest it is. This
> functionality is currently available in virt-what[1]. The current
> implementation is a bash shell which invokes a C libary. Our project
I think you mean it invokes an external C program
(virt-what-cpuid-helper).
> would be interested in seeing this functionality provided as a
> library (C or python is preferred). I sample python patch (probably
> not the best) is attached.
You can use virt-what from C in a handful of lines of code:
FILE *fp = popen ("virt-what", "r");
char line[1024];
while (fgets (line, sizeof line, fp) != NULL) {
if (strncmp (line, "xen", 3) == 0) ...;
}
pclose (fp);
It's even simpler and shorter from other languages.
The alternative you are proposing is a C library, plus bindings in
many different languages, which would add up to hundreds or thousands
of extra lines of code.
So I don't really see the benefit here.
> Would other folks see value in a library such as this? I am
> concerned that if projects each take different takes on this
> functionality by copying the code we are likely to diverge with
> un-desirable results.
You can copy specific tests from the code, or use virt-what as above.
It's worth reiterating the advice from the virt-what man page, that
using virt-what is often the wrong thing to do (not saying that in
your case -- I think your case fits into the narrow exceptions listed
in the man page). It's usually better to test for the specific APIs
you need.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
More information about the virt-tools-list
mailing list