mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Add a new example to illustrate domain migration
This commit adds a new example to illustrate peer to peer domain migration with virDomainMigrateToURI. Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
This commit is contained in:
parent
f393c4603a
commit
b21795bb5b
1
.gitignore
vendored
1
.gitignore
vendored
@ -74,6 +74,7 @@
|
|||||||
/examples/object-events/event-test
|
/examples/object-events/event-test
|
||||||
/examples/dominfo/info1
|
/examples/dominfo/info1
|
||||||
/examples/domsuspend/suspend
|
/examples/domsuspend/suspend
|
||||||
|
/examples/dommigrate/dommigrate
|
||||||
/examples/hellolibvirt/hellolibvirt
|
/examples/hellolibvirt/hellolibvirt
|
||||||
/examples/openauth/openauth
|
/examples/openauth/openauth
|
||||||
/gnulib/lib/*
|
/gnulib/lib/*
|
||||||
|
@ -23,7 +23,7 @@ SUBDIRS = . gnulib/lib include src daemon tools docs gnulib/tests \
|
|||||||
tests po examples/object-events examples/hellolibvirt \
|
tests po examples/object-events examples/hellolibvirt \
|
||||||
examples/dominfo examples/domsuspend examples/apparmor \
|
examples/dominfo examples/domsuspend examples/apparmor \
|
||||||
examples/xml/nwfilter examples/openauth examples/systemtap \
|
examples/xml/nwfilter examples/openauth examples/systemtap \
|
||||||
tools/wireshark
|
tools/wireshark examples/dommigrate
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
@ -2730,6 +2730,7 @@ AC_CONFIG_FILES([\
|
|||||||
examples/object-events/Makefile \
|
examples/object-events/Makefile \
|
||||||
examples/domsuspend/Makefile \
|
examples/domsuspend/Makefile \
|
||||||
examples/dominfo/Makefile \
|
examples/dominfo/Makefile \
|
||||||
|
examples/dommigrate/Makefile \
|
||||||
examples/openauth/Makefile \
|
examples/openauth/Makefile \
|
||||||
examples/hellolibvirt/Makefile \
|
examples/hellolibvirt/Makefile \
|
||||||
examples/systemtap/Makefile \
|
examples/systemtap/Makefile \
|
||||||
|
5
examples/dommigrate/Makefile.am
Normal file
5
examples/dommigrate/Makefile.am
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)
|
||||||
|
noinst_PROGRAMS = dommigrate
|
||||||
|
dommigrate_CFLAGS = $(WARN_CFLAGS)
|
||||||
|
dommigrate_SOURCES = dommigrate.c
|
||||||
|
dommigrate_LDADD = $(top_builddir)/src/libvirt.la
|
89
examples/dommigrate/dommigrate.c
Normal file
89
examples/dommigrate/dommigrate.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* dommigrate.c: This file is largely inspired from hellolibvirt and
|
||||||
|
* contains a trivial example that illustrate p2p domain
|
||||||
|
* migration with libvirt.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014 Cloudwatt
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libvirt/libvirt.h>
|
||||||
|
#include <libvirt/virterror.h>
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
usage(char *prgn, int ret)
|
||||||
|
{
|
||||||
|
printf("Usage: %s <src uri> <dst uri> <domain name>\n", prgn);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *src_uri, *dst_uri, *domname;
|
||||||
|
int ret = 0;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
|
if (argc < 4) {
|
||||||
|
ret = usage(argv[0], 1);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
src_uri = argv[1];
|
||||||
|
dst_uri = argv[2];
|
||||||
|
domname = argv[3];
|
||||||
|
|
||||||
|
printf("Attempting to connect to the source hypervisor...\n");
|
||||||
|
conn = virConnectOpenAuth(src_uri, virConnectAuthPtrDefault, 0);
|
||||||
|
if (!conn) {
|
||||||
|
ret = 1;
|
||||||
|
fprintf(stderr, "No connection to the source hypervisor: %s.\n",
|
||||||
|
virGetLastErrorMessage());
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Attempting to retrieve domain %s...\n", domname);
|
||||||
|
dom = virDomainLookupByName(conn, domname);
|
||||||
|
if (!dom) {
|
||||||
|
fprintf(stderr, "Failed to find domain %s.\n", domname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Attempting to migrate %s to %s...\n", domname, dst_uri);
|
||||||
|
if ((ret = virDomainMigrateToURI(dom, dst_uri,
|
||||||
|
VIR_MIGRATE_PEER2PEER,
|
||||||
|
NULL, 0)) != 0) {
|
||||||
|
fprintf(stderr, "Failed to migrate domain %s.\n", domname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Migration finished with success.\n");
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (dom != NULL)
|
||||||
|
virDomainFree(dom);
|
||||||
|
if (conn != NULL)
|
||||||
|
virConnectClose(conn);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
@ -1498,7 +1498,7 @@ rm -fr %{buildroot}
|
|||||||
# on RHEL 5, thus we need to expand it here.
|
# on RHEL 5, thus we need to expand it here.
|
||||||
make install DESTDIR=%{?buildroot} SYSTEMD_UNIT_DIR=%{_unitdir}
|
make install DESTDIR=%{?buildroot} SYSTEMD_UNIT_DIR=%{_unitdir}
|
||||||
|
|
||||||
for i in object-events dominfo domsuspend hellolibvirt openauth xml/nwfilter systemtap
|
for i in object-events dominfo domsuspend hellolibvirt openauth xml/nwfilter systemtap dommigrate
|
||||||
do
|
do
|
||||||
(cd examples/$i ; make clean ; rm -rf .deps .libs Makefile Makefile.in)
|
(cd examples/$i ; make clean ; rm -rf .deps .libs Makefile Makefile.in)
|
||||||
done
|
done
|
||||||
@ -2222,6 +2222,7 @@ exit 0
|
|||||||
%doc examples/object-events
|
%doc examples/object-events
|
||||||
%doc examples/dominfo
|
%doc examples/dominfo
|
||||||
%doc examples/domsuspend
|
%doc examples/domsuspend
|
||||||
|
%doc examples/dommigrate
|
||||||
%doc examples/openauth
|
%doc examples/openauth
|
||||||
%doc examples/xml
|
%doc examples/xml
|
||||||
%doc examples/systemtap
|
%doc examples/systemtap
|
||||||
|
Loading…
Reference in New Issue
Block a user