[! 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::Utils; use PVE::HTMLUtils; use PVE::HTMLGrid; !] [- use strict; my $out = ''; 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 ($udat{auth_cookie}); if ($udat{action} eq 'destroy') { $conn->vmcommand_destroy ($cid, $veid, 'qemu')->result; $udat{redirect} = "/vmlist/index.htm"; return; } elsif ($udat{action} eq 'shutdown') { $conn->vmcommand_stop ($cid, $veid, 'qemu', 0)->result; } elsif ($udat{action} eq 'stop') { $conn->vmcommand_stop ($cid, $veid, 'qemu', 1)->result; } elsif ($udat{action} eq 'start') { $conn->vmcommand_start ($cid, $veid, 'qemu')->result; } elsif ($udat{action} eq 'restart') { $conn->vmcommand_restart ($cid, $veid, 'qemu')->result; } } } if ($fdat{confirmdestroy}) { my $msg = PVE::HTMLUtils::msg ('confirm_remove'); $msg = sprintf ($msg, $veid); my $ptoken = PVE::Utils::get_page_token(); my $href = "?action=destroy&cid=$cid&veid=$veid&type=qemu&ptoken=$ptoken"; print OUT PVE::HTMLUtils::create_confirmframe ($msg, __("Remove"), $href, $fdat{__uri}); return; } if ($form->action eq 'save') { my $conn = PVE::ConfigClient::connect ($udat{auth_cookie}); eval { check_write_mode ($udat{AM}); my $maxcpus = 16; check_field (__("Name"), $fdat{name}, 'NOTEMPTY', 'NOWHITESPACES'); check_range (__("CPU Sockets"), $fdat{sockets}, 1, $maxcpus); check_range (__("Cores/Socket"), $fdat{cores}, 1, $maxcpus); my $cpus = $fdat{sockets}*$fdat{cores}; if ($cpus > $maxcpus) { die __("To manny CPUs (Cores * Sockets > $maxcpus)") . "\n"; } my $settings = { name => $fdat{name}, memory => $fdat{mem}, onboot => $fdat{onboot}, ostype => $fdat{ostype}, boot => $fdat{bootorder}, sockets => $fdat{sockets}, cores => $fdat{cores}, bootdisk => $fdat{bootdisk}, description => PVE::HTMLUtils::encode_description ($fdat{notes}||''), }; PVE::Cluster::check_vm_settings ($settings); $conn->vmconfig_set ($cid, $veid, 'qemu', $settings)->result; }; $udat{popup_error} = $@ if $@; } my $vminfo = PVE::Cluster::load_vmconfig ($cinfo, $cid, $veid, 'qemu', $udat{auth_cookie}); 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} || ''); my $grid = PVE::HTMLGrid->new ('fw1', 'fw2', 'fw3:right', 'fw4'); $grid->add_row (__("Name") . ':', $form->create_element ('name', 'text', defined ($fdat{name}) ? $fdat{name} : $vmconf->{name}), "VMID:", $form->create_element(undef, 'viewonly', $veid)); $grid->add_row (__("Guest Type") . ':', $form->create_element ('ostype', 'dropdown', defined ($fdat{ostype}) ? $fdat{ostype} : ($vmconf->{ostype} || 'other'), $oslist), __("Cluster Node") . ':', $form->create_element(undef, 'viewonly', $ni->{name} . " (" . $ni->{ip} . ")")); my $memory = defined ($fdat{mem}) ? $fdat{mem} : $vmconf->{memory}; my $sockets = defined ($fdat{sockets}) ? $fdat{sockets} : $vmconf->{sockets} || 1; my $cores = defined ($fdat{cores}) ? $fdat{cores} : $vmconf->{cores} || 1; $grid->add_row (__("Memory") . ' (MB):', $form->create_element ('mem', 'number', $memory), __("CPU Sockets") . ':', $form->create_element ('sockets', 'number', $sockets)); $grid->add_row ('', '', __("Cores/Socket") . ':', $form->create_element ('cores', 'number', $cores)); $grid->add_row ('', '', __("Start at boot") . ':', $form->create_element ('onboot', 'bool', defined ($fdat{onboot}) ? $fdat{onboot} : $onboot)); my $html = $grid->html(); my $fw2 = PVE::HTMLGrid::get_width ('fw2to4'); $grid = PVE::HTMLGrid->new ('fw1', $fw2); $fdat{notes} = $notes if !defined ($fdat{notes}); $grid->add_row (__('Notes') . ':', $form->create_element ('notes', 'textarea', $fdat{notes}, 4, ($fw2-4))); $html .= "
" . $grid->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; -]