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 6CDD072AE7 for ; Tue, 13 Apr 2021 14:17:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 43AD52A959 for ; Tue, 13 Apr 2021 14:16:57 +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 C94232A803 for ; Tue, 13 Apr 2021 14:16:54 +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 9329445A72 for ; Tue, 13 Apr 2021 14:16:54 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 13 Apr 2021 14:16:32 +0200 Message-Id: <20210413121640.3602975-15-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210413121640.3602975-1-f.gruenbichler@proxmox.com> References: <20210413121640.3602975-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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: [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: Tue, 13 Apr 2021 12:17:27 -0000 Signed-off-by: Fabian Grünbichler --- PVE/API2/Nodes.pm | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) 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) = @_; my $result = [ + { name => 'addr' }, { name => 'aplinfo' }, { name => 'apt' }, { name => 'capabilities' }, @@ -2183,6 +2184,75 @@ __PACKAGE__->register_method ({ return undef; }}); +__PACKAGE__->register_method ({ + name => 'get_node_addr', + path => 'addr', + method => 'GET', + proxyto => 'node', + permissions => { + check => ['perm', '/', [ 'Sys.Audit' ]], + }, + description => "Get the content of /etc/hosts.", + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + cidr => { + type => 'string', + format => 'CIDR', + format_description => 'CIDR', + description => 'Extra network for which to retrieve local address(es).', + optional => 1, + }, + }, + }, + returns => { + type => 'object', + properties => { + default => { + type => 'string', + description => 'Default node IP.', + format => 'ip', + }, + migration => { + type => 'array', + items => { + type => 'string', + description => 'Migration network IP(s).', + format => 'ip', + }, + optional => 1, + }, + extra => { + type => 'array', + items => { + type => 'string', + description => 'Extra network IP(s).', + format => 'ip', + }, + optional => 1, + }, + }, + }, + code => sub { + my ($param) = @_; + + my $data = {}; + + my $default = PVE::Cluster::remote_node_ip($param->{node}); + + my $dc_conf = cfs_read_file('datacenter.cfg'); + my $migration = $dc_conf->{migration}->{network}; + + $data->{default} = $default if defined($default); + $data->{migration} = PVE::Network::get_local_ip_from_cidr($migration, 1) + if $migration; + $data->{extra} = PVE::Network::get_local_ip_from_cidr($param->{cidr}, 1) + if $param->{cidr}; + + return $data; + }}); + # bash completion helper sub complete_templet_repo { -- 2.20.1