2 * dommigrate.c: This file is largely inspired from hellolibvirt and
3 * contains a trivial example that illustrate p2p domain
4 * migration with libvirt.
6 * Copyright (C) 2014 Cloudwatt
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see
20 * <http://www.gnu.org/licenses/>.
25 #include <libvirt/libvirt.h>
26 #include <libvirt/virterror.h>
30 usage(char *prgn
, int ret
)
32 printf("Usage: %s <src uri> <dst uri> <domain name>\n", prgn
);
37 main(int argc
, char *argv
[])
39 char *src_uri
, *dst_uri
, *domname
;
41 virConnectPtr conn
= NULL
;
42 virDomainPtr dom
= NULL
;
45 ret
= usage(argv
[0], 1);
53 printf("Attempting to connect to the source hypervisor...\n");
54 conn
= virConnectOpenAuth(src_uri
, virConnectAuthPtrDefault
, 0);
57 fprintf(stderr
, "No connection to the source hypervisor: %s.\n",
58 virGetLastErrorMessage());
62 printf("Attempting to retrieve domain %s...\n", domname
);
63 dom
= virDomainLookupByName(conn
, domname
);
65 fprintf(stderr
, "Failed to find domain %s.\n", domname
);
69 printf("Attempting to migrate %s to %s...\n", domname
, dst_uri
);
70 if ((ret
= virDomainMigrateToURI(dom
, dst_uri
,
71 VIR_MIGRATE_PEER2PEER
,
73 fprintf(stderr
, "Failed to migrate domain %s.\n", domname
);
77 printf("Migration finished with success.\n");
82 virConnectClose(conn
);