summaryrefslogtreecommitdiffstats
path: root/examples/node_info.ml
blob: c52615e50588d918d924af9ef49cbaef54aeb493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* Simple demo program showing node info.
   Usage: node_info [URI]
   (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
   http://libvirt.org/
 *)

open Printf

module C = Libvirt.Connect

let () =
  try
    let name =
      if Array.length Sys.argv >= 2 then
	Some (Sys.argv.(1))
      else
	None in
    let conn = C.connect_readonly ?name () in

    (* Get node_info, hostname, etc. *)
    let node_info = C.get_node_info conn in

    printf "model = %s\n" node_info.C.model;
    printf "memory = %Ld K\n" node_info.C.memory;
    printf "cpus = %d\n" node_info.C.cpus;
    printf "mhz = %d\n" node_info.C.mhz;
    printf "nodes = %d\n" node_info.C.nodes;
    printf "sockets = %d\n" node_info.C.sockets;
    printf "cores = %d\n" node_info.C.cores;
    printf "threads = %d\n%!" node_info.C.threads;

    let hostname = C.get_hostname conn in

    printf "hostname = %s\n%!" hostname;

    let uri = C.get_uri conn in

    printf "uri = %s\n%!" uri

  with
    Libvirt.Virterror err ->
      eprintf "error: %s\n" (Libvirt.Virterror.to_string err)

let () =
  (* Run the garbage collector which is a good way to check for
   * memory corruption errors and reference counting issues in libvirt.
   *)
  Gc.compact ()