[pve-devel] [PATCH manager 03/12] API: add node address(es) API endpoint
Fabian Grünbichler
f.gruenbichler at proxmox.com
Wed Nov 6 13:37:07 CET 2019
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
naming is not my forte - better recommendations welcome ;)
PVE/API2/Nodes.pm | 72 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 715c8563..ae408dcc 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -48,6 +48,7 @@ use Digest::MD5;
use Digest::SHA;
use PVE::API2::Disks;
use PVE::DataCenterConfig;
+use PVE::Network;
use JSON;
use Socket;
@@ -211,6 +212,7 @@ __PACKAGE__->register_method ({
{ name => 'certificates' },
{ name => 'config' },
{ name => 'hosts' },
+ { name => 'addr' },
];
return $result;
@@ -2072,6 +2074,76 @@ __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 IP address(es) of node in various networks.",
+ 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 IPs.',
+ 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});
+ $data->{default} = $default if defined($default);
+
+ my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ if (my $migration_network = $dc_conf->{migration}->{network}) {
+ my $ips = PVE::Network::get_local_ip_from_cidr($migration_network);
+ $data->{migration} = @$ips[0] if scalar($ips) == 1;
+ }
+
+ $data->{extra} = PVE::Network::get_local_ip_from_cidr($param->{cidr})
+ if $param->{cidr};
+
+ return $data;
+ }});
+
# bash completion helper
sub complete_templet_repo {
--
2.20.1
More information about the pve-devel
mailing list