[!
use strict;
use PVE::pvecfg;
use PVE::I18N;
use PVE::ConfigServer;
use PVE::Cluster;
use PVE::HTMLForm;
use PVE::HTMLUtils;
!]
[-
use strict;
sub html_table_line {
my ($v1, $v2, $v3, $v4) = @_;
$v1 = " " if !$v1;
$v2 = " " if !$v2;
$v3 = " " if !$v3;
$v4 = " " if !$v4;
my $html = '
';
$html .= "$v1 | $v2 | ";
$html .= " | $v3 | $v4 |
\n";
return $html;
}
my $out = '';
my $form = PVE::HTMLForm->new (\%fdat);
my $cinfo = $fdat{__cinfo};
my $cidlist = [];
foreach my $ni (@{$cinfo->{nodes}}) {
push @$cidlist, [$ni->{cid}, "$ni->{name} ($ni->{ip})"];
}
if (scalar (@$cidlist) <= 1) {
$out .= __("Only one cluster node defined - no migration possible.");
print OUT $out;
return;
}
$fdat{cid} = $cinfo->{local}->{cid} if !defined ($fdat{cid});
my $cidlist2 = [];
foreach my $ni (@{$cinfo->{nodes}}) {
push @$cidlist2, [$ni->{cid}, "$ni->{name} ($ni->{ip})"] if $ni->{cid} ne $fdat{cid};
}
my $conn = PVE::ConfigClient::connect ();
my $vzlist = $conn->cluster_vzlist()->result;
if ($form->action eq 'migrate') {
my $trackid;
eval {
check_write_mode ($udat{AM});
die __("Please select a VM") . "\n" if !$fdat{veid} || $fdat{veid} eq '-';
die __("Please select a target node") . "\n" if !defined ($fdat{targetcid});
my $vzl = $vzlist->{"CID_$fdat{cid}"} ||
die "undefined cluster node '$fdat{cid}'\n";
my $d = $vzl->{"VEID_$fdat{veid}"} ||
die "undefined virtual machine VM $fdat{veid}\n";
$trackid = $conn->vmcommand_migrate ($udat{auth_username}, $fdat{cid},
$fdat{veid}, $d->{type}, $fdat{targetcid},
$fdat{online})->result;
};
if ($@) {
$udat{popup_error} = $@;
} else {
print OUT PVE::HTMLUtils::create_vmops_frame ($fdat{veid}, $trackid);
return;
}
}
$out .= $form->create_header();
my $srclist = [['-', __("Please select a VM") ]];
my $vzl = $vzlist->{"CID_$fdat{cid}"};
foreach my $vkey (sort keys %$vzl) {
next if $vkey !~ m/^VEID_(\d+)$/;
my $veid = $1;
my $d = $vzl->{$vkey};
push @$srclist, [$veid, "VM $veid ($d->{name})"];
}
my $html = '';
$html .= html_table_line (__("Source Node") . ':',
$form->create_element ('cid', 'dynamicdropdown',
$fdat{cid}, $cidlist),
"VMID:",
$form->create_element ('veid', 'dropdown', $fdat{veid}, $srclist));
$html .= html_table_line (__("Target Node") . ':',
$form->create_element ('targetcid', 'dropdown', $fdat{targetcid},
$cidlist2),
__("Online migration"),
$form->create_element ('online', 'bool', $fdat{online}));
$html .= "
";
$html .= "
" . $form->create_cmdbutton ('migrate');
$out .= PVE::HTMLUtils::create_statusframe (undef, __("Define migration task"), undef, $html);
$out .= $form->create_footer();
print OUT $out;
-]