From e7fb6ff270f833412f7fdc753e170e68b0041656 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 21 May 2014 08:24:07 +0200 Subject: [PATCH] add new localnet command Print information about local network (IP/NETWORK/NODENAME). --- src/pve-firewall | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/pve-firewall b/src/pve-firewall index 49b45cb..91fc531 100755 --- a/src/pve-firewall +++ b/src/pve-firewall @@ -379,6 +379,40 @@ __PACKAGE__->register_method ({ return undef; }}); +__PACKAGE__->register_method ({ + name => 'localnet', + path => 'localnet', + method => 'GET', + description => "Print information about local network.", + parameters => { + additionalProperties => 0, + properties => {}, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + local $SIG{'__WARN__'} = 'DEFAULT'; # do not fill up syslog + + my $nodename = PVE::INotify::nodename(); + print "local hostname: $nodename\n"; + + my $ip = PVE::Cluster::remote_node_ip($nodename); + print "local IP address: $ip\n"; + + my $cluster_conf = PVE::Firewall::load_clusterfw_conf(); + + my $localnet = PVE::Firewall::local_network() || '127.0.0.0/8'; + print "network auto detect: $localnet\n"; + if ($cluster_conf->{aliases}->{local_network}) { + print "using user defined local_network: $cluster_conf->{aliases}->{local_network}->{cidr}\n"; + } else { + print "using detected local_network: $localnet\n"; + } + + return undef; + }}); + __PACKAGE__->register_method ({ name => 'simulate', path => 'simulate', @@ -497,6 +531,7 @@ my $cmddef = { stop => [ __PACKAGE__, 'stop', []], compile => [ __PACKAGE__, 'compile', []], simulate => [ __PACKAGE__, 'simulate', []], + localnet => [ __PACKAGE__, 'localnet', []], status => [ __PACKAGE__, 'status', [], undef, sub { my $res = shift; if ($res->{changes}) { -- 2.39.2