[pve-devel] [PATCH qemu-server v8 5/6] Refactor defaut bootdisk and smbios1 uuid generation in own subs

Emmanuel Kasper e.kasper at proxmox.com
Wed Sep 13 16:10:25 CEST 2017


This will allow code reuse for qm importovf
---
 PVE/API2/Qemu.pm  | 20 ++++----------------
 PVE/QemuServer.pm | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1002c87..4173bdf 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -535,26 +535,14 @@ __PACKAGE__->register_method({
 
 		    $vollist = &$create_disks($rpcenv, $authuser, $conf, $storecfg, $vmid, $pool, $param, $storage);
 
-		    # try to be smart about bootdisk
-		    my @disks = PVE::QemuServer::valid_drive_names();
-		    my $firstdisk;
-		    foreach my $ds (reverse @disks) {
-			next if !$conf->{$ds};
-			my $disk = PVE::QemuServer::parse_drive($ds, $conf->{$ds});
-			next if PVE::QemuServer::drive_is_cdrom($disk);
-			$firstdisk = $ds;
-		    }
-
-		    if (!$conf->{bootdisk} && $firstdisk) {
-			$conf->{bootdisk} = $firstdisk;
+		    if (!$conf->{bootdisk}) {
+			my $firstdisk = PVE::QemuServer::resolve_first_disk($conf);
+			$conf->{bootdisk} = $firstdisk if $firstdisk;
 		    }
 
 		    # auto generate uuid if user did not specify smbios1 option
 		    if (!$conf->{smbios1}) {
-			my ($uuid, $uuid_str);
-			UUID::generate($uuid);
-			UUID::unparse($uuid, $uuid_str);
-			$conf->{smbios1} = "uuid=$uuid_str";
+			$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
 		    }
 
 		    PVE::QemuConfig->write_config($vmid, $conf);
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2d09726..ee1cecd 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6421,6 +6421,26 @@ sub resolve_dst_disk_format {
 	return $format;
 }
 
+sub resolve_first_disk {
+    my $conf = shift;
+    my @disks = PVE::QemuServer::valid_drive_names();
+    my $firstdisk;
+    foreach my $ds (reverse @disks) {
+	next if !$conf->{$ds};
+	my $disk = PVE::QemuServer::parse_drive($ds, $conf->{$ds});
+	next if PVE::QemuServer::drive_is_cdrom($disk);
+	$firstdisk = $ds;
+    }
+    return $firstdisk;
+}
+
+sub generate_smbios1_uuid {
+    my ($uuid, $uuid_str);
+    UUID::generate($uuid);
+    UUID::unparse($uuid, $uuid_str);
+    return "uuid=$uuid_str";
+}
+
 # bash completion helper
 
 sub complete_backup_archives {
-- 
2.11.0





More information about the pve-devel mailing list