qemu-server/PVE/QemuServer/MetaInfo.pm
Fiona Ebner 8c4f436b3c move meta information handling to its own module
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>
2025-01-17 19:24:02 +01:00

48 lines
933 B
Perl

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;