2 * section: Informations
3 * synopsis: Extract information about Xen domain 0
4 * purpose: Demonstrate the basic use of the library to connect to the
5 * hypervisor and extract domain information.
8 * copy: see Copyright for the status of this software.
12 #include <libvirt/libvirt.h>
16 * @name: the name of the domain
18 * extract the domain 0 information
21 getDomainInfo(const char *uri
, const char *name
)
23 virConnectPtr conn
= NULL
; /* the hypervisor connection */
24 virDomainPtr dom
= NULL
; /* the domain being checked */
25 virDomainInfo info
; /* the information being fetched */
28 conn
= virConnectOpenReadOnly(uri
);
30 fprintf(stderr
, "Failed to connect to hypervisor\n");
34 /* Find the domain of the given name */
35 dom
= virDomainLookupByName(conn
, name
);
37 fprintf(stderr
, "Failed to find Domain %s\n", name
);
41 /* Get the information */
42 ret
= virDomainGetInfo(dom
, &info
);
44 fprintf(stderr
, "Failed to get information for Domain %s\n", name
);
48 printf("Domain %s: %d CPUs\n", name
, info
.nrVirtCpu
);
54 virConnectClose(conn
);
57 int main(int argc
, char **argv
)
60 fprintf(stderr
, "syntax: %s: URI NAME\n", argv
[0]);
63 getDomainInfo(argv
[1], argv
[2]);