[!
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 = int ($fdat{veid}); # filter leading zeros 0234
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 = '