[! use strict; use PVE::I18N; use PVE::ConfigServer; use PVE::HTMLControls; use PVE::HTMLForm; use PVE::Utils; use PVE::HTMLUtils; use PVE::Cluster; use PVE::APLInfo; use PVE::QemuServer; !] [- use strict; my $cinfo = $fdat{__cinfo}; my $form = PVE::HTMLForm->new (\%fdat); my $conn = PVE::ConfigClient::connect (); my $vzlist = $conn->cluster_vzlist()->result; my $kvmversion = $conn->kvm_version()->result; my $resolvconf = PVE::Config::read_file ('resolvconf'); my $vmops = PVE::Config::read_file ("vmops"); my $cpuinfo = PVE::Utils::get_cpu_info(); if ($form->action eq 'create') { my $veid = $fdat{veid}; my $cid = $fdat{hostcid}; my $trackid; eval { check_write_mode ($udat{AM}); my $settings; if ($fdat{virttype} eq 'openvz') { check_field (__("Memory"), $fdat{vzmem}, 'NOTEMPTY', 'NATURAL'); check_field (__("Swap"), $fdat{swap}, 'NOTEMPTY', 'NATURAL'); check_field (__("Template"), $fdat{ostemplate}, 'NOTEMPTY'); check_field (__("Hostname"), $fdat{hostname}, 'NOTEMPTY', 'NOWHITESPACES'); check_field (__("DNS Domain"), $fdat{dnsdomain}, 'NOTEMPTY', 'NOWHITESPACES'); check_field (__("Password"), $fdat{newpwd1}, 'NOTEMPTY'); check_field (__("Disk space"), $fdat{vzdisk}, 'NOTEMPTY', 'FLOAT'); check_range (__("Disk space"), $fdat{vzdisk}, 0.5, 1024); #check_range (__("CPUs"), $fdat{cpus}, 1, 16); die __("Passwords does not match") . "\n" if $fdat{newpwd1} ne $fdat{newpwd2}; die __("Password is too short") . "\n" if $fdat{newpwd1} && length ($fdat{newpwd1}) < 5; # always use fqdn for hostname if (($fdat{hostname} !~ m/\./) && $fdat{dnsdomain}) { $fdat{hostname} = "$fdat{hostname}.$fdat{dnsdomain}"; } $settings = { mem => $fdat{vzmem}, swap => $fdat{swap}, ostemplate => $fdat{ostemplate}, disk => $fdat{vzdisk}, onboot => $fdat{onboot} ? 'yes' : 'no', rootpasswd => PVE::Utils::_encrypt_pw ($fdat{newpwd1}), searchdomain => $fdat{dnsdomain}, hostname => $fdat{hostname}, cpus => 1, # $fdat{cpus}, }; if (my $pkginfo = PVE::APLInfo::pkginfo ($fdat{ostemplate})) { $settings->{description} = PVE::HTMLUtils::encode_description ($pkginfo->{headline}); } my $ns; push @$ns, $fdat{dnsserver1} if $fdat{dnsserver1} && ($fdat{dnsserver1} ne '0.0.0.0'); push @$ns, $fdat{dnsserver2} if $fdat{dnsserver2} && ($fdat{dnsserver2} ne '0.0.0.0'); $settings->{nameserver} = $ns; if ($fdat{nettype} eq 'veth') { $settings->{netif} = 'ifname=eth0'; if ($fdat{bridge} && ($fdat{bridge} ne 'vmbr0')) { $settings->{netif} .= ",bridge=$fdat{bridge}"; } } else { $settings->{ipset} = $fdat{ipaddress}; } } else { check_field (__("Memory"), $fdat{qmmem}, 'NOTEMPTY', 'NATURAL'); check_field (__("Name"), $fdat{name}, 'NOTEMPTY', 'NOWHITESPACES'); check_field (__("Disk space"), $fdat{qmdisk}, 'NOTEMPTY', 'FLOAT'); check_range (__("Disk space"), $fdat{qmdisk}, 0.5, 1024); check_range (__("CPUs"), $fdat{smp}, 1, 16); my $mac = PVE::QemuServer::random_ether_addr(); my $network = "$fdat{nictype}=$mac"; $settings = { memory => $fdat{qmmem}, cdrom => $fdat{cdrom}, onboot => $fdat{onboot} ? 'yes' : 'no', name => $fdat{name}, $fdat{bridge} => $network, ostype =>$fdat{ostype}, smp => $fdat{smp}, }; if ($fdat{disktype} eq 'ide') { $settings->{ide0} = $fdat{qmdisk}; $settings->{bootdisk} = 'ide0'; } elsif ($fdat{disktype} eq 'scsi') { $settings->{scsi0} = $fdat{qmdisk}; $settings->{bootdisk} = 'scsi0'; } elsif ($fdat{disktype} eq 'virtio') { $settings->{virtio0} = $fdat{qmdisk}; $settings->{bootdisk} = 'virtio0'; } } PVE::Cluster::check_vm_settings ($settings); $trackid = $conn->vmcommand_create ($udat{auth_username}, $cid, $veid, $fdat{virttype}, $settings)->result; }; if ($@) { $udat{popup_error} = $@; } else { print OUT PVE::HTMLUtils::create_vmops_frame ($veid, $trackid); return; } } $fdat{virttype} = 'openvz' if !$fdat{virttype}; my $out = ''; my $has_hvm = $cpuinfo->{hvm}; if (!$cpuinfo->{hvm}) { my $msg = __("This CPU does not support KVM virtual machines (no Intel VT / AMD-V support)."); $out .= PVE::HTMLUtils::create_noteframe (__("Attention"), $msg); $out .= "
\n"; } elsif (!$kvmversion) { my $msg = __("KVM module not loaded. Maybe you need to enable Intel VT / AMD-V support in the BIOS."); $out .= PVE::HTMLUtils::create_noteframe (__("Attention"), $msg); $out .= "
\n"; $has_hvm = 0; } my $nextveid = PVE::Cluster::get_nextid($vzlist, $vmops); my $cidlist = []; foreach my $ni (@{$cinfo->{nodes}}) { push @$cidlist, [$ni->{cid}, "$ni->{name} ($ni->{ip})"]; } 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 $tmpllist; if ($fdat{virttype} eq 'openvz') { my $fnlist = PVE::Config::get_template_list(); my $default; foreach my $fn (@$fnlist) { push @$tmpllist, [$fn, PVE::APLInfo::display_name ($fn)]; $default = $fn if $fn =~ m/debian-4.0-standard/; } $fdat{ostemplate} = $default if !$fdat{ostemplate}; } else { $tmpllist = PVE::Config::get_media_list(); } my $osl = PVE::QemuServer::os_list_description(); my $oslist = []; foreach my $os (sort keys %$osl) { push @$oslist, [ $os, $osl->{$os} ]; } $out .= $form->create_header(); my $html = ""; my $vtypes = [['openvz', 'Container (OpenVZ)']]; if ($has_hvm) { push @$vtypes, [ 'qemu', "Fully virtualized (KVM)" ]; } $html .= html_table_line (__("Type") . ':', $form->create_element ('virttype', 'dynamicdropdown', $fdat{virttype}, $vtypes), "VMID:", $form->create_element ('veid', 'number', $fdat{veid} || $nextveid)); my $bridges = PVE::Utils::get_bridges (); if ($fdat{virttype} eq 'openvz') { $html .= html_table_line (__("Template") . ':', $form->create_element ('ostemplate', 'dropdown', $fdat{ostemplate}, $tmpllist), __("Cluster Node") . ':', $form->create_element ('hostcid', 'dropdown', defined ($fdat{hostcid}) ? $fdat{hostcid} : $cinfo->{local}->{cid}, $cidlist)); $html .= html_table_line (__("Hostname") . ':', $form->create_element ('hostname', 'text', $fdat{hostname}), __("Start at boot") . ':', $form->create_element ('onboot', 'bool', defined ($fdat{onboot}) ? $fdat{onboot} : 0)); $html .= html_table_line (__("Memory") . ' (MB):', $form->create_element ('vzmem', 'number', $fdat{vzmem} || 512), __("Disk space") . ' (GB):', $form->create_element ('vzdisk', 'float', $fdat{vzdisk} || "8")); $html .= html_table_line (__("Swap") . ' (MB):', $form->create_element ('swap', 'number', defined ($fdat{swap}) ? $fdat{swap} : 512)); # __("CPUs") . ':', $form->create_element ('cpus', 'rotext', $fdat{cpus} || 1)); $html .= html_table_line (__("Password") . ':', $form->create_element ('newpwd1', 'password', $fdat{newpwd1})); $html .= html_table_line (__("Confirm Password") . ':', $form->create_element ('newpwd2', 'password', $fdat{newpwd2})); } else { $html .= html_table_line (__("Installation Media") . ':', $form->create_element ('cdrom', 'dropdown', $fdat{cdrom}, $tmpllist), __("Cluster Node") . ':', $form->create_element ('hostcid', 'dropdown', defined ($fdat{hostcid}) ? $fdat{hostcid} : $cinfo->{local}->{cid}, $cidlist)); $html .= html_table_line (__("Name") . ':', $form->create_element ('name', 'text', $fdat{name}), __("Start at boot") . ':', $form->create_element ('onboot', 'bool', defined ($fdat{onboot}) ? $fdat{onboot} : 0)); $html .= html_table_line (__("Disk space") . ' (GB):', $form->create_element ('qmdisk', 'float', $fdat{qmdisk} || "32"), __("Disk type") . ':', $form->create_element ('disktype', 'dropdown', $fdat{disktype}, [['ide', 'IDE'], ['scsi', 'SCSI'], ['virtio', 'VIRTIO']])); $html .= html_table_line (__("Memory") . ' (MB):', $form->create_element ('qmmem', 'number', $fdat{qmmem} || 512), __("CPUs") . ':', $form->create_element ('smp', 'number', $fdat{smp} || 1)); $html .= html_table_line ('', '', __("Guest Type") . ':', $form->create_element ('ostype', 'dropdown', $fdat{ostype} || 'other', $oslist)); } $html .= "
"; $out .= PVE::HTMLUtils::create_statusframe (undef, "Configuration", undef, $html); $out .= "
\n"; $html = ""; if ($fdat{virttype} eq 'openvz') { my $dns1 = @{$resolvconf->{nameservers}}[0] || '0.0.0.0'; my $dns2 = @{$resolvconf->{nameservers}}[1] || '0.0.0.0'; my $ntypes = [['', __("Virtual Network (venet)")], [ 'veth', __("Bridged Ethernet (veth)") ]]; $html .= html_table_line (__("Network Type") . ':', $form->create_element ('nettype', 'dynamicdropdown', $fdat{nettype}, $ntypes), __("DNS Domain") . ':', $form->create_element ('dnsdomain', 'text', $fdat{dnsdomain} || $resolvconf->{search}) ); if ($fdat{nettype} eq 'veth') { $html .= $form->create_element ('ipaddress', 'hidden', $fdat{ipaddress} || "127.0.0.1"); $html .= html_table_line (__("Bridge") . ':', $form->create_element ('bridge', 'dropdown', $fdat{bridge} || 'vmbr0', $bridges), __("First DNS Server") . ':', $form->create_element ('dnsserver1', 'ip', $fdat{dnsserver1} || $dns1)); } else { $html .= html_table_line (__("IP Address") . ':', $form->create_element ('ipaddress', 'ip', $fdat{ipaddress} || "127.0.0.1"), __("First DNS Server") . ':', $form->create_element ('dnsserver1', 'ip', $fdat{dnsserver1} || $dns1)); } $html .= html_table_line ('', '', __("Second DNS Server") . ':', $form->create_element ('dnsserver2', 'ip', $fdat{dnsserver2} || $dns2) ); } else { my $nics = PVE::QemuServer::nic_models (); my $brg; foreach my $bn (@$bridges) { if ($bn =~ m/^vmbr([0-9])$/) { push @$brg, [ "vlan$1", "vmbr$1" ]; } } push @$brg, [ "vlanu", "NAT (User Mode Network)" ]; $html .= html_table_line (__("Bridge") . ':', $form->create_element ('bridge', 'dropdown', $fdat{bridge} || 'vmbr0', $brg), __("Network Card") . ':', $form->create_element ('nictype', 'dropdown', $fdat{nictype}, $nics)); } $html .= "
"; $out .= PVE::HTMLUtils::create_statusframe (undef, __("Network"), undef, $html); $out .= "
"; $out .= $form->create_cmdbutton ('create'); $out .= $form->create_footer(); print OUT $out; -]