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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9B34C6D240 for ; Wed, 31 Mar 2021 19:32:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8847612821 for ; Wed, 31 Mar 2021 19:32:24 +0200 (CEST) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A9AF812816 for ; Wed, 31 Mar 2021 19:32:21 +0200 (CEST) Received: by mail-wm1-x32c.google.com with SMTP id p19so10559716wmq.1 for ; Wed, 31 Mar 2021 10:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=odiso-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=sqtLBp4U+jR+QKkd0++5s0qEq7+wOKCF1GFzUPN4p5s=; b=MCUaPAl3e6+R3x+y6155z44FifnhwQAeEq+sIsYjS8yIH0q8+EFLt0murBGPrtF828 TiACcjeh8OMw5hRUQ6yZOljs8nRAzpGAGz+oH/gOD22509qsS85V5XH30gs63oI8b1Vz hOIU4A9uFzBlswPnvxgAPKKzod2y4TX+OvrbyF2OqjOoEcxMPiflYZpTwr1bq8ztY+Rk GCCYVo3Xzm65YWQ/0SUnuPKiCyKOLHXyCImrKWWdIshzTo16yyCBOP5fmo8ga79xzFz3 MDVNleAzx3n1s9TzqcRuqa/iEfwP/vd6AT/YK4cfe7VzJVL8bfQkYhv7opT5PmKOBmx2 aTFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=sqtLBp4U+jR+QKkd0++5s0qEq7+wOKCF1GFzUPN4p5s=; b=Jk5jDb2PKcpXjEAQ6SgfHoZLD2KuknPh6PZxI3qiDLe5254fPIc6DyHhLJd7nrGkOp uVE5sZx0BZsswzrPtnL9s3r++J97NDvODpi6Vup4GvKPbBWPUdb0FkzMC/i+iqgXz+eb Rjxl947QqyEzuppKCdevO8b0HIqkViqjIUJGuOhWynI3CTxm9bHc3Yh1Mhy6dBURk+Mi Q50fqZqqq9ioqT5twlyZxJc2HmarpOlxKq5O6vpjvEWQVNO7wzTEc3dnIMr0opesOYgx +KTyW0rWA3sjKC/Tj78eidYomUFlY/hHfkjHpx8N80xfYmPZIyrFBxUbbGInj8C0ZMAG +aRg== X-Gm-Message-State: AOAM5330qxj7XzpLiqGQcBXSgUZxlFe7fAferuJqkvwMc55S/nIv2Dez eaZifs+CSvHqosU7YmYicOpX/x36WWIAM8bDX/A= X-Google-Smtp-Source: ABdhPJw0FLcxtGwcYkJRMQgtqAewe269+WAG3vs310Voh6VSQqeB8sAuNif5Pyb8t8aYzwcymHwVvA== X-Received: by 2002:a1c:9d96:: with SMTP id g144mr4275123wme.46.1617211935133; Wed, 31 Mar 2021 10:32:15 -0700 (PDT) Received: from ?IPv6:2a0a:1580:0:1::100c? (ovpn1.odiso.net. [2a0a:1580:2000::3f]) by smtp.gmail.com with ESMTPSA id a4sm5605234wrx.86.2021.03.31.10.32.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Mar 2021 10:32:14 -0700 (PDT) Message-ID: <7e6302d05f4098b24891a1fc29e4654de51e47d5.camel@odiso.com> From: aderumier@odiso.com To: Proxmox VE development discussion Date: Wed, 31 Mar 2021 19:32:13 +0200 In-Reply-To: References: <20210328151203.2063706-1-aderumier@odiso.com> <20210328151203.2063706-5-aderumier@odiso.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.098 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qm.pm, proxmox.com, cloudinit.pm, qemu.pm] Subject: Re: [pve-devel] [PATCH qemu-server 4/6] api2: add cloudinit config api 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: Wed, 31 Mar 2021 17:32:24 -0000 hi, > Why do you add the macaddress here? I couldn't find anything in this > nor  > in the previous patch series explaining why this is done. This is mostly to show to user that config drive need to be regenereted. cloud-init agent use mac address to map ip to correct interface, so if you change mac address, you need to reload cloudnit. Another way could be to show net0 interface, but other attributes like vlan,bridge,..  don't have any effect on cloudnit and don't need any regenerate. Le mercredi 31 mars 2021 à 16:13 +0200, Mira Limbeck a écrit : > Why do you add the macaddress here? I couldn't find anything in this > nor > in the previous patch series explaining why this is done. > > On 3/28/21 5:12 PM, Alexandre Derumier wrote: > > --- > >   PVE/API2/Qemu.pm            | 73 > > +++++++++++++++++++++++++++++++++++++ > >   PVE/CLI/qm.pm               |  1 + > >   PVE/QemuServer/Cloudinit.pm | 70 > > +++++++++++++++++++++++++++++++++++ > >   3 files changed, 144 insertions(+) > > > > diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm > > index ea74c69..b6122fe 100644 > > --- a/PVE/API2/Qemu.pm > > +++ b/PVE/API2/Qemu.pm > > @@ -21,6 +21,7 @@ use PVE::ReplicationConfig; > >   use PVE::GuestHelpers; > >   use PVE::QemuConfig; > >   use PVE::QemuServer; > > +use PVE::QemuServer::Cloudinit; > >   use PVE::QemuServer::Drive; > >   use PVE::QemuServer::CPUConfig; > >   use PVE::QemuServer::Monitor qw(mon_cmd); > > @@ -1039,6 +1040,78 @@ __PACKAGE__->register_method({ > >         return PVE::GuestHelpers::config_with_pending_array($conf, > > $pending_delete_hash); > >      }}); > >   > > +__PACKAGE__->register_method({ > > +    name => 'cloudinit_pending', > > +    path => '{vmid}/cloudinit', > > +    method => 'GET', > > +    proxyto => 'node', > > +    description => "Get the cloudinit configuration with both > > current and pending values.", > > +    permissions => { > > +       check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]], > > +    }, > > +    parameters => { > > +       additionalProperties => 0, > > +       properties => { > > +           node => get_standard_option('pve-node'), > > +           vmid => get_standard_option('pve-vmid', { completion => > > \&PVE::QemuServer::complete_vmid }), > > +       }, > > +    }, > > +    returns => { > > +       type => "array", > > +       items => { > > +           type => "object", > > +           properties => { > > +               key => { > > +                   description => "Configuration option name.", > > +                   type => 'string', > > +               }, > > +               value => { > > +                   description => "Current value.", > > +                   type => 'string', > > +                   optional => 1, > > +               }, > > +               pending => { > > +                   description => "Pending value.", > > +                   type => 'string', > > +                   optional => 1, > > +               }, > > +               delete => { > > +                   description => "Indicates a pending delete > > request if present and not 0. " . > > +                                  "The value 2 indicates a force- > > delete request.", > > +                   type => 'integer', > > +                   minimum => 0, > > +                   maximum => 2, > > +                   optional => 1, > > +               }, > > +           }, > > +       }, > > +    }, > > +    code => sub { > > +       my ($param) = @_; > > + > > +       my $vmid = $param->{vmid}; > > +       my $conf = PVE::QemuConfig->load_config($vmid); > > + > > +       if( defined($conf->{cipassword}) && > > +           defined($conf->{cloudinit}->{cipassword}) && > > +           $conf->{cipassword} ne $conf->{cloudinit}- > > >{cipassword}) { > > +           $conf->{cipassword} = '********** '; > > +       } elsif (defined($conf->{cipassword})) { > > +           $conf->{cipassword} = '**********'; > > +       } > > + > > +       $conf->{cloudinit}->{cipassword} = '**********' if > > defined($conf->{cloudinit}->{cipassword}); > > + > > +       my $res = []; > > +       my $pending = > > PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid); > > + > > +       foreach my $opt (keys %{$pending}) { > > +           push @$res, $pending->{$opt}; > > +       } > > + > > +       return $res; > > +   }}); > > + > >   # POST/PUT {vmid}/config implementation > >   # > >   # The original API used PUT (idempotent) an we assumed that all > > operations > > diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm > > index f8972bd..e24b832 100755 > > --- a/PVE/CLI/qm.pm > > +++ b/PVE/CLI/qm.pm > > @@ -996,6 +996,7 @@ our $cmddef = { > >                 my $data = shift; > >                 print "$data\n"; > >             }], > > +       pending => [ "PVE::API2::Qemu", 'cloudinit_pending', > > ['vmid'], { node => $nodename }, > > \&PVE::GuestHelpers::format_pending ] > >       }, > >   > >   }; > > diff --git a/PVE/QemuServer/Cloudinit.pm > > b/PVE/QemuServer/Cloudinit.pm > > index f4bf925..20cf583 100644 > > --- a/PVE/QemuServer/Cloudinit.pm > > +++ b/PVE/QemuServer/Cloudinit.pm > > @@ -629,4 +629,74 @@ sub dump_cloudinit_config { > >       } > >   } > >   > > +sub get_pending_config { > > +    my ($conf, $vmid) = @_; > > + > > +    my $newconf = { %{$conf} }; > > +    my $cloudinit_current = $newconf->{cloudinit}; > > +    my @cloudinit_opts = keys > > %{PVE::QemuServer::cloudinit_config_properties()}; > > +    push @cloudinit_opts, 'name'; > > + > > +    #add cloud-init drive > > +    my $drives = {}; > > +    PVE::QemuConfig->foreach_volume($newconf, sub { > > +       my ($ds, $drive) = @_; > > +       $drives->{$ds} = 1 if > > PVE::QemuServer::drive_is_cloudinit($drive); > > +    }); > > + > > +    PVE::QemuConfig->foreach_volume($cloudinit_current, sub { > > +       my ($ds, $drive) = @_; > > +       $drives->{$ds} = 1 if > > PVE::QemuServer::drive_is_cloudinit($drive); > > +    }); > > +    foreach my $ds (keys %{$drives}) { > > +       push @cloudinit_opts, $ds; > > +    } > > + > > +    $newconf->{name} = "VM$vmid" if !$newconf->{name}; > > + > > +    my $print_net_addr = sub { > > +       my ($conf, $opt, $netid) = @_; > > + > > +       if (defined($conf->{$netid})) { > > + > > +           my $net = PVE::QemuServer::parse_net($conf->{$netid}); > > +           if (defined($conf->{$opt})) { > > +               $conf->{$opt} .= ",macaddr=".$net->{macaddr} if > > $net->{macaddr}; > > +           } else { > > +               $conf->{$opt} = ""; > > +           } > > +       } > > +    }; > > + > > +    my $res = {}; > > +    foreach my $opt (@cloudinit_opts) { > > + > > +       #add macaddr to ipconfig > > +       if ($opt =~ m/^ipconfig(\d+)/) { > > +           my $netid = "net$1"; > > +           next if !defined($newconf->{$netid}) && > > !defined($cloudinit_current->{$netid}) && !defined($newconf- > > >{$opt}) && !defined($cloudinit_current->{$opt} ); > > + > > +           &$print_net_addr($newconf, $opt, $netid); > > +           &$print_net_addr($cloudinit_current, $opt, $netid); > > +       } > > + > > +       my $item = { > > +           key => $opt, > > +       }; > > +       if ($cloudinit_current->{$opt}) { > > +           $item->{value} = $cloudinit_current->{$opt}; > > +           if ($newconf->{$opt}) { > > +               $item->{pending} = $newconf->{$opt} if $newconf- > > >{$opt} ne $cloudinit_current->{$opt}; > > +           } else { > > +               $item->{delete} = 1; > > +           } > > +       } else { > > +           $item->{pending} = $newconf->{$opt} if $newconf->{$opt} > > +       } > > + > > +       $res->{$opt} = $item; > > +   } > > +   return $res; > > +} > > + > >   1; > > > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >