[pve-devel] r5163 - in qemu-server/pve2: . PVE PVE/API2/Qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Sep 16 13:45:00 CEST 2010


Author: dietmar
Date: 2010-09-16 11:45:00 +0000 (Thu, 16 Sep 2010)
New Revision: 5163

Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/PVE/API2/Qemu/Config.pm
   qemu-server/pve2/PVE/API2/Qemu/Status.pm
   qemu-server/pve2/PVE/QemuServer.pm
   qemu-server/pve2/nqm
Log:
	* PVE/QemuServer.pm (parse_options_new): removed - no longer needed


Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2010-09-15 12:20:24 UTC (rev 5162)
+++ qemu-server/pve2/ChangeLog	2010-09-16 11:45:00 UTC (rev 5163)
@@ -1,3 +1,7 @@
+2010-09-16  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/QemuServer.pm (parse_options_new): removed - no longer needed
+
 2010-09-14  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/API2/Qemu.pm: new index class

Modified: qemu-server/pve2/PVE/API2/Qemu/Config.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Config.pm	2010-09-15 12:20:24 UTC (rev 5162)
+++ qemu-server/pve2/PVE/API2/Qemu/Config.pm	2010-09-16 11:45:00 UTC (rev 5163)
@@ -34,6 +34,16 @@
 
 use base qw(PVE::RESTHandler);
 
