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

Emmanuel Kasper e.kasper at proxmox.com
Wed Jun 7 11:37:41 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 54db5ab..f8e767d 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -543,26 +543,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 7e91ac6..dbfc4ea 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6405,6 +6405,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