[! 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::APLInfo; !] [- use strict; my $out = ''; my $html; 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 $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 (); if ($udat{action} eq 'destroy') { $conn->vmcommand_destroy ($cid, $veid, 'openvz', $udat{auth_username})->result; $udat{redirect} = "/vmlist/index.htm"; return; } elsif ($udat{action} eq 'shutdown') { $conn->vmcommand_stop ($cid, $veid, 'openvz', $udat{auth_username}, 0)->result; } elsif ($udat{action} eq 'stop') { $conn->vmcommand_stop ($cid, $veid, 'openvz', $udat{auth_username}, 1)->result; } elsif ($udat{action} eq 'umount') { $conn->vmcommand_umount ($cid, $veid, 'openvz', $udat{auth_username})->result; } elsif ($udat{action} eq 'start') { $conn->vmcommand_start ($cid, $veid, 'openvz', $udat{auth_username})->result; } elsif ($udat{action} eq 'restart') { $conn->vmcommand_restart ($cid, $veid, 'openvz', $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=openvz"; print OUT PVE::HTMLUtils::create_confirmframe ($msg, __("Remove"), $href, $fdat{__uri}); return; } my $vzinfo = PVE::Cluster::load_vmconfig ($cinfo, $cid, $veid, 'openvz'); 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 (); 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 ($udat{auth_username}, $cid, $veid, 'openvz', $settings)->result; } }; $udat{popup_error} = $@ if $@; } my $tmpl = PVE::APLInfo::display_name ("$veconf->{ostemplate}->{value}.tar.gz"); $html = ''; $html .= html_table_line (__("Template") . ':', PVE::HTMLForm::viewonly_element ($tmpl), "VMID:", PVE::HTMLForm::viewonly_element ($veid)); $html .= html_table_line (__("Disk space") . ' (GB):', $form->create_element ('disk', 'float', $fdat{disk} || $disk), __("Cluster Node") . ':', PVE::HTMLForm::viewonly_element($ni->{name} . " (" . $ni->{ip} . ")")); $html .= html_table_line (__("Memory") . ' (MB):', $form->create_element ('mem', 'number', $fdat{mem} || $mem), __("Start at boot") . ':', $form->create_element ('onboot', 'bool', defined ($fdat{onboot}) ? $fdat{onboot} : $onboot)); #__("CPUs") . ':', $form->create_element ('cpus', 'rotext', defined ($fdat{cpus}) ? $fdat{cpus} : $cpus)); $html .= html_table_line (__("Swap") . ' (MB):', $form->create_element ('swap', 'number', defined ($fdat{swap}) ? $fdat{swap} : $swap)); $html .= ""; $html .= '
 "; $fdat{notes} = $notes if !defined ($fdat{notes}); my $rows = 4; my $rh = int ($rows*int(1.2*12+1)); $html .= "
" . __('Notes') . ":
'; $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; -]