From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 5F2031FF164
	for <inbox@lore.proxmox.com>; Fri,  3 Jan 2025 17:00:18 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 8486829439;
	Fri,  3 Jan 2025 16:58:49 +0100 (CET)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri,  3 Jan 2025 16:57:54 +0100
Message-Id: <20250103155802.143669-12-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250103155802.143669-1-f.ebner@proxmox.com>
References: <20250103155802.143669-1-f.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.101 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 PROLO_LEO1                0.1 Meta Catches all Leo drug variations so far
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH qemu-server 11/19] move meta information
 handling to its own module
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Like this, it can be used by modules that cannot depend on
QemuServer.pm without creating a cyclic dependency.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/API2/Qemu.pm           |  3 ++-
 PVE/QemuServer.pm          | 42 +++-------------------------------
 PVE/QemuServer/Makefile    |  1 +
 PVE/QemuServer/MetaInfo.pm | 47 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 40 deletions(-)
 create mode 100644 PVE/QemuServer/MetaInfo.pm

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 4ad9165a..7eba3a33 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -35,6 +35,7 @@ use PVE::QemuServer::ImportDisk;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
+use PVE::QemuServer::MetaInfo;
 use PVE::QemuServer::PCI;
 use PVE::QemuServer::QMPHelpers;
 use PVE::QemuServer::USB;
@@ -1204,7 +1205,7 @@ __PACKAGE__->register_method({
 		    assert_scsi_feature_compatibility($opt, $conf, $storecfg, $param->{$opt});
 		}
 
-		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
+		$conf->{meta} = PVE::QemuServer::MetaInfo::new_meta_info_string();
 
 		my $vollist = [];
 		eval {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index af8712f6..12e5543d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -57,6 +57,7 @@ use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options get_cpu_bitne
 use PVE::QemuServer::Drive qw(is_valid_drivename checked_volume_format drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
+use PVE::QemuServer::MetaInfo;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
 use PVE::QemuServer::QMPHelpers qw(qemu_deviceadd qemu_devicedel qemu_objectadd qemu_objectdel);
@@ -281,21 +282,6 @@ my $rng_fmt = {
     },
 };
 
-my $meta_info_fmt = {
-    'ctime' => {
-	type => 'integer',
-	description => "The guest creation timestamp as UNIX epoch time",
-	minimum => 0,
-	optional => 1,
-    },
-    'creation-qemu' => {
-	type => 'string',
-	description => "The QEMU (machine) version from the time this VM was created.",
-	pattern => '\d+(\.\d+)+',
-	optional => 1,
-    },
-};
-
 my $confdesc = {
     onboot => {
 	optional => 1,
@@ -729,7 +715,7 @@ EODESCR
     },
     meta => {
 	type => 'string',
-	format => $meta_info_fmt,
+	format => $PVE::QemuServer::MetaInfo::meta_info_fmt,
 	description => "Some (read-only) meta-information about this guest.",
 	optional => 1,
     },
@@ -2058,32 +2044,10 @@ sub parse_rng {
     return $res;
 }
 
-sub parse_meta_info {
-    my ($value) = @_;
-
-    return if !$value;
-
-    my $res = eval { parse_property_string($meta_info_fmt, $value) };
-    warn $@ if $@;
-    return $res;
-}
-
-sub new_meta_info_string {
-    my () = @_; # for now do not allow to override any value
-
-    return PVE::JSONSchema::print_property_string(
-	{
-	    'creation-qemu' => kvm_user_version(),
-	    ctime => "". int(time()),
-	},
-	$meta_info_fmt
-    );
-}
-
 sub qemu_created_version_fixups {
     my ($conf, $forcemachine, $kvmver) = @_;
 
-    my $meta = parse_meta_info($conf->{meta}) // {};
+    my $meta = PVE::QemuServer::MetaInfo::parse_meta_info($conf->{meta}) // {};
     my $forced_vers = PVE::QemuServer::Machine::extract_version($forcemachine);
 
     # check if we need to apply some handling for VMs that always use the latest machine version but
diff --git a/PVE/QemuServer/Makefile b/PVE/QemuServer/Makefile
index 89d12091..18fd13ea 100644
--- a/PVE/QemuServer/Makefile
+++ b/PVE/QemuServer/Makefile
@@ -7,6 +7,7 @@ SOURCES=PCI.pm		\
 	Helpers.pm	\
 	Monitor.pm	\
 	Machine.pm	\
+	MetaInfo.pm	\
 	CPUConfig.pm	\
 	CGroup.pm	\
 	Drive.pm	\
diff --git a/PVE/QemuServer/MetaInfo.pm b/PVE/QemuServer/MetaInfo.pm
new file mode 100644
index 00000000..a8cb6c5e
--- /dev/null
+++ b/PVE/QemuServer/MetaInfo.pm
@@ -0,0 +1,47 @@
+package PVE::QemuServer::MetaInfo;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema;
+
+use PVE::QemuServer::Helpers;
+
+our $meta_info_fmt = {
+    'ctime' => {
+	type => 'integer',
+	description => "The guest creation timestamp as UNIX epoch time",
+	minimum => 0,
+	optional => 1,
+    },
+    'creation-qemu' => {
+	type => 'string',
+	description => "The QEMU (machine) version from the time this VM was created.",
+	pattern => '\d+(\.\d+)+',
+	optional => 1,
+    },
+};
+
+sub parse_meta_info {
+    my ($value) = @_;
+
+    return if !$value;
+
+    my $res = eval { PVE::JSONSchema::parse_property_string($meta_info_fmt, $value) };
+    warn $@ if $@;
+    return $res;
+}
+
+sub new_meta_info_string {
+    my () = @_; # for now do not allow to override any value
+
+    return PVE::JSONSchema::print_property_string(
+	{
+	    'creation-qemu' => PVE::QemuServer::Helpers::kvm_user_version(),
+	    ctime => "". int(time()),
+	},
+	$meta_info_fmt,
+    );
+}
+
+1;
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel