[pve-devel] [PATCH manager] API: add node address(es) API endpoint
Fabian Grünbichler
f.gruenbichler at proxmox.com
Fri Mar 6 11:20:31 CET 2020
Signed-off-by: Fabian Grünbichler <f.gruenbichler at 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 58497b2b..206fc423 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -241,6 +241,7 @@ __PACKAGE__->register_method ({
{ name => 'certificates' },
{ name => 'config' },
{ name => 'hosts' },
+ { name => 'addr' },
];
push @$result, { name => 'sdn' } if $have_sdn;
@@ -2147,6 +2148,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
More information about the pve-devel
mailing list