pf-tools/pf-tools: 3 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Sep 23 09:37:27 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/b005c26d097a
changeset: 807:b005c26d097a
user: "Christophe Caillet <quadchris at free.fr>"
date: Thu Sep 23 08:45:57 2010 +0200
description:
Factorize me more
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/1c052f08baab
changeset: 808:1c052f08baab
user: "Christophe Caillet <quadchris at free.fr>"
date: Thu Sep 23 08:46:16 2010 +0200
description:
FIX
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/3fd194956c81
changeset: 809:3fd194956c81
user: "Christophe Caillet <quadchris at free.fr>"
date: Thu Sep 23 11:37:07 2010 +0200
description:
dumpiplist is now replaced by Display_IP_config
diffstat:
2 files changed, 1 insertion(+), 120 deletions(-)
tools/Display_IP_config | 1
tools/dumpiplist.pl | 120 -----------------------------------------------
diffs (482 lines):
diff -r 192bbd15991e -r 3fd194956c81 lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm Wed Sep 22 08:40:40 2010 +0200
+++ b/lib/PFTools/Conf/Host.pm Thu Sep 23 11:37:07 2010 +0200
@@ -22,6 +22,7 @@
use strict;
use warnings;
+use Carp;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Exporter;
use Fcntl ':mode';
@@ -762,6 +763,36 @@
return $result;
}
+sub __Add_deployment_on_host_entry {
+ my ( $type, $host2add, $hostclass, $host_number ) = @_;
+ my $result = {};
+
+ unless( $type or $host2add or $hostclass ) {
+ croak q{ERROR: one or more parameter is not defined};
+ }
+ if( ref $type || ref $hostclass ) {
+ croak q{ERROR: $type and/or $hostclass MUST BE a string};
+ }
+ unless( ref $host2add eq 'HASH' ) {
+ croak q{ERROR: non-ref $host2add};
+ }
+ my $dep_def = $DEF_SECTIONS->{'host'}->{'deployment'};
+ $result = {
+ 'hostname_model' => $host2add->{'hostgroup'}->{'hostname'},
+ 'hosttype' => $hostclass,
+ 'order' => $host2add->{'hostgroup'}->{'order'},
+ };
+ if( $type eq 'host' ) {
+ foreach my $key ( keys %{$dep_def} ) {
+ my $value = $host2add->{'deployment'}->{"$key\.$host_number"}
+ || $host2add->{'deployment'}->{$key};
+ next unless $value;
+ $result->{$key} = $value;
+ }
+ }
+ return $result;
+}
+
sub __Build_hostlist {
my ( $param ) = @_;
@@ -855,36 +886,22 @@
$host2add->{'deployment'}->{"dhcpvlan\.$host_number"}
|| $host2add->{'deployment'}->{'dhcpvlan'}
|| $site_part->{'dhcpvlan'};
+ unless( $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan} ) {
+ Abort( $CODE->{'INVALID_VALUE'},
+ "Unknown vlan " . $dhcpvlan . " on site "
+ . $site . " for " . $hostname
+ );
+ }
+ $host_part->{$hostname}->{'deployment'} =
+ __Add_deployment_on_host_entry (
+ $type, $host2add, $hostclass, $host_number,
+ );
if( $type eq 'host' ) {
$host_part->{$hostname}->{'boot'} = __Add_boot_on_host_entry (
- $host2add,
- $host_number,
- $site_part,
- $pf_config,
+ $host2add, $host_number, $site_part, $pf_config,
);
- unless(
- $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan}
- ) {
- Abort( $CODE->{'INVALID_VALUE'},
- "Unknown vlan " . $dhcpvlan . " on site "
- . $site . " for " . $hostname
- );
- }
- $host_part->{$hostname}->{'deployment'} = {
- 'hostname_model'
- => $host2add->{'hostgroup'}->{'hostname'},
- 'hosttype' => $hostclass,
- };
- foreach my $key ( keys %{$dep_def} ) {
- my $value =
- $host2add->{'deployment'}->{"$key\.$host_number"}
- || $host2add->{'deployment'}->{$key};
- next unless $value;
- $host_part->{$hostname}->{'deployment'}->{$key} =
- $value;
- }
- $host_part->{$hostname}->{'dns'}->{'resolver'}
- = $host2add->{'dns'}->{"resolver\.$host_number" }
+ $host_part->{$hostname}->{'dns'}->{'resolver'} =
+ $host2add->{'dns'}->{"resolver\.$host_number" }
|| $host2add->{'dns'}->{'resolver'};
}
# Check interfaces
@@ -923,13 +940,10 @@
}
foreach my $ip_type ( 'ipv4', 'ipv6' ) {
next if ( !$pf_config->{'features'}->{$ip_type} );
- my $addr_key
- = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
- my $zone_key
- = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
- my $dhcp_key
- = ( $ip_type eq 'ipv6' ) ? 'DHCP6' : 'DHCP';
my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
+ my $addr_key = "BY_ADDR".$suffix;
+ my $zone_key = "ZONE".$suffix;
+ my $dhcp_key = "DHCP".$suffix;
my $zone_ip = $if2add->{$ip_type};
$zone_ip =~ s/\/.+$//;
my $zone_part
diff -r 192bbd15991e -r 3fd194956c81 tools/Display_IP_config
--- a/tools/Display_IP_config Wed Sep 22 08:40:40 2010 +0200
+++ b/tools/Display_IP_config Thu Sep 23 11:37:07 2010 +0200
@@ -25,10 +25,12 @@
use strict;
use warnings;
+use Data::Dumper;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw ( :config ignore_case_always bundling );
use NetAddr::IP;
+use PFTools::Structqueries;
use PFTools::Utils;
####################################################
@@ -92,28 +94,26 @@
my ($host_part) = @_;
my $order;
foreach my $hostclass ( keys %{$host_part} ) {
- foreach my $hostname ( keys %{ $host_part->{$hostclass} } ) {
- my $srv_order
- = $host_part->{$hostclass}->{$hostname}->{'deployment'}
- ->{'order'}
+ 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'}->{'order'}
|| 999;
- push( @{ $order->{$srv_order} }, $hostname );
+ if( ! $order->{$srv_order}->{$hostclass} ) {
+ $order->{$srv_order}->{$hostclass} = [];
+ }
+ push( @{ $order->{$srv_order}->{$hostclass} }, $hostname );
}
}
return $order;
}
sub get_srv_iface {
- my ( $ip_type, $srv_name, $global_config, $site ) = @_;
+ my ( $ip_type, $srv_name, $host_props ) = @_;
my $result = {};
return undef if ( !$PF_CONFIG->{'features'}->{$ip_type} );
- my $host_props = Get_host_config_from_CONFIG(
- $srv_name, $global_config, $site
- );
- unless( $host_props ) {
- die "Unknown hostname " . $srv_name . " in global configuration";
- }
foreach my $iface ( keys %{ $host_props->{'interfaces'} } ) {
$result->{$iface}->{'addr'}
= $host_props->{'interfaces'}->{$iface}->{$ip_type};
@@ -200,23 +200,34 @@
my $host_part
= $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$options->{'site'}}->{'HOST'}->{'BY_NAME'};
-if ( $options->{'host'} ne "" && !defined $$host_part->{$options->{'host'}} ) {
+
+if (
+ defined $options->{'host'}
+ && $options->{'host'} ne ""
+ && !defined $host_part->{$options->{'host'}}
+) {
die "Unexistant hostclass in global configuration";
}
if ($options->{'host'}) {
if ($options->{'read'}) {
foreach my $hostname ( sort keys %{ $host_part->{$options->{'host'}} } ) {
- print "\t" . $hostname . "\n";
- 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";
+ if( ! ref ( $host_part->{$options->{'host'}}->{$hostname} ) ) {
+ print "\t$hostname is an alias for "
+ . $host_part->{$options->{'host'}}->{$hostname} . "\n";
}
- foreach my $iface ( sort keys %{$srv_net} ) {
- print "\t\t"
- . $iface . "("
- . $srv_net->{$iface}->{'vlan'} . ")\t: "
- . $srv_net->{$iface}->{'addr'} . "\n";
+ else {
+ print "\t" . $hostname . "\n";
+ 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";
+ }
+ foreach my $iface ( sort keys %{$srv_net} ) {
+ print "\t\t"
+ . $iface . "("
+ . $srv_net->{$iface}->{'vlan'} . ")\t: "
+ . $srv_net->{$iface}->{'addr'} . "\n";
+ }
}
}
}
@@ -237,11 +248,16 @@
my $srv_type_list = order_servers($host_part);
foreach my $prio ( sort keys %{$srv_type_list} ) {
print "Server with deployment priority : " . $prio . "\n";
- foreach my $srv_type ( sort @{ $srv_type_list->{$prio} } ) {
- foreach my $srv ( sort keys %{ $host_part->{$srv_type} } ) {
+ foreach my $srv_type ( sort keys %{ $srv_type_list->{$prio} } ) {
+ print "srv type --> ".$srv_type."\n";
+ foreach my $srv ( @{ $srv_type_list->{$prio}->{$srv_type} } ) {
print "\t" . $srv . "\n";
- my $srv_net = get_srv_iface( $srv,
- $host_part->{$srv_type}->{$srv} );
+ my $host_props = Get_host_config_from_CONFIG(
+ $srv, $GLOBAL_STRUCT, $options->{'site'}
+ );
+ my $srv_net = get_srv_iface(
+ $options->{'type'}, $srv, $host_props
+ );
foreach my $iface ( sort keys %{$srv_net} ) {
print "\t\t"
. $iface . "("
diff -r 192bbd15991e -r 3fd194956c81 tools/dumpiplist.pl
--- a/tools/dumpiplist.pl Wed Sep 22 08:40:40 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,241 +0,0 @@
-#!/usr/bin/perl
-##
-## $Id$
-##
-## Copyright (C) 2008 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
-## as published by the Free Software Foundation; either version 2
-## of the License, or (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-##
-
-# liste toute les adresses ip depuis le fichier private-network
-# prend le fichier private-network en argument et un 1 en second
-# argument si on souhaite avoir les adresses pour les uml (implique alteon00 surtout)
-
-use strict;
-use warnings;
-
-use English qw( -no_match_vars ); # Avoids regex performance penalty
-use Getopt::Long qw ( :config ignore_case_always bundling );
-
-use PFTools::Net;
-use PFTools::Update;
-
-my $help = 0;
-my $type = '';
-my $src = '';
-my $read = 0;
-my $program = $0;
-$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
-
-sub _ipcomp {
- my ( $a, $b ) = @_;
- my ( $suba1, $suba2, $suba3, $suba4, $supa ) = split( /\./, $a );
- my ( $subb1, $subb2, $subb3, $subb4, $supb ) = split( /\./, $b );
-
- return 1 if ( $suba1 > $subb1 );
- return -1 if ( $suba1 < $subb1 );
- return 1 if ( $suba2 > $subb2 );
- return -1 if ( $suba2 < $subb2 );
- return 1 if ( $suba3 > $subb3 );
- return -1 if ( $suba3 < $subb3 );
- return 1 if ( $suba4 > $subb4 );
- return -1 if ( $suba4 < $subb4 );
- $supa = 0 if !defined($supa);
- $supb = 0 if !defined($supb);
- return 1 if ( $supa gt $supb );
- return -1 if ( $supa lt $supb );
- return 0;
-}
-
-sub Do_help {
- print STDERR << "# ENDHELP";
- $program - version $version
-
-Usage: $program [options]
- -h --help: print help and exit
- -s --src: source file for private-network
- -t --type: specify a server type to extract from global confifuration
- -r --read: specify that output will be human readable
-
-# ENDHELP
-}
-
-sub order_servers ($) {
- my ($ref_net) = @_;
- my $result = [];
- my $order = {};
-
- foreach my $srv ( keys %{$ref_net} ) {
- my $srv_order;
- if ( !defined $ref_net->{$srv}->{'order'} ) {
- $srv_order = 999;
- }
- else {
- $srv_order = $ref_net->{$srv}->{'order'};
- }
- push( @{ $order->{$srv_order} }, $srv );
- }
-
- # foreach my $prio ( sort keys %{$order} ) {
- # foreach my $srv ( @{$order->{$prio}} ) {
- # push ( @{$result}, $srv ) ;
- # }
- # }
- return $order;
-}
-
-sub get_srv_iface ($$) {
- my ( $srv_name, $ref_srv ) = @_;
- my $ordered_vlan = {};
- my $result = {};
- foreach my $vlan ( keys %{ $ref_srv->{'ifup'} } ) {
- my $vlan_name = $vlan;
- $vlan_name =~ s/^$srv_name\.//;
- $ordered_vlan->{ $ref_srv->{'ifup'}->{$vlan} } = $vlan_name;
- }
- foreach my $iface ( sort keys %{$ordered_vlan} ) {
- $result->{$iface}->{'addr'} = $ref_srv->{'zone'}
- ->{ $srv_name . "." . $ordered_vlan->{$iface} }->{'FIELD'};
- $result->{$iface}->{'vlan'} = $ordered_vlan->{$iface};
- }
- return $result;
-}
-
-sub get_srv_ip ($$) {
- my ( $srv_type, $ref_net ) = @_;
- my $result = {};
-
- foreach my $srv ( keys %{ $ref_net->{$srv_type}->{'SRVLIST'} } ) {
- my $ref_srv = $ref_net->{$srv_type}->{'SRVLIST'}->{$srv};
- foreach my $iface ( keys %{ $ref_srv->{'zone'} } ) {
- next if ( $iface !~ /^$srv\./ );
- $result->{ $ref_srv->{'zone'}->{$iface}->{'FIELD'} }->{'hostname'}
- = $srv;
- $result->{ $ref_srv->{'zone'}->{$iface}->{'FIELD'} }->{'iface'}
- = $ref_srv->{'ifup'}->{$iface};
- }
- }
- return $result;
-}
-
-sub get_all_ip ($) {
- my ($ref_net) = @_;
- my $result = {};
-
- foreach my $srv_type ( keys %{$ref_net} ) {
- foreach my $srv ( keys %{ $ref_net->{$srv_type}->{'SRVLIST'} } ) {
- my $ref_srv = $ref_net->{$srv_type}->{'SRVLIST'}->{$srv};
- foreach my $iface ( keys %{ $ref_srv->{'zone'} } ) {
- next if ( $iface !~ /^$srv\./ );
- my $entry = {
- 'hostname' => $srv,
- 'iface' => $ref_srv->{'ifup'}->{$iface}
- };
- push(
- @{ $result->{ $ref_srv->{'zone'}->{$iface}->{'FIELD'} }
- },
- $entry
- );
- }
- }
- }
- return $result;
-}
-
-GetOptions(
- 'help|h' => \$help,
- 'type|t=s' => \$type,
- 'read|r' => \$read,
- 'src|s=s' => \$src
-) || die "Didn't grok options on CLI\n";
-
-if ($help) {
- Do_help();
- exit 0;
-}
-
-if ( !$src ) {
- die "Source file for network description is not defined\n";
-}
-elsif ( !-e $src ) {
- die $src . " source file doesn't exist\n";
-}
-
-my $PF_NET = Init_lib_net( Get_source($src) );
-my $SRV_LIST = $PF_NET->{'SERVERS'}->{'BY_NAME'};
-
-if ( $type && !defined $SRV_LIST->{$type} ) {
- die "Non existant server type " . $type . "\n";
-}
-
-if ($type) {
- if ($read) {
- foreach my $srv ( sort keys %{ $SRV_LIST->{$type}->{'SRVLIST'} } ) {
- print "\t" . $srv . "\n";
- my $srv_net = get_srv_iface( $srv,
- $SRV_LIST->{$type}->{'SRVLIST'}->{$srv} );
- foreach my $iface ( sort keys %{$srv_net} ) {
- print "\t\t"
- . $iface . "("
- . $srv_net->{$iface}->{'vlan'} . ")\t: "
- . $srv_net->{$iface}->{'addr'} . "\n";
- }
- }
- }
- else {
- my $srv_ip = get_srv_ip( $type, $SRV_LIST );
- foreach my $ip ( sort { _ipcomp( $a, $b ) } keys %{$srv_ip} ) {
- print $ip. "\t"
- . $srv_ip->{$ip}->{'hostname'} . "("
- . $srv_ip->{$ip}->{'iface'} . ")\n";
- }
- }
-}
-else {
- if ($read) {
- my $srv_type_list = order_servers($SRV_LIST);
- foreach my $prio ( sort keys %{$srv_type_list} ) {
- print "Server with deployment priority : " . $prio . "\n";
- foreach my $srv_type ( sort @{ $srv_type_list->{$prio} } ) {
- foreach my $srv (
- sort keys %{ $SRV_LIST->{$srv_type}->{'SRVLIST'} } )
- {
- print "\t" . $srv . "\n";
- my $srv_net = get_srv_iface( $srv,
- $SRV_LIST->{$srv_type}->{'SRVLIST'}->{$srv} );
- foreach my $iface ( sort keys %{$srv_net} ) {
- print "\t\t"
- . $iface . "("
- . $srv_net->{$iface}->{'vlan'} . ")\t: "
- . $srv_net->{$iface}->{'addr'} . "\n";
- }
- }
- print "\n";
- }
- print "\n";
- }
- }
- else {
- my $ip_list = get_all_ip($SRV_LIST);
- foreach my $ip ( sort { _ipcomp( $a, $b ) } keys %{$ip_list} ) {
- print "$ip\t"
- . join( ' ',
- map {"$_->{'hostname'}($_->{'iface'})"} @{ $ip_list->{$ip} } )
- . "\n";
- }
- }
-}
More information about the pf-tools-commits
mailing list