[!
use strict;
use PVE::pvecfg;
use PVE::I18N;
use PVE::ConfigServer;
use PVE::HTMLTable;
use PVE::Config;
use PVE::Cluster;
use PVE::HTMLForm;
use PVE::HTMLControls;
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 $html;
my $form = PVE::HTMLForm->new (\%fdat);
my $cinfo = $fdat{__cinfo};
my $veid = $fdat{veid};
my $cid = $fdat{cid};
if ($udat{action}) {
eval { check_write_mode ($udat{AM}); };
if ($@) {
$udat{popup_error} = $@;
} else {
my $conn = PVE::ConfigClient::connect ();
if ($udat{action} eq 'destroy') {
$conn->vmcommand_destroy ($cid, $veid, 'qemu', $udat{auth_username})->result;
$udat{redirect} = "/vmlist/index.htm";
return;
} elsif ($udat{action} eq 'shutdown') {
$conn->vmcommand_stop ($cid, $veid, 'qemu', $udat{auth_username}, 0)->result;
} elsif ($udat{action} eq 'stop') {
$conn->vmcommand_stop ($cid, $veid, 'qemu', $udat{auth_username}, 1)->result;
} elsif ($udat{action} eq 'start') {
$conn->vmcommand_start ($cid, $veid, 'qemu', $udat{auth_username})->result;
} elsif ($udat{action} eq 'restart') {
$conn->vmcommand_restart ($cid, $veid, 'qemu', $udat{auth_username})->result;
}
}
}
if ($fdat{confirmdestroy}) {
my $msg = PVE::HTMLUtils::msg ('confirm_remove');
$msg = sprintf ($msg, $veid);
my $href = "?action=destroy&cid=$cid&veid=$veid&type=qemu";
print OUT PVE::HTMLUtils::create_confirmframe ($msg, __("Remove"), $href, $fdat{__uri});
return;
}
if ($form->action eq 'save') {
my $conn = PVE::ConfigClient::connect ();
eval {
check_write_mode ($udat{AM});
check_field (__("Name"), $fdat{name}, 'NOTEMPTY', 'NOWHITESPACES');
check_range (__("CPUs"), $fdat{smp}, 1, 64);
my $settings = { name => $fdat{name},
memory => $fdat{mem},
onboot => $fdat{onboot},
ostype => $fdat{ostype},
boot => $fdat{bootorder},
smp => $fdat{smp},
bootdisk => $fdat{bootdisk},
description => PVE::HTMLUtils::encode_description ($fdat{notes}||''),
};
PVE::Cluster::check_vm_settings ($settings);
$conn->vmconfig_set ($udat{auth_username}, $cid, $veid, 'qemu', $settings)->result;
};
$udat{popup_error} = $@ if $@;
}
my $vminfo = PVE::Cluster::load_vmconfig ($cinfo, $cid, $veid, 'qemu');
my $status = $vminfo->{vzlist}->{"VEID_$veid"}->{status};
my $vmconf = $vminfo->{config};
my $ni = $vminfo->{ni};
my $onboot = ($vmconf->{onboot} eq 'yes' || $vmconf->{onboot} eq '1');
my $osl = PVE::QemuServer::os_list_description();
my $oslist = []; foreach my $os (sort keys %$osl) { push @$oslist, [ $os, $osl->{$os} ]; }
my $notes = PVE::HTMLUtils::decode_description ($vmconf->{description} || '');
$html = '';
$html .= html_table_line (__("Name") . ':',
$form->create_element ('name', 'text', defined ($fdat{name}) ? $fdat{name} : $vmconf->{name}),
"VMID:", PVE::HTMLForm::viewonly_element ($veid));
$html .= html_table_line (__("Guest Type") . ':',
$form->create_element ('ostype', 'dropdown', defined ($fdat{ostype}) ? $fdat{ostype} : ($vmconf->{ostype} || 'other'), $oslist),
__("Cluster Node") . ':',
PVE::HTMLForm::viewonly_element($ni->{name} . " (" . $ni->{ip} . ")"));
# $html .= html_table_line (__("Disk space") . ' (GB):',
# PVE::HTMLForm::viewonly_element (sprintf ("%0.2f", $vmconf->{disksize})),
# __("Disk type") . ':',
# PVE::HTMLForm::viewonly_element ($vmconf->{disktype}));
$html .= html_table_line (__("Memory") . ' (MB):',
$form->create_element ('mem', 'number', defined ($fdat{mem}) ? $fdat{mem} : $vmconf->{memory}),
__("CPUs") . ':',
$form->create_element ('smp', 'number',
defined ($fdat{smp}) ? $fdat{smp} : $vmconf->{smp} || 1));
$html .= html_table_line ('', '',
__("Start at boot") . ':',
$form->create_element ('onboot', 'bool',
defined ($fdat{onboot}) ? $fdat{onboot} : $onboot));
$html .= " ";
$fdat{notes} = $notes if !defined ($fdat{notes});
my $rows = 4;
my $rh = int ($rows*int(1.2*12+1));
$html .= " |
Notes: | |
";
$html .= '
';
$html .= "
";
$html .= $form->create_cmdbutton ('save');
$out .= $form->create_header();
$out .= PVE::HTMLUtils::create_statusframe (undef, "Configuration", undef, $html);
$out .= $form->create_footer();
$out .= "
\n";
$html = PVE::HTMLUtils::create_vmstatus ($cid, $veid, 'qemu', $vminfo);
$out .= PVE::HTMLUtils::create_statusframe ("vmstatus${cid}_$veid", "Status", undef, $html) . "
";
$out .= PVE::HTMLControls::create_wsviewer ("vmstatus${cid}_$veid", "vmstatus${cid}_${veid}right", '/ws/vmstatus', { cid => $cid , veid => $veid , type => 'qemu' }, 5);
print OUT $out;
-]