[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [EXAMPLE PATCH 15/15] Example virt-admin



You had only one job.  That's what you can say about this example
binary.  In future, parts of virsh that are usable for this binary
should be split into separate shell-utils and virt-admin should gain all
the cool features of virsh without too much code addition.

Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 .gitignore                      |  2 ++
 Makefile.am                     |  4 +--
 configure.ac                    |  7 ++++-
 libvirt.spec.in                 |  2 ++
 tools/virt-admin/Makefile.am    | 70 +++++++++++++++++++++++++++++++++++++++++
 tools/virt-admin/virt-admin.c   | 68 +++++++++++++++++++++++++++++++++++++++
 tools/virt-admin/virt-admin.pod | 43 +++++++++++++++++++++++++
 7 files changed, 193 insertions(+), 3 deletions(-)
 create mode 100644 tools/virt-admin/Makefile.am
 create mode 100644 tools/virt-admin/virt-admin.c
 create mode 100644 tools/virt-admin/virt-admin.pod

diff --git a/.gitignore b/.gitignore
index d299063..d6964f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -173,6 +173,8 @@
 /tools/virsh-*-edit.c
 /tools/virt-*-validate
 /tools/virt-sanlock-cleanup
+/tools/virt-admin/virt-admin.1
+/tools/virt-admin/virt-admin
 /tools/wireshark/src/plugin.c
 /tools/wireshark/src/libvirt
 /update.log
diff --git a/Makefile.am b/Makefile.am
index 4aafe94..cdae769 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in

-## Copyright (C) 2005-2013 Red Hat, Inc.
+## Copyright (C) 2005-2015 Red Hat, Inc.
 ##
 ## This library is free software; you can redistribute it and/or
 ## modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,7 @@ SUBDIRS = . gnulib/lib include src daemon tools docs gnulib/tests \
   examples/dominfo examples/domsuspend examples/apparmor \
   examples/xml/nwfilter examples/openauth examples/systemtap \
   tools/wireshark examples/dommigrate \
-  examples/lxcconvert examples/domtop
+  examples/lxcconvert examples/domtop tools/virt-admin

 ACLOCAL_AMFLAGS = -I m4

diff --git a/configure.ac b/configure.ac
index d13f825..aa0cc4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1694,6 +1694,10 @@ dnl virsh libraries
 VIRSH_LIBS="$VIRSH_LIBS $READLINE_LIBS"
 AC_SUBST([VIRSH_LIBS])

+dnl virt-admin libraries
+VIRT_ADMIN_LIBS="$VIRT_ADMIN_LIBS $READLINE_LIBS"
+AC_SUBST([VIRT_ADMIN_LIBS])
+
 dnl check if the network driver should be compiled

 AC_ARG_WITH([network],
@@ -2825,7 +2829,8 @@ AC_CONFIG_FILES([\
         examples/xml/nwfilter/Makefile \
         examples/lxcconvert/Makefile \
         tools/wireshark/Makefile \
-        tools/wireshark/src/Makefile])
+        tools/wireshark/src/Makefile \
+        tools/virt-admin/Makefile])
 AC_OUTPUT

 AC_MSG_NOTICE([])
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 7c13588..7cfd358 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -2181,6 +2181,8 @@ exit 0
 %if %{with_admin}
 %files admin
 %defattr(-, root, root)
+%{_mandir}/man1/virt-admin.1*
+%{_bindir}/virt-admin
 %{_libdir}/%{name}/libvirt_admin.so
 %endif

