[pve-devel] r6474 - qemu-server/pve2/PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Aug 15 09:55:08 CEST 2011


Author: dietmar
Date: 2011-08-15 09:55:08 +0200 (Mon, 15 Aug 2011)
New Revision: 6474

Modified:
   qemu-server/pve2/PVE/QemuServer.pm
Log:
cleanup default handling


Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2011-08-15 06:39:57 UTC (rev 6473)
+++ qemu-server/pve2/PVE/QemuServer.pm	2011-08-15 07:55:08 UTC (rev 6474)
@@ -125,28 +125,26 @@
 
 my $pcisysfs = "/sys/bus/pci";
 
-my $default_memory = 512;
-my $default_min_memory = 16;
-
 my $keymaphash = PVE::Tools::kvmkeymaps();
 
 my $confdesc = {
     onboot => {
 	optional => 1,
 	type => 'boolean',
-	description => "Specifies whether a VM will be started during system bootup. Default is read from global configuration file.",
+	description => "Specifies whether a VM will be started during system bootup.",
 	default => 0,
     },
     autostart => {
 	optional => 1,
 	type => 'boolean',
-	description => "Automatic restart after crash (currently ignored). Default is read from global configuration file.",
+	description => "Automatic restart after crash (currently ignored).",
 	default => 0,
     },
     reboot => {
 	optional => 1,
 	type => 'boolean',
-	description => "Allow reboot (default=yes). If set to 'no' the VM exit on reboot.",
+	description => "Allow reboot. If set to '0' the VM exit on reboot.",
+	default => 1,
     },
     lock => {
 	optional => 1,
@@ -163,7 +161,7 @@
     cpuunits => {
 	optional => 1,
 	type => 'integer',
-	description => "CPU weight for a VM. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this VM gets. Number is relative to weights of all the other running VMs.\n\nNOTE: You can disable fair-scheduler configuration by setting this to 0. Default is read from global configuration file.",
+	description => "CPU weight for a VM. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this VM gets. Number is relative to weights of all the other running VMs.\n\nNOTE: You can disable fair-scheduler configuration by setting this to 0.",
 	minimum => 0,
 	maximum => 500000,
 	default => 1000,
@@ -171,15 +169,16 @@
     memory => {
 	optional => 1,
 	type => 'integer',
-	description => "Amount of RAM for the VM in MB. Default is read from global configuration file.",
-	minimum => $default_min_memory,
-	default => $default_memory,
+	description => "Amount of RAM for the VM in MB.",
+	minimum => 16,
+	default => 512,
     },
     keyboard => {
 	optional => 1,
 	type => 'string',
-	description => "Keybord layout for vnc server. Default is read from global configuration file.",
+	description => "Keybord layout for vnc server. Default is read from the datacenter configuration file.",
 	enum => [ keys %$keymaphash ],
+	default => 'en',
     },
     name => {
 	optional => 1,
@@ -218,6 +217,7 @@
 	type => 'string',
 	description => "Boot on floppy (a), hard disk (c), CD-ROM (d), or network (n). Default is 'cad' (disk, floppy, cdrom)",
 	pattern => '[acdn]{1,4}',
+	default => 'cad',
     },
     bootdisk => {
 	optional => 1,
@@ -234,35 +234,39 @@
     sockets => {
 	optional => 1,
 	type => 'integer',
-	description => "The number of CPU sockets (default=1).",
+	description => "The number of CPU sockets.",
 	minimum => 1,
+	default => 1,
     },
     cores => {
 	optional => 1,
 	type => 'integer',
-	description => "The number of cores per socket (default=1)",
+	description => "The number of cores per socket.",
 	minimum => 1,
+	default => 1,
     },
     acpi => {
 	optional => 1,
 	type => 'boolean',
-	description => "Enable/disable ACPI (default=yes).",
+	description => "Enable/disable ACPI.",
+	default => 1,
     },
     kvm => {
 	optional => 1,
 	type => 'boolean',
-	description => "Enable/disable KVM hardware virtualization (default=yes).",
+	description => "Enable/disable KVM hardware virtualization.",
+	default => 1,
     },
     tdf => {
 	optional => 1,
 	type => 'boolean',
-	description => "Enable/disable time drift fix. Default is read from global configuration file.",
+	description => "Enable/disable time drift fix.",
 	default => 1,
     },
     localtime => { 
 	optional => 1,
 	type => 'boolean',
-	description => "Set the real time clock to local time.",
+	description => "Set the real time clock to local time. This is enabled by default if ostype indicates a Microsoft OS.",
     },
     freeze => {
 	optional => 1,
@@ -272,9 +276,8 @@
     vga => {
 	optional => 1,
 	type => 'string',
-	description => "Select VGA type. Default is a Cirrus Logic GD5446 PCI VGA card ('cirrus'). If you want to use high resolution modes (>= 1280x1024x16) then you should use option 'std' or 'vmware'. Default is read from global configuration file.",
+	description => "Select VGA type. Default is a Cirrus Logic GD5446 PCI VGA card ('cirrus'). If you want to use high resolution modes (>= 1280x1024x16) then you should use option 'std' or 'vmware'. Default is 'std' for win7/w2k8, and 'cirrur' for other ostype.",
 	enum => [qw(std cirrus vmware)],
-	default => 'cirrus',
     },
     hostpci => {
 	optional => 1,
@@ -336,19 +339,19 @@
 	optional => 1,
 	type => 'boolean',
 	default => 1,
-	description => "Enable/disable the usb tablet device. This device is usually needed to allow absolute mouse positioning. Else the mouse runs out of sync with normal vnc clients. If you're running lots of console-only guests on one host, you may consider disabling this to save some context switches. Default is read from global configuration file.",
+	description => "Enable/disable the usb tablet device. This device is usually needed to allow absolute mouse positioning. Else the mouse runs out of sync with normal vnc clients. If you're running lots of console-only guests on one host, you may consider disabling this to save some context switches.",
     },
     migrate_speed => {
 	optional => 1,
 	type => 'integer',
-	description => "Set maximum speed (in MB/s) for migrations. Default is read from global configuration file. Value 0 is no limit.",
+	description => "Set maximum speed (in MB/s) for migrations. Value 0 is no limit.",
 	minimum => 0,
 	default => 0,
     },
     migrate_downtime => {
 	optional => 1,
 	type => 'integer',
-	description => "Set maximum tolerated downtime (in seconds) for migrations. Default is read from global configuration file.",
+	description => "Set maximum tolerated downtime (in seconds) for migrations.",
 	minimum => 0,
 	default => 1,
     },
@@ -360,7 +363,7 @@
     },
     cpu => {
 	optional => 1,
-	description => "Emulated CPU type",
+	description => "Emulated CPU type.",
 	type => 'string',
 	enum => [ qw(486 athlon pentium pentium2 pentium3 coreduo core2duo kvm32 kvm64 qemu32 qemu64 phenom host) ],
 	default => 'qemu64',
@@ -739,9 +742,7 @@
     my $defaults = load_defaults();
 
     $settings->{name} = "vm$vmid" if !$settings->{name};
-    if (!$settings->{memory}) {
-	$settings->{memory} = $defaults->{memory} || $default_memory;
-    }
+    $settings->{memory} = $defaults->{memory} if !$settings->{memory};
 
     my $data = '';
     foreach my $opt (keys %$settings) {
@@ -1497,28 +1498,35 @@
 
 sub load_defaults { 
 
-    my $filename = "/etc/pve/qemu-server.cfg";
-
     my $res = {};
 
+    # we use static defaults from our JSON schema configuration
     foreach my $key (keys %$confdesc) {
 	if (defined(my $default = $confdesc->{$key}->{default})) {
 	    $res->{$key} = $default;
 	}
     }
    
+    # and only allow a few values to be overwritten by
+    # seetings in the datacenter option file.
+    my $allow_overwrite = {
+	keyboard => 1,
+    };
+
+    my $filename = "/etc/pve/datacenter.cfg";
+
     my $fh = new IO::File ($filename, "r") || return $res;
 
-    while (my $line = <$fh>) {
-	
+    while (my $line = <$fh>) {	
 	next if $line =~ m/^\#/;
-
 	next if $line =~ m/^\s*$/;
 
 	if ($line =~ m/^([a-z][a-z_]*):\s*(\S+)\s*$/) {
 	    my $key = $1;
 	    my $value = $2;
 
+	    next if !$allow_overwrite->{$key};
+
 	    if ($confdesc->{$key} && $confdesc->{$key}->{default}) {
 		eval { $value = check_type($key, $value); };
 		if ($@) {
@@ -1950,7 +1958,13 @@
 
     push @$cmd, '-no-reboot' if  defined ($conf->{reboot}) && $conf->{reboot} == 0;
 
-    my $vga = $conf->{vga} || $defaults->{vga};
+    my $vga = $conf->{vga};
+    if (!$vga) {
+	if ($conf->{ostype} && ($conf->{ostype} eq 'win7' || $conf->{ostype} eq 'w2k8')) {
+	    $vga = 'std';
+	}
+    }
+  
     push @$cmd, '-vga', $vga if $vga; # for kvm 77 and later
 
     # time drift fix
@@ -2010,12 +2024,8 @@
 	push @$cmd, '-drive', $tmp;
     });
 
-    if ($conf->{memory}) {
-	push @$cmd, '-m', $conf->{memory};
-    } else {
-	push @$cmd, '-m', $defaults->{memory} || $default_memory;
-    }
-
+    push @$cmd, '-m', $conf->{memory} || $defaults->{memory};
+ 
     my $foundnet = 0;
 
     foreach my $k (sort keys %$conf) {




More information about the pve-devel mailing list