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 <d.csa...@proxmox.com>
---
changes from v2:
* adapt to load_profile name change

 src/PVE/API2/LXC.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 8839105..12a1439 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,19 @@ __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/guest-profile/${profile}", 
['Mapping.Use']);
+           my $profile_cfg = eval { 
PVE::Profiles::Plugin::load_profile($profile, 'ct') };
+           raise_param_exc({ profile => "$@" }) if $@;
+
+           for my $opt (keys $param->%*) {
+               $profile_cfg->{$opt} = $param->{$opt};
+           }
+
+           $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');
@@ -381,6 +403,7 @@ __PACKAGE__->register_method({
            my $vollist = [];
            eval {
                my $orig_mp_param; # only used if $restore
+               print "using profile '$profile'\n" if $profile;
                if ($restore) {
                    die "can't overwrite running container\n" if 
PVE::LXC::check_running($vmid);
                    if ($archive ne '-') {
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to