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 1188999798 for ; Tue, 14 Nov 2023 11:36:18 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E6BF51E215 for ; Tue, 14 Nov 2023 11:35:47 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 14 Nov 2023 11:35:46 +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 5FE4F42876 for ; Tue, 14 Nov 2023 11:35:46 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Tue, 14 Nov 2023 11:35:38 +0100 Message-Id: <20231114103545.2878054-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231114103545.2878054-1-d.csapak@proxmox.com> References: <20231114103545.2878054-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.017 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH guest-common v2 1/1] add profiles section config plugin 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: Tue, 14 Nov 2023 10:36:18 -0000 this is intended to house custom profiles which can be used on guest creation instead of manually needing to specify every option. we do special things here: * we always set 'allow_unknown' to 1, because when using the guest specific parts in the cli, we cannot depend on the other one, else we'd get a cyclic dependency, and without that we need to ignore unknown sections * we pack the type and id in the global options, so that when using it with a seperated section config they get included in the create/updateSchema Signed-off-by: Dominik Csapak --- src/Makefile | 2 ++ src/PVE/Profiles/Plugin.pm | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/PVE/Profiles/Plugin.pm diff --git a/src/Makefile b/src/Makefile index cbc40c1..d99645c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,6 +17,8 @@ install: PVE install -d ${PERL5DIR}/PVE/Mapping install -m 0644 PVE/Mapping/PCI.pm ${PERL5DIR}/PVE/Mapping/ install -m 0644 PVE/Mapping/USB.pm ${PERL5DIR}/PVE/Mapping/ + install -d ${PERL5DIR}/PVE/Profiles + install -m 0644 PVE/Profiles/Plugin.pm ${PERL5DIR}/PVE/Profiles/ install -d ${PERL5DIR}/PVE/VZDump install -m 0644 PVE/VZDump/Plugin.pm ${PERL5DIR}/PVE/VZDump/ install -m 0644 PVE/VZDump/Common.pm ${PERL5DIR}/PVE/VZDump/ diff --git a/src/PVE/Profiles/Plugin.pm b/src/PVE/Profiles/Plugin.pm new file mode 100644 index 0000000..6ea2b5f --- /dev/null +++ b/src/PVE/Profiles/Plugin.pm @@ -0,0 +1,74 @@ +package PVE::Profiles::Plugin; + +use strict; +use warnings; + +use PVE::Cluster qw(cfs_register_file); +use PVE::SectionConfig; + +use base qw(PVE::SectionConfig); + +my $CFG_PATH = 'virtual-guest/profiles.cfg'; + +cfs_register_file ($CFG_PATH, + sub { __PACKAGE__->parse_config(@_); }, + sub { __PACKAGE__->write_config(@_); }); + +my $defaultData = { + propertyList => { + type => { description => 'Profile type.' }, + id => { + type => 'string', + description => "The ID of the profile.", + format => 'pve-configid', + }, + 'profile-description' => { + description => "Description.", + type => 'string', + optional => 1, + maxLength => 4096, + }, + }, + options => { + type => {}, + id => {}, + 'profile-description' => { optional => 1 }, + }, +}; + +sub private { + return $defaultData; +} + +sub parse_config { + my ($class, $filename, $raw, $allow_unknown) = @_; + + # always allow unknown, so that qemu-server/pct-container + # can parse the file without loading the other plugin type + return $class->SUPER::parse_config($filename, $raw, 1); +} + +sub write_config { + my ($class, $filename, $cfg, $allow_unknown) = @_; + + return $class->SUPER::write_config($filename, $cfg, 1); +} + +# gets, checks and prepares the guest config +# throws an error if it does not exist or the type is wrong +sub get_guest_ready_config { + my ($id, $type) = @_; + + my $cfg = PVE::Cluster::cfs_read_file($CFG_PATH); + + my $profile = $cfg->{ids}->{$id}; + die "no such profile '$id'\n" if !defined $profile; + die "wrong type '$profile->{type}'\n" if $profile->{type} ne $type; + + delete $profile->{type}; + delete $profile->{'profile-description'}; + + return $profile; +} + +1; -- 2.30.2