diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2008-01-08 13:26:23 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2008-01-08 13:26:23 +0000 |
commit | 9b4bab1fe618affd0e69666ec6467b414cee325e (patch) | |
tree | ff0334a53631096c82f1fe234c1c1775bc63adc9 /examples | |
parent | 4c5a6c02d72a5c40102b6c26705574f84c89eb20 (diff) | |
download | virt-top-9b4bab1fe618affd0e69666ec6467b414cee325e.tar.gz virt-top-9b4bab1fe618affd0e69666ec6467b414cee325e.tar.xz virt-top-9b4bab1fe618affd0e69666ec6467b414cee325e.zip |
Move programming information to libvirt generated doc.
* README, libvirt/libvirt.mli: Moved programming information to
libvirt generated documentation, greatly expanded examples and
other issues.
* examples/Makefile.in, examples/node_info.ml, examples/.depend:
Added node_info example program.
* .hgignore, Makefile.in: Ignore, clean up node_info binary.
* examples/list_domains.ml: Make a read-only connection.
Diffstat (limited to 'examples')
-rw-r--r--[-rwxr-xr-x] | examples/.depend | 2 | ||||
-rw-r--r-- | examples/Makefile.in | 24 | ||||
-rw-r--r--[-rwxr-xr-x] | examples/list_domains.ml | 2 | ||||
-rw-r--r-- | examples/node_info.ml | 48 |
4 files changed, 73 insertions, 3 deletions
diff --git a/examples/.depend b/examples/.depend index bc5cec2..334ba5d 100755..100644 --- a/examples/.depend +++ b/examples/.depend @@ -1,2 +1,4 @@ list_domains.cmo: ../libvirt/libvirt.cmi list_domains.cmx: ../libvirt/libvirt.cmx +node_info.cmo: ../libvirt/libvirt.cmi +node_info.cmx: ../libvirt/libvirt.cmx diff --git a/examples/Makefile.in b/examples/Makefile.in index 0f0c527..75a98eb 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -36,8 +36,8 @@ endif export LIBRARY_PATH=../libvirt export LD_LIBRARY_PATH=../libvirt -BYTE_TARGETS := list_domains -OPT_TARGETS := list_domains.opt +BYTE_TARGETS := list_domains node_info +OPT_TARGETS := list_domains.opt node_info.opt all: $(BYTE_TARGETS) @@ -53,6 +53,16 @@ list_domains.opt: list_domains.cmx $(OCAMLFIND) ocamlopt \ $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ ../libvirt/mllibvirt.cmxa -o $@ $< + +node_info: node_info.cmo + $(OCAMLFIND) ocamlc \ + $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) \ + ../libvirt/mllibvirt.cma -o $@ $< + +node_info.opt: node_info.cmx + $(OCAMLFIND) ocamlopt \ + $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ + ../libvirt/mllibvirt.cmxa -o $@ $< else list_domains: list_domains.cmo $(OCAMLC) \ @@ -63,6 +73,16 @@ list_domains.opt: list_domains.cmx $(OCAMLOPT) \ $(OCAMLOPTINCS) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ ../libvirt/mllibvirt.cmxa -o $@ $< + +node_info: node_info.cmo + $(OCAMLC) \ + $(OCAMLCINCS) $(OCAMLCFLAGS) $(OCAMLCLIBS) \ + ../libvirt/mllibvirt.cma -o $@ $< + +node_info.opt: node_info.cmx + $(OCAMLOPT) \ + $(OCAMLOPTINCS) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ + ../libvirt/mllibvirt.cmxa -o $@ $< endif install: diff --git a/examples/list_domains.ml b/examples/list_domains.ml index 9451ab2..c97432c 100755..100644 --- a/examples/list_domains.ml +++ b/examples/list_domains.ml @@ -17,7 +17,7 @@ let () = Some (Sys.argv.(1)) else None in - let conn = C.connect ?name () in + let conn = C.connect_readonly ?name () in (* List running domains. *) let n = C.num_of_domains conn in diff --git a/examples/node_info.ml b/examples/node_info.ml new file mode 100644 index 0000000..c52615e --- /dev/null +++ b/examples/node_info.ml @@ -0,0 +1,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 () |