pf-tools/pf-tools: 3 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Sep 12 13:33:21 UTC 2014
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e3bf5efb1194
changeset: 1329:e3bf5efb1194
user: shad
date: Thu Sep 11 18:10:36 2014 +0200
description:
compile
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/aa9224166f8b
changeset: 1330:aa9224166f8b
user: shad
date: Fri Sep 12 14:33:25 2014 +0200
description:
style
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/7b9779ade096
changeset: 1331:7b9779ade096
user: shad
date: Fri Sep 12 15:33:15 2014 +0200
description:
simple dump work again, site option taken into account, fix read and host options
diffstat:
tools/Display_IP_config | 158 ++++++++++++++++++++++-------------------------
1 files changed, 74 insertions(+), 84 deletions(-)
diffs (309 lines):
diff -r 128869957697 -r 7b9779ade096 tools/Display_IP_config
--- a/tools/Display_IP_config Tue Sep 02 13:41:53 2014 +0200
+++ b/tools/Display_IP_config Fri Sep 12 15:33:15 2014 +0200
@@ -1,7 +1,7 @@
#!/usr/bin/perl
#
+# Copyright (C) 2004-2014 Stephane Pontier <shad at sitadelle.com>
# Copyright (C) 2008-2010 Christophe Caillet <quadchris at free.fr>
-# Copyright (C) 2004 Stephane Pontier <shad at sitadelle.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -25,6 +25,7 @@
use strict;
use warnings;
+use Carp;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use File::Basename;
use Getopt::Long qw ( :config ignore_case_always bundling );
@@ -37,18 +38,13 @@
# Vars
my @options_specs = (
- 'help',
- 'read',
- 'host|h=s',
- 'type|t=s',
- 'config|c=s',
- 'store=s',
- 'output|o=s',
+ 'help', 'host|h=s', 'site|s=s', 'type|t=s',
+ 'output|o=s', 'read', 'store=s', 'config|c=s',
);
my $options = {
- 'type' => 'ipv4',
- 'output' => '-',
+ 'type' => q{ipv4},
+ 'output' => q{-},
};
my $PF_CONFIG = {};
@@ -59,26 +55,27 @@
######################################################
# Functions
-sub Do_help () {
- print STDERR << "# ENDHELP";
+sub do_help {
+ print {*STDERR} << "ENDHELP";
Usage: $program [options]
- --help : print help and exit
- -h --host : the hostclass or hostname for which you want to display configuration
- -s --site : the site where the hostname is defined
+ --help : print help and exit
+ -h --host : the hostclass for which you want to display configuration
+ -s --site : the site that will be dump
-t --type : IP type (ipv4 or ipv6)
-o --output : destination
- --read : display result in "human readable" format
+ --read : display result in "human readable" format
--store : path for accessing storable file containing the global configuration
-c --config : path for accessing pf-tools.conf file
-# ENDHELP
+ENDHELP
+ return;
}
sub _ipcomp {
my ( $ip1, $ip2 ) = @_;
- my $ip_obj1 = new NetAddr::IP($ip1);
- my $ip_obj2 = new NetAddr::IP($ip2);
+ my $ip_obj1 = NetAddr::IP->new($ip1);
+ my $ip_obj2 = NetAddr::IP->new($ip2);
if ( $ip_obj1 < $ip_obj2 ) {
return -1;
@@ -96,14 +93,14 @@
next if ( ref $host_part->{$hostclass} ne 'HASH' );
foreach my $hostname ( keys %{ $host_part->{$hostclass} } ) {
next if ( ref $host_part->{$hostclass}->{$hostname} ne 'HASH' );
- my $srv_order =
- $host_part->{$hostclass}->{$hostname}->{'deployment'}
+ my $srv_order
+ = $host_part->{$hostclass}->{$hostname}->{'deployment'}
->{'order'}
|| 999;
if ( !$order->{$srv_order}->{$hostclass} ) {
$order->{$srv_order}->{$hostclass} = [];
}
- push( @{ $order->{$srv_order}->{$hostclass} }, $hostname );
+ push @{ $order->{$srv_order}->{$hostclass} }, $hostname;
}
}
return $order;
@@ -113,7 +110,7 @@
my ( $ip_type, $srv_name, $host_props ) = @_;
my $result = {};
- return undef if ( !$PF_CONFIG->{'features'}->{$ip_type} );
+ return if ( !$PF_CONFIG->{'features'}->{$ip_type} );
foreach my $iface ( keys %{ $host_props->{'interfaces'} } ) {
$result->{$iface}->{'addr'}
= $host_props->{'interfaces'}->{$iface}->{$ip_type};
@@ -127,13 +124,14 @@
my ( $ip_type, $hostclass, $host_part, $pf_config ) = @_;
my $result = {};
- return undef if ( !$pf_config->{'features'}->{$ip_type} );
- foreach my $srv ( keys %{ $host_part->{$hostclass} } ) {
- my $ref_srv = $$host_part->{$hostclass}->{$srv};
+ return if ( !$pf_config->{'features'}->{$ip_type} );
+ foreach my $srv ( keys %{$host_part} ) {
+ my $ref_srv = $host_part->{$srv};
+ next if !ref $ref_srv;
foreach my $iface ( keys %{ $ref_srv->{'interfaces'} } ) {
my $ip_if = $ref_srv->{'interfaces'}->{$iface}->{$ip_type};
$result->{$ip_if}->{'hostname'} = $srv;
- $result->{$ip_if}->{'iface'} = $$iface;
+ $result->{$ip_if}->{'iface'} = $iface;
}
}
return $result;
@@ -143,22 +141,19 @@
my ( $ip_type, $host_part, $pf_config ) = @_;
my $result = {};
- return undef if ( !$pf_config->{'features'}->{$ip_type} );
+ return if ( !$pf_config->{'features'}->{$ip_type} );
foreach my $hostclass ( keys %{$host_part} ) {
foreach my $srv ( keys %{ $host_part->{$hostclass} } ) {
my $ref_srv = $host_part->{$hostclass}->{$srv};
+ next if !ref $ref_srv;
foreach my $iface ( keys %{ $ref_srv->{'interfaces'} } ) {
my $entry = {
'hostname' => $srv,
'iface' => $iface
};
- push(
- @{ $result->{
- $ref_srv->{'interfaces'}->{$iface}->{$ip_type}
- }
- },
- $entry
- );
+ push @{ $result->{ $ref_srv->{'interfaces'}->{$iface}
+ ->{$ip_type} } },
+ $entry;
}
}
}
@@ -169,29 +164,25 @@
### MAIN
GetOptions( $options, @options_specs )
- or die "Didn't grok options (see --help).\n";
+ or croak "Didn't grok options (see --help).\n";
if ( $options->{'help'} ) {
- Do_help();
+ do_help();
exit 0;
}
-( $PF_CONFIG, $GLOBAL_STRUCT ) = init_tools(
- "",
- $options->{'config'},
- $options->{'store'}
-);
+( $PF_CONFIG, $GLOBAL_STRUCT )
+ = init_tools( q{}, $options->{'config'}, $options->{'store'} );
-unless ( $options->{'site'} ) {
- unless ( $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = get_site_list_from_hostname(
- $options->{'host'}, $GLOBAL_STRUCT
- );
- unless ($site_list) {
- die qq{ERROR: Unknown hostclass $options->{'host'}};
+if ( !$options->{'site'} ) {
+ if ( !$PF_CONFIG->{'location'}->{'site'} ) {
+ my $site_list = get_site_list_from_hostname( $options->{'host'},
+ $GLOBAL_STRUCT );
+ if ( !$site_list ) {
+ croak qq{ERROR: Unknown hostclass $options->{'host'}};
}
if ( scalar @{$site_list} > 1 ) {
- die qq{ERROR: Multiple sites for hostclass $options->{'host'}};
+ croak qq{ERROR: Multiple sites for hostclass $options->{'host'}};
}
( $options->{'site'} ) = @{$site_list};
}
@@ -199,15 +190,14 @@
}
my $site_ref = get_site_config( $options->{'site'}, $GLOBAL_STRUCT );
-my $host_part = $site_ref->->{'HOST'}->{'BY_NAME'};
+my $host_part = $site_ref->{'HOST'}->{'BY_NAME'};
-if (
- defined $options->{'host'}
- && $options->{'host'} ne ""
- && !defined $host_part->{ $options->{'host'} }
- )
+if ( defined $options->{'host'}
+ && $options->{'host'} ne q{}
+ && !defined $host_part->{ $options->{'host'} } )
{
- die "Unexistant hostclass in global configuration";
+ croak
+ qq{Unexistant hostclass $options->{host} in site $options->{'site'} configuration};
}
if ( $options->{'host'} ) {
if ( $options->{'read'} ) {
@@ -220,16 +210,14 @@
}
else {
print "\t" . $hostname . "\n";
- my $srv_net = get_srv_iface(
- $options->{'type'}, $hostname,
- $host_part->{ $options->{'host'} }->{$hostname}
- );
+ my $srv_net = get_srv_iface( $options->{'type'}, $hostname,
+ $host_part->{ $options->{'host'} }->{$hostname} );
if ( !defined $srv_net ) {
- die "IP feature $options->{'type'} is deactivated";
+ croak "IP feature $options->{'type'} is deactivated";
}
foreach my $iface ( sort keys %{$srv_net} ) {
print "\t\t"
- . $iface . "("
+ . $iface . q{(}
. $srv_net->{$iface}->{'vlan'} . ")\t: "
. $srv_net->{$iface}->{'addr'} . "\n";
}
@@ -237,14 +225,17 @@
}
}
else {
- my $srv_ip = get_srv_ip(
- $options->{'type'}, $options->{'host'},
- $host_part->{ $options->{'host'} }, $PF_CONFIG
- );
- foreach my $ip ( sort { _ipcomp( $a, $b ) } keys %{$srv_ip} ) {
- print $ip. "\t"
- . $srv_ip->{$ip}->{'hostname'} . "("
- . $srv_ip->{$ip}->{'iface'} . ")\n";
+ foreach
+ my $hostname ( sort keys %{ $host_part->{ $options->{'host'} } } )
+ {
+ next if !ref( $host_part->{ $options->{'host'} }->{$hostname} );
+ my $srv_ip = get_srv_ip( $options->{'type'}, $options->{'host'},
+ $host_part->{ $options->{'host'} }, $PF_CONFIG );
+ foreach my $ip ( sort { _ipcomp( $a, $b ) } keys %{$srv_ip} ) {
+ print $ip. "\t"
+ . $srv_ip->{$ip}->{'hostname'} . q{(}
+ . $srv_ip->{$ip}->{'iface'} . ")\n";
+ }
}
}
}
@@ -252,21 +243,22 @@
if ( $options->{'read'} ) {
my $srv_type_list = order_servers($host_part);
foreach my $prio ( sort keys %{$srv_type_list} ) {
- print "Server with deployment priority : " . $prio . "\n";
+ print q{Server with deployment priority : } . $prio . "\n";
foreach my $srv_type ( sort keys %{ $srv_type_list->{$prio} } ) {
- print "srv type --> " . $srv_type . "\n";
+ print q{srv type --> } . $srv_type . "\n";
foreach my $srv ( @{ $srv_type_list->{$prio}->{$srv_type} } )
{
print "\t" . $srv . "\n";
- my $host_props = get_host_config(
- $srv, $GLOBAL_STRUCT, $options->{'site'}
- );
- my $srv_net = get_srv_iface(
- $options->{'type'}, $srv, $host_props
- );
+ my $host_props = get_host_config( $srv, $GLOBAL_STRUCT,
+ $options->{'site'} );
+ my $srv_net = get_srv_iface( $options->{'type'}, $srv,
+ $host_props );
+ if ( !defined $srv_net ) {
+ carp "IP feature $options->{'type'} is deactivated";
+ }
foreach my $iface ( sort keys %{$srv_net} ) {
print "\t\t"
- . $iface . "("
+ . $iface . q{(}
. $srv_net->{$iface}->{'vlan'} . ")\t: "
. $srv_net->{$iface}->{'addr'} . "\n";
}
@@ -281,10 +273,8 @@
= get_all_ip( $options->{'type'}, $host_part, $PF_CONFIG );
foreach my $ip ( sort { _ipcomp( $a, $b ) } keys %{$ip_list} ) {
print "$ip\t"
- . join(
- ' ',
- map {"$_->{'hostname'}($_->{'iface'})"} @{ $ip_list->{$ip} }
- )
+ . join( q{ },
+ map {"$_->{'hostname'}($_->{'iface'})"} @{ $ip_list->{$ip} } )
. "\n";
}
}
More information about the pf-tools-commits
mailing list