config: add new meta property with the VM creation time

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>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-10-21 09:10:49 +02:00
parent 115cb432bc
commit 26b443c846
2 changed files with 39 additions and 0 deletions

View File

@ -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);

View File

@ -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 = {
@ -2115,6 +2130,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) = @_;
@ -2136,6 +2172,7 @@ sub json_config_properties {
vmstate => 1,
runningmachine => 1,
runningcpu => 1,
meta => 1,
};
foreach my $opt (keys %$confdesc) {