From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 559797BFE6 for ; Wed, 3 Nov 2021 16:58:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 41EFC17115 for ; Wed, 3 Nov 2021 16:58:22 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 054A0170EC for ; Wed, 3 Nov 2021 16:58:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D1E404603F for ; Wed, 3 Nov 2021 16:58:20 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Date: Wed, 3 Nov 2021 16:58:09 +0100 Message-Id: <20211103155812.1461208-2-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211103155812.1461208-1-t.lamprecht@proxmox.com> References: <20211103155812.1461208-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.176 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemu.pm, qemuserver.pm] Subject: [pve-devel] [PATCH v2 1/4] config: add new meta property withe creation time X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 15:58:22 -0000 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 --- 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