+my $resolve_cdrom_alias = sub {
+    my $param = shift;
+
+    if (my $value = $param->{cdrom}) {
+	$value .= ",media=cdrom" if $value !~ m/media=/;
+	$param->{ide2} = $value;
+	delete $param->{cdrom};
+    }
+};
+
 __PACKAGE__->register_method ({
     name => 'index', 
     path => '',  
@@ -117,10 +127,20 @@
 	
 	my $storecfg = read_file('storagecfg');
 
-	my $opts = PVE::QemuServer::parse_options_new($storecfg, $param->{vmid}, $param, 1);
+	&$resolve_cdrom_alias($param);
 
-	PVE::QemuServer::add_random_macs ($opts);
+	foreach my $opt (keys %$param) {
+	    if (PVE::QemuServer::valid_drivename($opt)) {
+		my $drive = PVE::QemuServer::parse_drive ($opt, $param->{$opt});
+		raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
 
+		PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
+		$param->{$opt} = PVE::QemuServer::print_drive ($vmid, $drive);
+	    }
+	}
+
+	PVE::QemuServer::add_random_macs ($param);
+
 	#fixme: ? syslog ('info', "VM $vmid creating new virtual machine");
 	
 	my $vollist = [];
@@ -131,23 +151,23 @@
 	    die "unable to create vm $vmid: config file already exists\n" 
 		if -f $filename;
 
-	    $vollist = PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
+	    $vollist = PVE::QemuServer::create_disks ($storecfg, $vmid, $param);
 
 	    # try to be smart about bootdisk
 	    my @disks = PVE::QemuServer::disknames();
 	    my $firstdisk;
 	    foreach my $ds (reverse @disks) {
-		next if !$opts->{$ds};
-		my $disk = PVE::QemuServer::parse_drive ($ds, $opts->{$ds});
+		next if !$param->{$ds};
+		my $disk = PVE::QemuServer::parse_drive ($ds, $param->{$ds});
 		next if PVE::QemuServer::drive_is_cdrom ($disk);
 		$firstdisk = $ds;
 	    }
 
-	    if (!$opts->{bootdisk} && $firstdisk) {
-		$opts->{bootdisk} = $firstdisk; 
+	    if (!$param->{bootdisk} && $firstdisk) {
+		$param->{bootdisk} = $firstdisk; 
 	    }
 
-	    PVE::QemuServer::create_conf_nolock($vmid, $opts);
+	    PVE::QemuServer::create_conf_nolock($vmid, $param);
 	};
 
 	eval { PVE::QemuServer::lock_config ($vmid, $createfn); };
@@ -212,14 +232,47 @@
 
 	my $storecfg = read_file('storagecfg');
 
-	my $opts = PVE::QemuServer::parse_options_new($storecfg, $param->{vmid}, $param, 1);
+	&$resolve_cdrom_alias($param);
 
+	my $eject = {};
+	my $cdchange = {};
+
+	foreach my $opt (keys %$param) {
+	    if (PVE::QemuServer::valid_drivename($opt)) {
+		my $drive = PVE::QemuServer::parse_drive ($opt, $param->{$opt});
+		raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
+		if ($drive->{file} eq 'eject') {
+		    $eject->{$opt} = 1;
+		    delete $param->{$opt};
+		    next;
+		}
+
+		PVE::QemuServer::cleanup_drive_path($opt, $storecfg, $drive);
+		$param->{$opt} = PVE::QemuServer::print_drive ($vmid, $drive);
+
+		if (PVE::QemuServer::drive_is_cdrom ($drive)) {
+		    $cdchange->{$opt} = PVE::QemuServer::get_iso_path ($storecfg, $vmid, $drive->{file});
+		}
+	    }
+	}
+
+	PVE::QemuServer::add_random_macs ($param);
+
 	my $updatefn =  sub {
 
 	    my $conf = PVE::QemuServer::load_config ($vmid);
 
 	    PVE::QemuServer::check_lock($conf) if !$skiplock;
 
+	    foreach my $opt (keys %$eject) {
+		if ($conf->{$opt}) {
+		    my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
+		    $cdchange->{$opt} = undef if PVE::QemuServer::drive_is_cdrom($drive);
+		} else {
+		    raise_param_exc({ $opt => "eject failed - drive does not exist." });
+		}
+	    }
+
 	    my $unset = {};
 
 	    foreach my $opt (PVE::Tools::split_list($delete)) {
@@ -229,21 +282,28 @@
 		} 
 		next if !defined ($conf->{$opt});
 		if (PVE::QemuServer::valid_drivename($opt)) {
-		    my $disk = $conf->{diskinfo}->{$opt};
-		    if ($disk && !PVE::QemuServer::drive_is_cdrom ($disk)) {
-			PVE::QemuServer::unlink_image($storecfg, $vmid, $disk->{file});
+		    my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
+		    if (PVE::QemuServer::drive_is_cdrom ($drive)) {
+			$cdchange->{$opt} = undef;
+		    } else {
+			PVE::QemuServer::unlink_image($storecfg, $vmid, $drive->{file});
 		    }
 		}
 		$unset->{$opt} = 1;
 	    }
 
-	    PVE::QemuServer::add_random_macs ($opts);
+	    PVE::QemuServer::create_disks ($storecfg, $vmid, $param);
 
-	    PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
+	    PVE::QemuServer::change_config_nolock  ($vmid, $param, $unset, 1);
 
-	    PVE::QemuServer::change_config_nolock  ($vmid, $opts, $unset, 1);
+	    return if !PVE::QemuServer::check_running ($vmid);
 
-	    # return if !PVE::QemuServer::check_running ($vmid);
+	    foreach my $opt (keys %$cdchange) {
+		my $qdn = PVE::QemuServer::qemu_drive_name ($opt, 'cdrom');
+		my $path = $cdchange->{$opt};
+		PVE::QemuServer::vm_monitor_command ($vmid, "eject $qdn", 0);
+		PVE::QemuServer::vm_monitor_command ($vmid, "change $qdn \"$path\"", 0) if $path;
+	    }
 	};
 
 	PVE::QemuServer::lock_config ($vmid, $updatefn);

Modified: qemu-server/pve2/PVE/API2/Qemu/Status.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Status.pm	2010-09-15 12:20:24 UTC (rev 5162)
+++ qemu-server/pve2/PVE/API2/Qemu/Status.pm	2010-09-16 11:45:00 UTC (rev 5163)
@@ -87,7 +87,7 @@
 		type => 'string',
 		enum => [qw(start stop reset shutdown cad suspend resume vncticket) ],
 	    },
-	    ticket => get_standard_option('pve-vncticket'), 
+	    ticket => get_standard_option('pve-vncticket', { optional => 1 }), 
 	},
     },
     returns => { type => 'null'},

Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2010-09-15 12:20:24 UTC (rev 5162)
+++ qemu-server/pve2/PVE/QemuServer.pm	2010-09-16 11:45:00 UTC (rev 5163)
@@ -685,6 +685,25 @@
     raise_param_exc({ $opt => "unexpected media type ($vtype != $etype)" });
 }
 
