public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>,
	"Fabian Grünbichler" <f.gruenbichler@proxmox.com>
Subject: Re: [pve-devel] [PATCH manager] API: add node address(es) API endpoint
Date: Fri, 16 Apr 2021 12:17:49 +0200	[thread overview]
Message-ID: <6d9ddd05-4a58-dcdd-3a3a-988708fd97dd@proxmox.com> (raw)
In-Reply-To: <20210413121640.3602975-15-f.gruenbichler@proxmox.com>

On 13.04.21 14:16, Fabian Grünbichler wrote:
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
>  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',

hmm, not so sure if this the best path choice, if network wouldn't be templated 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 
major releas,
and mode some things like netstat, possible even dns, under there - but it's work and
the gain was rather small - with this call which could fit there ROI would 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 even 
ip-addresses`?

> +    method => 'GET',
> +    proxyto => 'node',
> +    permissions => {
> +	check => ['perm', '/', [ 'Sys.Audit' ]],

why not `/nodes/{node}` ?

> +    },
> +    description => "Get the content of /etc/hosts.",

above is wrong? probably left-over from copying?

> +    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;

style nit, probably opinionated and thus really no hard feelings, but maybe the
following is lightly more legible due to declaration being nearer to usage:

if (my $default = PVE::Cluster::remote_node_ip($param->{node}) {
    $data->{default} = $default;
}

my $dc_conf = cfs_read_file('datacenter.cfg');
if (my $migration = $dc_conf->{migration}->{network}) {
    $data->{migration} = PVE::Network::get_local_ip_from_cidr($migration, 1);
}

if (my $cidr = $param->{cidr}) {
    $data->{extra} = PVE::Network::get_local_ip_from_cidr($param->{cidr}, 1)
}

> +	$data->{extra} = PVE::Network::get_local_ip_from_cidr($param->{cidr}, 1)
> +	    if $param->{cidr};
> +
> +	return $data;
> +    }});
> +
>  # bash completion helper
>  
>  sub complete_templet_repo {
> 





  reply	other threads:[~2021-04-16 10:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 12:16 [pve-devel] [RFC qemu-server++ 0/22] remote migration Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH proxmox 1/2] websocket: make field public Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH proxmox 2/2] websocket: adapt for client connection Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH proxmox-websocket-tunnel 1/2] initial commit Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH proxmox-websocket-tunnel 2/2] add tunnel implementation Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH access-control 1/2] tickets: add tunnel ticket Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH access-control 2/2] ticket: normalize path for verification Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH cluster 1/4] remote.cfg: add new config file Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH cluster 2/4] add get_remote_info Fabian Grünbichler
2021-04-18 17:07   ` Thomas Lamprecht
2021-04-19  7:48     ` Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH cluster 3/4] remote: add option/completion Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH cluster 4/4] get_remote_info: also return FP if available Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH common 1/2] schema: pull out abstract 'id-pair' verifier Fabian Grünbichler
2021-04-16 10:24   ` [pve-devel] applied: " Thomas Lamprecht
2021-04-19  8:43     ` [pve-devel] [PATCH common] fixup: remove double braces Stefan Reiter
2021-04-19  9:56       ` [pve-devel] applied: " Thomas Lamprecht
2021-04-13 12:16 ` [pve-devel] [PATCH common 2/2] schema: add pve-bridge-id option/format/pair Fabian Grünbichler
2021-04-16  9:53   ` Thomas Lamprecht
2021-04-16 10:10     ` Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH guest-common] migrate: handle migration_network with remote migration Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH manager] API: add node address(es) API endpoint Fabian Grünbichler
2021-04-16 10:17   ` Thomas Lamprecht [this message]
2021-04-16 11:37     ` Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH storage] import: allow import from UNIX socket Fabian Grünbichler
2021-04-16 10:24   ` [pve-devel] applied: " Thomas Lamprecht
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 1/7] migrate: factor out storage checks Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 2/7] refactor map_storage to map_id Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 3/7] schema: use pve-bridge-id Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 4/7] mtunnel: add API endpoints Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 5/7] migrate: refactor remote VM/tunnel start Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 6/7] migrate: add remote migration handling Fabian Grünbichler
2021-04-13 12:16 ` [pve-devel] [PATCH qemu-server 7/7] api: add remote migrate endpoint Fabian Grünbichler
2021-04-15 14:04 ` [pve-devel] [RFC qemu-server++ 0/22] remote migration alexandre derumier
2021-04-15 14:32   ` Fabian Grünbichler
2021-04-15 14:36     ` Thomas Lamprecht
2021-04-15 16:38     ` Moula BADJI
2021-05-05  6:02       ` aderumier
2021-05-05  9:22         ` Dominik Csapak
2021-04-16  7:36     ` alexandre derumier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d9ddd05-4a58-dcdd-3a3a-988708fd97dd@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal