forked from djamps/migrate-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigratevm.pl
executable file
·45 lines (39 loc) · 1.49 KB
/
migratevm.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
use File::Basename qw( dirname );
use lib dirname(__FILE__).'/lib';
use Xen::API;
use Data::Dumper;
use Getopt::Long;
## Setup command line options
my $opt = {};
GetOptions ( $opt,
"configfile=s",
"shost=s",
"suser=s",
"spass=s",
"svm=s",
"dhost=s",
"duser=s",
"dpass=s",
"dsr=s",
"ssl",
"debug!",
);
my $version = "1.2.0";
print "migratevm $version started\n";
## Set up vars
my $shost = $opt->{'shost'} || Xen::API::input("Enter source host name/IP (blank = localhost): ") || 'localhost';
my $suser = $opt->{'suser'} || Xen::API::input("Enter username for ".$shost." (blank = root): ") || 'root';
my $spass = $opt->{'spass'} || Xen::API::password("Enter password for ".$shost.": ");
my $svm = $opt->{'svm'} || Xen::API::input("Enter source vm name or uuid on $shost: ");
my $dhost = $opt->{'dhost'} || Xen::API::input("Enter destination host name/IP (blank = localhost): ") || 'localhost';
my $duser = $opt->{'duser'} || Xen::API::input("Enter username for ".$dhost." (blank = root): ") || 'root';
my $dpass = $opt->{'dpass'} || Xen::API::password("Enter password for ".$dhost.": ");
my $dsr = exists($opt->{'dsr'})?$opt->{'dsr'}:Xen::API::input("Destination SR on ".$dhost." (blank for default): ");
## Create Xen::API object on source host
print "Connecting to source host\n";
my $x = Xen::API->new($shost,$suser,$spass) || die $!;
## Do the transfer
print "Connecting to destination host and Starting transfer\n";
$x->transfer_vm($svm,$opt->{'ssl'},$dhost,$duser,$dpass,$dsr);
exit;