]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add example that renames domain there and back
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 27 Aug 2015 10:55:52 +0000 (12:55 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 4 Sep 2015 16:55:01 +0000 (18:55 +0200)
And in the middle it prints out its name to demonstrate changes in later
patch(es).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
.gitignore
configure.ac
examples/rename/Makefile.am [new file with mode: 0644]
examples/rename/rename.c [new file with mode: 0644]

index 6bd41be9db89bac87d87bd649e0b94ef0abc9e1f..19402f5b8cd2585967db26d6a0373b756b7ed252 100644 (file)
@@ -83,6 +83,7 @@
 /examples/domtop/domtop
 /examples/hellolibvirt/hellolibvirt
 /examples/openauth/openauth
+/examples/rename/test
 /gnulib/lib/*
 /gnulib/m4/*
 /gnulib/tests/*
index 136c2e73b8dfc0f1403ccce9e53a76c77ca19882..ef7fbdbed32ce0e8853f8741dbf67bce240c5051 100644 (file)
@@ -2806,6 +2806,7 @@ AC_CONFIG_FILES([\
         examples/domtop/Makefile \
         examples/openauth/Makefile \
         examples/hellolibvirt/Makefile \
+        examples/rename/Makefile \
         examples/systemtap/Makefile \
         examples/xml/nwfilter/Makefile \
         examples/lxcconvert/Makefile \
diff --git a/examples/rename/Makefile.am b/examples/rename/Makefile.am
new file mode 100644 (file)
index 0000000..1b3484c
--- /dev/null
@@ -0,0 +1,24 @@
+## Copyright (C) 2005-2013 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/>.
+
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
+LDADDS = $(STATIC_BINARIES) $(WARN_CFLAGS) $(top_builddir)/src/libvirt.la \
+       $(COVERAGE_LDFLAGS)
+
+noinst_PROGRAMS=rename
+
+rename_SOURCES=rename.c
+rename_LDADD= $(LDADDS)
diff --git a/examples/rename/rename.c b/examples/rename/rename.c
new file mode 100644 (file)
index 0000000..85f18e9
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * rename.c
+ *
+ * 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/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libvirt/libvirt.h>
+
+int main(int argc, char **argv)
+{
+    virConnectPtr conn = NULL; /* the hypervisor connection */
+    virDomainPtr dom = NULL;   /* the domain being checked */
+    int ret = EXIT_FAILURE;
+
+    if (argc != 3) {
+        fprintf(stderr, "Usage: %s <current_domname> <temporary_domname>\n",
+                argv[0]);
+        goto error;
+    }
+
+    conn = virConnectOpen(NULL);
+    if (conn == NULL) {
+        fprintf(stderr, "Failed to connect to hypervisor\n");
+        goto error;
+    }
+
+    dom = virDomainLookupByName(conn, argv[1]);
+    if (dom == NULL) {
+        fprintf(stderr, "Failed to find domain\n");
+        goto error;
+    }
+
+    printf("Before first rename: %s\n", virDomainGetName(dom));
+
+    /* Get the information */
+    ret = virDomainRename(dom, argv[2], 0);
+    if (ret < 0) {
+        fprintf(stderr, "Failed to rename domain\n");
+        goto error;
+    }
+
+    printf("After first rename: %s\n", virDomainGetName(dom));
+
+    /* Get the information */
+    ret = virDomainRename(dom, argv[1], 0);
+    if (ret < 0) {
+        fprintf(stderr, "Failed to rename domain\n");
+        goto error;
+    }
+
+    printf("After second rename: %s\n", virDomainGetName(dom));
+
+ error:
+    if (dom != NULL)
+        virDomainFree(dom);
+    if (conn != NULL)
+        virConnectClose(conn);
+    return ret;
+}