public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 1/4] config: add new meta property withe creation time
Date: Wed,  3 Nov 2021 16:58:09 +0100	[thread overview]
Message-ID: <20211103155812.1461208-2-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20211103155812.1461208-1-t.lamprecht@proxmox.com>

currently we only add the creation time (ctime), that was requested
as low priority wish from some users from time to time.

Note that the meta info is not available in the update API endpoints,
and at the moment the code should not change/add/delete it either in
any place.

We may want to update in on actions like clone or backup-restore in
the future, e.g., to also save the time of that event and possibly
the original source VMID, put that can be thought out later.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

no changes

 PVE/API2/Qemu.pm  |  2 ++
 PVE/QemuServer.pm | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1ac81e2..b479811 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -708,6 +708,8 @@ __PACKAGE__->register_method({
 		my $conf = $param;
 		my $arch = PVE::QemuServer::get_vm_arch($conf);
 
+		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
+
 		my $vollist = [];
 		eval {
 		    $vollist = &$create_disks($rpcenv, $authuser, $conf, $arch, $storecfg, $vmid, $pool, $param, $storage);
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fbc0d46..8b98e69 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -286,6 +286,15 @@ my $rng_fmt = {
     },
 };
 
+my $meta_info_fmt = {
+    'ctime' => {
+	type => 'integer',
+	description => "The guest creation timestamp as UNIX epoch time",
+	minimum => 0,
+	optional => 1,
+    },
+};
+
 my $confdesc = {
     onboot => {
 	optional => 1,
@@ -707,6 +716,12 @@ EODESCR
 	description => "Configure a VirtIO-based Random Number Generator.",
 	optional => 1,
     },
+    meta => {
+	type => 'string',
+	format => $meta_info_fmt,
+	description => "Some (read-only) meta-information about this guest.",
+	optional => 1,
+    },
 };
 
 my $cicustom_fmt = {
@@ -2107,6 +2122,27 @@ 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(
+	{
+	    ctime => "". int(time()),
+	},
+	$meta_info_fmt
+    );
+}
+
 PVE::JSONSchema::register_format('pve-qm-usb-device', \&verify_usb_device);
 sub verify_usb_device {
     my ($value, $noerr) = @_;
@@ -2128,6 +2164,7 @@ sub json_config_properties {
 	vmstate => 1,
 	runningmachine => 1,
 	runningcpu => 1,
+	meta => 1,
     };
 
     foreach my $opt (keys %$confdesc) {
-- 
2.30.2





  reply	other threads:[~2021-11-03 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 15:58 [pve-devel] [PATCH v2 0/4] <add meta info and bandaid for QEMU 6.1 and unpinned q35 machine backward compat Thomas Lamprecht
2021-11-03 15:58 ` Thomas Lamprecht [this message]
2021-11-03 15:58 ` [pve-devel] [PATCH v2 2/4] config: meta: also save the QEMU version installed during creation Thomas Lamprecht
2021-11-03 15:58 ` [pve-devel] [PATCH v2 3/4] tests: cfg2cmd: add a few q35 related tests Thomas Lamprecht
2021-11-03 15:58 ` [pve-devel] [PATCH v2 4/4] cfg2cmd: switch off ACPI hotplug on bridges for q35 VMs Thomas Lamprecht
2021-11-04  8:05 ` [pve-devel] [PATCH v2 0/4] <add meta info and bandaid for QEMU 6.1 and unpinned q35 machine backward compat Dominik Csapak
2021-11-04 14:16 ` Wolfgang Bumiller
2021-11-04 14:33 ` [pve-devel] applied-series: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211103155812.1461208-2-t.lamprecht@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal