vm_start: collect and return migration info

in addition to printing it. preparation for remote cluster migration,
where we want to return this in a structured fashion over the migration
tunnel instead of parsing stdout via SSH.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-03-30 13:41:36 +02:00 committed by Thomas Lamprecht
parent ba5396b580
commit 84da82174e

View File

@ -4806,7 +4806,7 @@ sub vm_migrate_alloc_nbd_disks {
sub vm_start { sub vm_start {
my ($storecfg, $vmid, $params, $migrate_opts) = @_; my ($storecfg, $vmid, $params, $migrate_opts) = @_;
PVE::QemuConfig->lock_config($vmid, sub { return PVE::QemuConfig->lock_config($vmid, sub {
my $conf = PVE::QemuConfig->load_config($vmid, $migrate_opts->{migratedfrom}); my $conf = PVE::QemuConfig->load_config($vmid, $migrate_opts->{migratedfrom});
die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf); die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
@ -4828,7 +4828,7 @@ sub vm_start {
} }
} }
vm_start_nolock($storecfg, $vmid, $conf, $params, $migrate_opts); return vm_start_nolock($storecfg, $vmid, $conf, $params, $migrate_opts);
}); });
} }
@ -4857,6 +4857,8 @@ sub vm_start_nolock {
my $migratedfrom = $migrate_opts->{migratedfrom}; my $migratedfrom = $migrate_opts->{migratedfrom};
my $migration_type = $migrate_opts->{type}; my $migration_type = $migrate_opts->{type};
my $res = {};
# clean up leftover reboot request files # clean up leftover reboot request files
eval { clear_reboot_request($vmid); }; eval { clear_reboot_request($vmid); };
warn $@ if $@; warn $@ if $@;
@ -5065,6 +5067,7 @@ sub vm_start_nolock {
} }
print "migration listens on $migrate_uri\n" if $migrate_uri; print "migration listens on $migrate_uri\n" if $migrate_uri;
$res->{migrate_uri} = $migrate_uri;
if ($statefile && $statefile ne 'tcp' && $statefile ne 'unix') { if ($statefile && $statefile ne 'tcp' && $statefile ne 'unix') {
eval { mon_cmd($vmid, "cont"); }; eval { mon_cmd($vmid, "cont"); };
@ -5092,13 +5095,19 @@ sub vm_start_nolock {
$migrate_storage_uri = "nbd:${localip}:${storage_migrate_port}"; $migrate_storage_uri = "nbd:${localip}:${storage_migrate_port}";
} }
$res->{migrate_storage_uri} = $migrate_storage_uri;
foreach my $opt (sort keys %$nbd) { foreach my $opt (sort keys %$nbd) {
my $drivestr = $nbd->{$opt}->{drivestr}; my $drivestr = $nbd->{$opt}->{drivestr};
my $volid = $nbd->{$opt}->{volid}; my $volid = $nbd->{$opt}->{volid};
mon_cmd($vmid, "nbd-server-add", device => "drive-$opt", writable => JSON::true ); mon_cmd($vmid, "nbd-server-add", device => "drive-$opt", writable => JSON::true );
print "storage migration listens on $migrate_storage_uri:exportname=drive-$opt volume:$drivestr\n"; my $nbd_uri = "$migrate_storage_uri:exportname=drive-$opt";
print "storage migration listens on $nbd_uri volume:$drivestr\n";
print "re-using replicated volume: $opt - $volid\n" print "re-using replicated volume: $opt - $volid\n"
if $nbd->{$opt}->{replicated}; if $nbd->{$opt}->{replicated};
$res->{drives}->{$opt} = $nbd->{$opt};
$res->{drives}->{$opt}->{nbd_uri} = $nbd_uri;
} }
} }
@ -5110,6 +5119,7 @@ sub vm_start_nolock {
if ($spice_port) { if ($spice_port) {
print "spice listens on port $spice_port\n"; print "spice listens on port $spice_port\n";
$res->{spice_port} = $spice_port;
if ($migrate_opts->{spice_ticket}) { if ($migrate_opts->{spice_ticket}) {
mon_cmd($vmid, "set_password", protocol => 'spice', password => $migrate_opts->{spice_ticket}); mon_cmd($vmid, "set_password", protocol => 'spice', password => $migrate_opts->{spice_ticket});
mon_cmd($vmid, "expire_password", protocol => 'spice', time => "+30"); mon_cmd($vmid, "expire_password", protocol => 'spice', time => "+30");
@ -5143,6 +5153,8 @@ sub vm_start_nolock {
} }
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start'); PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
return $res;
} }
sub vm_commandline { sub vm_commandline {