diff --git a/tools/virt-admin/Makefile.am b/tools/virt-admin/Makefile.am
new file mode 100644
index 0000000..47c9646
--- /dev/null
+++ b/tools/virt-admin/Makefile.am
@@ -0,0 +1,70 @@
+## Copyright (C) 2015 Red Hat, Inc.
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+AM_CPPFLAGS = \
+	-I$(top_builddir)/include -I$(top_srcdir)/include	\
+	-I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib	\
+	-I$(top_builddir)/src -I$(top_srcdir)/src		\
+	-I$(top_srcdir)/src/util				\
+	-I$(top_srcdir)						\
+	$(GETTEXT_CPPFLAGS)
+
+AM_LDFLAGS = \
+	$(RELRO_LDFLAGS)					\
+	$(NO_INDIRECT_LDFLAGS)					\
+	$(NULL)
+
+POD2MAN = pod2man -c "Virtualization Support" -r "$(PACKAGE)-$(VERSION)"
+
+EXTRA_DIST = virt-admin.pod
+
+DISTCLEANFILES =
+
+bin_PROGRAMS = virt-admin
+
+dist_man1_MANS = virt-admin.1
+
+virt_admin_SOURCES = virt-admin.c
+
+virt_admin_LDFLAGS = \
+		$(AM_LDFLAGS) 					\
+		$(COVERAGE_LDFLAGS)				\
+		$(NULL)
+
+virt_admin_LDADD =						\
+		$(STATIC_BINARIES)				\
+		$(PIE_LDFLAGS)					\
+		../../src/libvirt.la				\
+		../../src/libvirt-admin.la			\
+		$(top_srcdir)/gnulib/lib/libgnu.la		\
+		$(VIRT_ADMIN_LIBS)				\
+		$(NULL)
+
+virt_admin_CFLAGS =						\
+		$(WARN_CFLAGS)					\
+		$(PIE_CFLAGS)					\
+		$(COVERAGE_CFLAGS)				\
+		$(LIBXML_CFLAGS)				\
+		$(READLINE_CFLAGS)				\
+		$(NULL)
+
+virt-admin.1: virt-admin.pod $(top_srcdir)/configure.ac
+	$(AM_V_GEN)$(POD2MAN) $< $(srcdir)/$@ \
+	    && if grep 'POD ERROR' $(srcdir)/$@ ; then \
+		rm $(srcdir)/$@; exit 1; fi
+
+CLEANFILES = *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda
+MAINTAINERCLEANFILES = $(dist_man1_MANS)
diff --git a/tools/virt-admin/virt-admin.c b/tools/virt-admin/virt-admin.c
new file mode 100644
index 0000000..2e67882
--- /dev/null
+++ b/tools/virt-admin/virt-admin.c
@@ -0,0 +1,68 @@
+/*
+ * virt-admin.c: a shell to exercise the libvirt admin API
+ *
+ * Copyright (C) 2014-2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Martin Kletzander <mkletzan redhat com>
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+
+#include "configmake.h"
+#include "internal.h"
+
+#include <viralloc.h>
+
+int
+main(int argc ATTRIBUTE_UNUSED,
+     char **argv ATTRIBUTE_UNUSED)
+{
+    int ret = EXIT_FAILURE;
+    char *greeting = NULL;
+    virAdmConnectPtr conn = NULL;
+
+    if (!setlocale(LC_ALL, "")) {
+        perror("setlocale");
+        /* failure to setup locale is not fatal */
+    }
+    if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
+        perror("bindtextdomain");
+        return EXIT_FAILURE;
+    }
+    if (!textdomain(PACKAGE)) {
+        perror("textdomain");
+        return EXIT_FAILURE;
+    }
+
+    if (!(conn = virAdmConnectOpen(0)))
+        goto cleanup;
+
+    if (!(greeting = virAdmHello(conn, 0)))
+        goto cleanup;
+
+    printf("%s\n", greeting);
+
+    ret = EXIT_SUCCESS;
+ cleanup:
+    VIR_FREE(greeting);
+    virAdmConnectClose(conn);
+    return ret;
+}
diff --git a/tools/virt-admin/virt-admin.pod b/tools/virt-admin/virt-admin.pod
new file mode 100644
index 0000000..b82013b
--- /dev/null
+++ b/tools/virt-admin/virt-admin.pod
@@ -0,0 +1,43 @@
+=head1 NAME
+
+virt-admin - client for admin interface of libvirt
+
+=head1 SYNOPSIS
+
+B<virt-admin>
+
+=head1 DESCRIPTION
+
+Libre ip_sum do { lor(); } sit; I'm @.
+
+=head1 EXIT STATUS
+
+It should be 0, really.
+
+=head1 BUGS
+
+None!
+
+=head1 AUTHORS
+
+  Please refer to the AUTHORS file distributed with libvirt.
+
+  Martin Kletzander <mkletzan redhat com>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2014-2015 Red Hat, Inc., and the authors listed in the
+libvirt AUTHORS file.
+
+=head1 LICENSE
+
+virt-admin is distributed under the terms of the GNU GPL v2+.  This is
+free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE
+
+=head1 SEE ALSO
+
+L<virsh(1)>, L<http://www.libvirt.org/>
+
+=cut
--
2.3.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]