we use the profile cfg as the 'param' hash, but overwrite the values
with the ones from the api call, so one can overwrite options from
the profile easily

Signed-off-by: Dominik Csapak <[email protected]>
---
 src/PVE/API2/LXC.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 28d14de..e35f859 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -27,6 +27,10 @@ use PVE::API2::LXC::Config;
 use PVE::API2::LXC::Status;
 use PVE::API2::LXC::Snapshot;
 use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::Profiles::Plugin;
+use PVE::Profiles::CT;
+
 use base qw(PVE::RESTHandler);
 
 BEGIN {
@@ -196,6 +200,11 @@ __PACKAGE__->register_method({
                default => 0,
                description => "Start the CT after its creation finished 
successfully.",
            },
+           profile => {
+               optional => 1,
+               type => 'string',
+               description => "The profile to use as base config.",
+           },
        }),
     },
     returns => {
@@ -209,6 +218,21 @@ __PACKAGE__->register_method({
        my $rpcenv = PVE::RPCEnvironment::get();
        my $authuser = $rpcenv->get_user();
 
+       my $profile = extract_param($param, 'profile');
+       if (defined($profile)) {
+           $rpcenv->check_full($authuser, "/mapping/profiles/${profile}", 
['Mapping.Use']);
+           my $profile_cfgs = cfs_read_file('virtual-guest/profiles.cfg');
+           my $profile_cfg = $profile_cfgs->{ids}->{$profile};
+           die "no such profile '$profile'\n" if !defined($profile_cfg);
+           die "wrong type '$profile_cfg->{type}'\n" if $profile_cfg->{type} 
ne 'ct';
+
+           for my $opt (keys $param->%*) {
+               $profile_cfg->{$opt} = $param->{$opt};
+           }
+           delete $profile_cfg->{type};
+           $param = $profile_cfg;
+       }
+
        my $node = extract_param($param, 'node');
        my $vmid = extract_param($param, 'vmid');
        my $ignore_unpack_errors = extract_param($param, 
'ignore-unpack-errors');
-- 
2.30.2



_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to