summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorrjones@localhost <rjones@localhost>2007-08-30 17:38:09 +0100
committerrjones@localhost <rjones@localhost>2007-08-30 17:38:09 +0100
commita8b837d5018c488a130fcbea425904817a862210 (patch)
tree44fc8f4a58d6e1651053c4c40d32b3816add43fa /examples
downloadvirt-top-a8b837d5018c488a130fcbea425904817a862210.tar.gz
virt-top-a8b837d5018c488a130fcbea425904817a862210.tar.xz
virt-top-a8b837d5018c488a130fcbea425904817a862210.zip
Initial import from CVS.
Diffstat (limited to 'examples')
-rw-r--r--examples/.cvsignore8
-rw-r--r--examples/.depend2
-rw-r--r--examples/Makefile32
-rw-r--r--examples/Makefile.in32
-rw-r--r--examples/list_domains.ml47
5 files changed, 121 insertions, 0 deletions
diff --git a/examples/.cvsignore b/examples/.cvsignore
new file mode 100644
index 0000000..1353c69
--- /dev/null
+++ b/examples/.cvsignore
@@ -0,0 +1,8 @@
+*.cmi
+*.cmo
+*.cmx
+*.cma
+*.cmxa
+Makefile
+list_domains
+list_domains.opt \ No newline at end of file
diff --git a/examples/.depend b/examples/.depend
new file mode 100644
index 0000000..bc5cec2
--- /dev/null
+++ b/examples/.depend
@@ -0,0 +1,2 @@
+list_domains.cmo: ../libvirt/libvirt.cmi
+list_domains.cmx: ../libvirt/libvirt.cmx
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..4692e36
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,32 @@
+# $Id: Makefile.in,v 1.1 2007/08/21 12:33:40 rjones Exp $
+
+OCAMLCPACKAGES := -package extlib,unix -I ../libvirt
+OCAMLCFLAGS := -g
+OCAMLCLIBS := -linkpkg
+
+OCAMLOPTPACKAGES := $(OCAMLCPACKAGES)
+OCAMLOPTFLAGS :=
+OCAMLOPTLIBS := $(OCAMLCLIBS)
+
+export LIBRARY_PATH=../libvirt
+export LD_LIBRARY_PATH=../libvirt
+
+BYTE_TARGETS := list_domains
+OPT_TARGETS := list_domains.opt
+
+all: $(BYTE_TARGETS)
+
+opt: $(OPT_TARGETS)
+
+list_domains: list_domains.cmo
+ ocamlfind ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) \
+ ../libvirt/mllibvirt.cma -o $@ $<
+
+list_domains.opt: list_domains.cmx
+ ocamlfind ocamlopt \
+ $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \
+ ../libvirt/mllibvirt.cmxa -o $@ $<
+
+install:
+
+include ../Make.rules
diff --git a/examples/Makefile.in b/examples/Makefile.in
new file mode 100644
index 0000000..4692e36
--- /dev/null
+++ b/examples/Makefile.in
@@ -0,0 +1,32 @@
+# $Id: Makefile.in,v 1.1 2007/08/21 12:33:40 rjones Exp $
+
+OCAMLCPACKAGES := -package extlib,unix -I ../libvirt
+OCAMLCFLAGS := -g
+OCAMLCLIBS := -linkpkg
+
+OCAMLOPTPACKAGES := $(OCAMLCPACKAGES)
+OCAMLOPTFLAGS :=
+OCAMLOPTLIBS := $(OCAMLCLIBS)
+
+export LIBRARY_PATH=../libvirt
+export LD_LIBRARY_PATH=../libvirt
+
+BYTE_TARGETS := list_domains
+OPT_TARGETS := list_domains.opt
+
+all: $(BYTE_TARGETS)
+
+opt: $(OPT_TARGETS)
+
+list_domains: list_domains.cmo
+ ocamlfind ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) \
+ ../libvirt/mllibvirt.cma -o $@ $<
+
+list_domains.opt: list_domains.cmx
+ ocamlfind ocamlopt \
+ $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \
+ ../libvirt/mllibvirt.cmxa -o $@ $<
+
+install:
+
+include ../Make.rules
diff --git a/examples/list_domains.ml b/examples/list_domains.ml
new file mode 100644
index 0000000..f752754
--- /dev/null
+++ b/examples/list_domains.ml
@@ -0,0 +1,47 @@
+(* Simple demo program showing how to list out domains.
+ Usage: list_domains [URI]
+ (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
+ http://libvirt.org/
+ $Id: list_domains.ml,v 1.1 2007/08/06 10:16:53 rjones Exp $
+ *)
+
+open Printf
+
+module C = Libvirt.Connect
+module D = Libvirt.Domain
+module N = Libvirt.Network
+
+let () =
+ try
+ let name =
+ if Array.length Sys.argv >= 2 then
+ Some (Sys.argv.(1))
+ else
+ None in
+ let conn = C.connect ?name () in
+
+ (* List running domains. *)
+ let n = C.num_of_domains conn in
+ let ids = C.list_domains conn n in
+ let domains = Array.map (D.lookup_by_id conn) ids in
+ Array.iter (
+ fun dom ->
+ printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
+ ) domains;
+
+ (* List inactive domains. *)
+ let n = C.num_of_defined_domains conn in
+ let names = C.list_defined_domains conn n in
+ Array.iter (
+ fun name ->
+ printf "inactive %s\n%!" name
+ ) names;
+ 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 ()