[! 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 PVE::HTMLGrid; use PVE::APLInfo; !] [- use strict; my $out = ''; my $html; my $form = PVE::HTMLForm->new (\%fdat); my $cinfo = $fdat{__cinfo}; my $veid = $fdat{veid}; my $cid = $fdat{cid}; my $pkglist = PVE::APLInfo::load_data(); 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, 'openvz')->result; $udat{redirect} = "/vmlist/index.htm"; return; } elsif ($udat{action} eq 'shutdown') { $conn->vmcommand_stop ($cid, $veid, 'openvz', 0)->result; } elsif ($udat{action} eq 'stop') { $conn->vmcommand_stop ($cid, $veid, 'openvz', 1)->result; } elsif ($udat{action} eq 'umount') { $conn->vmcommand_umount ($cid, $veid, 'openvz')->result; } elsif ($udat{action} eq 'start') { $conn->vmcommand_start ($cid, $veid, 'openvz')->result; } elsif ($udat{action} eq 'restart') { $conn->vmcommand_restart ($cid, $veid, 'openvz')->result; } } } if ($fdat{confirmdestroy}) { my $msg = PVE::HTMLUtils::msg ('confirm_remove'); $msg = sprintf ($msg, $veid); my $href = "?action=destroy&cid=$cid&veid=$veid&type=openvz"; print OUT PVE::HTMLUtils::create_confirmframe ($msg, __("Remove"), $href, $fdat{__uri}); return; } my $vzinfo = PVE::Cluster::load_vmconfig ($cinfo, $cid, $veid, 'openvz', $udat{auth_cookie}); my $status = $vzinfo->{vzlist}->{"VEID_$veid"}->{status}; my $veconf = $vzinfo->{config}; my $ni = $vzinfo->{ni}; my $mem = int (($veconf->{vmguarpages}->{bar} * 4) / 1024); my $swdiff = $veconf->{vmguarpages}->{bar} - $veconf->{lockedpages}->{bar}; my $swap = $swdiff > 0 ? int (($swdiff * 4) / 1024) : 0; $mem = $mem - $swap; my $disk = sprintf ("%0.2f", $veconf->{diskspace}->{bar} / (1024*1024)); my $onboot = ($veconf->{onboot}->{value} eq 'yes' || $veconf->{onboot}->{value} eq '1'); my $cpus = $veconf->{cpus}->{value} || 1; my $notes = PVE::HTMLUtils::decode_description ($veconf->{description}->{value} || ''); if ($form->action eq 'save') { my $conn = PVE::ConfigClient::connect ($udat{auth_cookie}); eval { check_write_mode ($udat{AM}); check_field (__("Memory"), $fdat{mem}, 'NOTEMPTY', 'NATURAL'); check_field (__("Swap"), $fdat{swap}, 'NOTEMPTY', 'NATURAL'); check_field (__("Disk space"), $fdat{disk}, 'NOTEMPTY', 'FLOAT'); check_range (__("CPUs"), $fdat{cpus}, 1, 16); my $settings = {}; if ($cpus ne $fdat{cpus}) { $settings->{cpus} = $fdat{cpus}; } if ($mem ne $fdat{mem}) { $settings->{mem} = $fdat{mem}; } if ($swap ne $fdat{swap}) { $settings->{swap} = $fdat{swap}; } if ($disk ne $fdat{disk}) { $settings->{disk} = $fdat{disk}; } if ($notes ne $fdat{notes}) { $settings->{description} = PVE::HTMLUtils::encode_description ($fdat{notes}||''); } if ($onboot != $fdat{onboot}) { $settings->{onboot} = $fdat{onboot} ? 'yes' : 'no'; } PVE::Cluster::check_vm_settings ($settings); if (scalar (keys %$settings) > 0) { $conn->vmconfig_set ($cid, $veid, 'openvz', $settings)->result; } }; $udat{popup_error} = $@ if $@; } my $tmpl = PVE::APLInfo::display_name ("$veconf->{ostemplate}->{value}.tar.gz"); my $grid = PVE::HTMLGrid->new ('fw1', 'fw2', 'fw3:right', 'fw4'); $grid->add_row (__("Template") . ':', $form->create_element(undef, 'viewonly', $tmpl), "VMID:", $form->create_element(undef, 'viewonly', $veid)); $grid->add_row (__("Disk space") . ' (GB):', $form->create_element ('disk', 'float', $fdat{disk} || $disk), __("Cluster Node") . ':', $form->create_element(undef, 'viewonly', $ni->{name} . " (" . $ni->{ip} . ")")); $grid->add_row(__("Memory") . ' (MB):', $form->create_element ('mem', 'number', $fdat{mem} || $mem), __("Start at boot") . ':', $form->create_element ('onboot', 'bool', defined ($fdat{onboot}) ? $fdat{onboot} : $onboot)); $grid->add_row (__("Swap") . ' (MB):', $form->create_element ('swap', 'number', defined ($fdat{swap}) ? $fdat{swap} : $swap), __("CPUs") . ':', $form->create_element ('cpus', 'number', defined ($fdat{cpus}) ? $fdat{cpus} : $cpus)); 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, 'openvz', $vzinfo); $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 => 'openvz' }, 5); print OUT $out; -]