+sub cleanup_drive_path {
+    my ($opt, $storecfg, $drive) = @_;
+
+    # try to convert filesystem paths to volume IDs
+
+    if (($drive->{file} !~ m/^(cdrom|none)$/) &&
+	($drive->{file} !~ m|^/dev/.+|) &&
+	($drive->{file} !~ m/^([^:]+):(.+)$/) &&
+	($drive->{file} !~ m/^\d+$/)) { 
+	my ($vtype, $volid) = PVE::Storage::path_to_volume_id($storecfg, $drive->{file});
+	raise_param_exc({ $opt => "unable to associate path '$drive->{file}' to any storage"}) if !$vtype;
+	$drive->{media} = 'cdrom' if !$drive->{media} && $vtype eq 'iso';
+	verify_media_type($opt, $vtype, $drive->{media});
+	$drive->{file} = $volid;
+    }
+
+    $drive->{media} = 'cdrom' if !$drive->{media} && $drive->{file} =~ m/^(cdrom|none)$/;
+}
+
 # fixme: remove
 sub parse_options {
     my ($self, $vmid, $create) = @_;
@@ -712,8 +731,7 @@
 	if ($@) {
 	    die "unable to parse value for '$opt' : $@";
 	} else {
-	    my $fmt = $confdesc->{$opt}->{format};
-	    if ($fmt && $fmt eq 'pve-qm-drive') {
+	    if (valid_drivename($opt)) {
 		my $drive = parse_drive ($opt, $value);
 		if (($drive->{file} !~ m/^(undef|delete|cdrom|none)$/) &&
 		    ($drive->{file} !~ m|^/dev/.+|) &&
@@ -747,50 +765,6 @@
     return $settings;
 }
 
-# fixme: should we return the parse value?
-sub parse_options_new {
-    my ($storecfg, $vmid, $param, $create) = @_;
-
-    my $settings = {};
-
-    foreach my $opt (keys %$param) {
-	my $value = $param->{$opt};
-
-	if (!defined($value)) {
-	    raise_param_exc({ $opt => "got undefined value" });
-	}
-	    
-	if ($opt eq 'cdrom') {
-	    $opt = 'ide2';
-	    $value .= ",media=cdrom" if $value !~ m/media=/;
-	}
-
-	my $v;
-	eval { $v = check_type($opt, $value); };
-	raise_param_exc({ $opt => $@ }) if $@;
-	my $fmt = $confdesc->{$opt}->{format};
-	if ($fmt && $fmt eq 'pve-qm-drive') {
-	    my $drive = parse_drive ($opt, $value);
-	    if (($drive->{file} !~ m/^(cdrom|none)$/) &&
-		($drive->{file} !~ m|^/dev/.+|) &&
-		($drive->{file} !~ m/^([^:]+):(.+)$/) &&
-		($drive->{file} !~ m/^\d+$/)) { 
-		# try to convert path to volume id
-		my ($vtype, $volid) = PVE::Storage::path_to_volume_id($storecfg, $drive->{file}) if $storecfg;
-
-	       
-		raise_param_exc({ $opt => "unable to associate path '$drive->{file}' to any storage"}) if !$vtype;
-		verify_media_type($opt, $vtype, $drive->{media});
-		$drive->{file} = $volid;
-		$v = print_drive ($vmid, $drive);
-	    }
-	}
-	$settings->{$opt} = $v;
-    }
-
-    return $settings;
-}
-
 sub create_conf_nolock {
     my ($vmid, $settings) = @_;
 
@@ -2436,6 +2410,7 @@
     });
 }
 
+# fixme: remove
 sub vm_cdrom {
     my ($self, $vmid, $dev, $volid) = @_;
 

Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm	2010-09-15 12:20:24 UTC (rev 5162)
+++ qemu-server/pve2/nqm	2010-09-16 11:45:00 UTC (rev 5163)
@@ -365,7 +365,6 @@
     }});
 
 # fixme: unlink
-# fixme: cdrom
 
 my $cmddef = {
     list => [ "PVE::API2::Qemu::Config", 'vmlist', [],




More information about the pve-devel mailing list