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 168EF7391B for ; Fri, 16 Apr 2021 12:18:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0168B23365 for ; Fri, 16 Apr 2021 12:17:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id 5B4C82335B for ; Fri, 16 Apr 2021 12:17:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1E42F458BD for ; Fri, 16 Apr 2021 12:17:50 +0200 (CEST) Message-ID: <6d9ddd05-4a58-dcdd-3a3a-988708fd97dd@proxmox.com> Date: Fri, 16 Apr 2021 12:17:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Thunderbird/88.0 Content-Language: en-US To: Proxmox VE development discussion , =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= References: <20210413121640.3602975-1-f.gruenbichler@proxmox.com> <20210413121640.3602975-15-f.gruenbichler@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20210413121640.3602975-15-f.gruenbichler@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -0.040 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium 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. [nodes.pm] Subject: Re: [pve-devel] [PATCH manager] API: add node address(es) API endpoint 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: Fri, 16 Apr 2021 10:18:21 -0000 On 13.04.21 14:16, Fabian Gr=C3=BCnbichler wrote: > Signed-off-by: Fabian Gr=C3=BCnbichler > --- > PVE/API2/Nodes.pm | 70 +++++++++++++++++++++++++++++++++++++++++++++++= > 1 file changed, 70 insertions(+) >=20 > diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm > index ba6621c6..b30d0739 100644 > --- a/PVE/API2/Nodes.pm > +++ b/PVE/API2/Nodes.pm > @@ -222,6 +222,7 @@ __PACKAGE__->register_method ({ > my ($param) =3D @_; > =20 > my $result =3D [ > + { name =3D> 'addr' }, > { name =3D> 'aplinfo' }, > { name =3D> 'apt' }, > { name =3D> 'capabilities' }, > @@ -2183,6 +2184,75 @@ __PACKAGE__->register_method ({ > return undef; > }}); > =20 > +__PACKAGE__->register_method ({ > + name =3D> 'get_node_addr', > + path =3D> 'addr', hmm, not so sure if this the best path choice, if network wouldn't be tem= plated by the {iface} param that would be a better choice to avoid crowding here. I pondered over moving that one a level deeper to network/if/{name} for a=20 major releas, and mode some things like netstat, possible even dns, under there - but i= t's work and the gain was rather small - with this call which could fit there ROI woul= d be slightly bigger, but not too sure if worth it, just throwing out the idea there. Besides that, the name could be slightly more descriptive `ip-addr` or ev= en=20 ip-addresses`? > + method =3D> 'GET', > + proxyto =3D> 'node', > + permissions =3D> { > + check =3D> ['perm', '/', [ 'Sys.Audit' ]], why not `/nodes/{node}` ? > + }, > + description =3D> "Get the content of /etc/hosts.", above is wrong? probably left-over from copying? > + parameters =3D> { > + additionalProperties =3D> 0, > + properties =3D> { > + node =3D> get_standard_option('pve-node'), > + cidr =3D> { > + type =3D> 'string', > + format =3D> 'CIDR', > + format_description =3D> 'CIDR', > + description =3D> 'Extra network for which to retrieve local address(= es).', > + optional =3D> 1, > + }, > + }, > + }, > + returns =3D> { > + type =3D> 'object', > + properties =3D> { > + default =3D> { > + type =3D> 'string', > + description =3D> 'Default node IP.', > + format =3D> 'ip', > + }, > + migration =3D> { > + type =3D> 'array', > + items =3D> { > + type =3D> 'string', > + description =3D> 'Migration network IP(s).', > + format =3D> 'ip', > + }, > + optional =3D> 1, > + }, > + extra =3D> { > + type =3D> 'array', > + items =3D> { > + type =3D> 'string', > + description =3D> 'Extra network IP(s).', > + format =3D> 'ip', > + }, > + optional =3D> 1, > + }, > + }, > + }, > + code =3D> sub { > + my ($param) =3D @_; > + > + my $data =3D {}; > + > + my $default =3D PVE::Cluster::remote_node_ip($param->{node}); > + > + my $dc_conf =3D cfs_read_file('datacenter.cfg'); > + my $migration =3D $dc_conf->{migration}->{network}; > + > + $data->{default} =3D $default if defined($default); > + $data->{migration} =3D PVE::Network::get_local_ip_from_cidr($migratio= n, 1) > + if $migration; style nit, probably opinionated and thus really no hard feelings, but may= be the following is lightly more legible due to declaration being nearer to usag= e: if (my $default =3D PVE::Cluster::remote_node_ip($param->{node}) { $data->{default} =3D $default; } my $dc_conf =3D cfs_read_file('datacenter.cfg'); if (my $migration =3D $dc_conf->{migration}->{network}) { $data->{migration} =3D PVE::Network::get_local_ip_from_cidr($migratio= n, 1); } if (my $cidr =3D $param->{cidr}) { $data->{extra} =3D PVE::Network::get_local_ip_from_cidr($param->{cidr= }, 1) } > + $data->{extra} =3D PVE::Network::get_local_ip_from_cidr($param->{cidr= }, 1) > + if $param->{cidr}; > + > + return $data; > + }}); > + > # bash completion helper > =20 > sub complete_templet_repo { >=20