pf-tools/pf-tools: 2 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Oct 13 15:43:24 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/6e880bf1eb37
changeset: 890:6e880bf1eb37
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Oct 13 17:40:28 2010 +0200
description:
Build and rebuild is always work!
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/7deed643aebf
changeset: 891:7deed643aebf
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Oct 13 17:43:02 2010 +0200
description:
merge ... i have some difficulties with mercurial :)
diffstat:
0 files changed
diffs (401 lines):
diff -r 1e72e8b32a72 -r 7deed643aebf debian/control
--- a/debian/control Wed Oct 13 10:54:44 2010 +0200
+++ b/debian/control Wed Oct 13 17:43:02 2010 +0200
@@ -3,7 +3,7 @@
Priority: optional
Maintainer: Christophe Caillet <quadchris at free.fr>
Uploaders: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>, Christophe Caillet <quadchris at free.fr>
-Build-Depends-Indep: perl, libhash-merge-simple-perl, libtest-exception-perl, libtest-most-perl
+Build-Depends-Indep: perl, libhash-merge-simple-perl, libtest-exception-perl, libtest-simple-perl
Standards-Version: 3.0.1
Package: pf-tools
diff -r 1e72e8b32a72 -r 7deed643aebf lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Wed Oct 13 10:54:44 2010 +0200
+++ b/lib/PFTools/Utils.pm Wed Oct 13 17:43:02 2010 +0200
@@ -59,7 +59,7 @@
#########################################################################
# Functions
-sub Init_TOOLS ($;$$$) {
+sub Init_TOOLS {
my ( $hostname, $pf_config_file, $global_store_file, $reload ) = @_;
my ( $pf_config, $global_struct );
@@ -80,38 +80,34 @@
my $source
= Get_source( 'COMMON:/' . $pf_config->{'path'}->{'start_file'},
$hostname, {}, $pf_config );
- Set_deferredlog();
if ( ! VCS_checkout( $hostname, $pf_config, {} ) ) {
- Abort( $CODE->{'EXEC'},
- "Unable to checkout configuration from VCS system" );
+ croak q{ERROR: Unable to checkout configuration from VCS system"};
}
- Unset_deferredlog();
- $global_struct
- = Init_GLOBAL_NETCONFIG( $source, {}, $pf_config );
+ $global_struct = Init_GLOBAL_NETCONFIG(
+ $source, {}, $pf_config
+ );
Flush2disk_GLOBAL( $global_struct, $pf_config );
}
else {
$global_struct = Retrieve_GLOBAL($global_store_file);
if ( !defined $global_struct ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "An error occured during retrieve from the storable file "
- . $global_store_file );
+ croak qq{ERROR: while retrieving from $global_store_file};
}
}
return ( $pf_config, $global_struct );
}
-sub Get_kpkg_from_kernel ($$) {
+sub Get_kpkg_from_kernel {
my ( $pxefilename, $deploymode ) = @_;
- if ( $deploymode =~ /^ubuntu/ ) {
- $pxefilename =~ /vmlinuz-(.+)$/;
+ if ( $deploymode =~ m{\A ubuntu}xms ) {
+ $pxefilename =~ m{vmlinuz-(.+) \Z}xms;
return "linux-image-" . $1;
}
else {
- if ( $pxefilename =~ /pxe/ ) {
+ if ( $pxefilename =~ m{pxe} ) {
my ( $vm, $type, $pxe, $version, @append )
- = split( /-/, $pxefilename );
+ = split( m{-}, $pxefilename );
return
"linux-image-"
. $version . "-"
@@ -121,7 +117,7 @@
}
else {
my ( $vm, $version, $type, $append_version )
- = split( /-/, $pxefilename );
+ = split( m{-}, $pxefilename );
return
"linux-image-"
. $version . "-"
@@ -132,18 +128,18 @@
}
}
-sub Build_preseed_filename ($$$$$$) {
+sub Build_preseed_filename {
my ($srv_name, $preseed_tpl, $host_props,
$default_preseed, $pf_script, $pf_config
) = @_;
- if ( !open( PRESEED_TPL, $preseed_tpl ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to get preseed template from file " . $preseed_tpl );
+ my $preseed_hl = IO::File->new( $preseed_tpl );
+ unless( $preseed_hl ) {
+ carp qq{WARN: Unable to get preseed template from $preseed_tpl};
return $default_preseed;
}
- my $preseed_content = join '', <PRESEED_TPL>;
- close(PRESEED_TPL);
+ my $preseed_content = join '', <$preseed_hl>;
+ $preseed_hl->close();
my $kernel_pkg = Get_kpkg_from_kernel(
$host_props->{'boot'}->{'kernel'},
$host_props->{'deployment'}->{'mode'}
@@ -155,41 +151,48 @@
'distrib' => $host_props->{'deployment'}->{'distrib'},
'config_script' => $pf_script
};
- $preseed_content = $tpl->process( \$preseed_content, $preseed_subst );
-
- if ( !open( DST_PRESEED, ">/tmp/tmp_preseed" ) ) {
- Warn( $CODE->{'OPEN'}, "Unable to create preseed file /tmp_preseed" );
+ $tpl->process( \$preseed_content, $preseed_subst, \$preseed_content );
+ # FIXME with correct temporary filename handler
+ my $src = "/tmp/tmp_preseed";
+ my $tmp_hl = IO::File->new( ">" . $src );
+ unless( $tmp_hl ) {
+ carp qq{WARN: Unable to create preseed file $src};
return $default_preseed;
}
- print DST_PRESEED $preseed_content;
- close(DST_PRESEED);
- my $src = "/tmp/tmp_preseed";
+ $tmp_hl->print( $preseed_content );
+ $tmp_hl->close();
+
my $dst = $pf_config->{'path'}->{'preseed_dir'} . "/preseed_" . $srv_name;
if ( compare( $src, $dst ) ) {
move( $src, $dst );
}
else {
- if ( !unlink($src) ) {
- Warn( $CODE->{'UNLINK'}, "Unable to unlink source file " . $src );
+ if ( !unlink( $src ) ) {
+ carp qq{WARN: Unable to unlink source file $src};
}
}
return "preseed_" . $srv_name;
}
-sub Get_MD5SUM_for_preseedfile ($$) {
+sub Get_MD5SUM_for_preseedfile {
my ( $filename, $pf_config ) = @_;
my ( $md5, $hdl );
$md5 = Digest::MD5->new;
- open $hdl, $pf_config->{'path'}->{'preseed_dir'} . "/" . $filename
- || return undef;
+ $hdl = IO::File->new(
+ $pf_config->{'path'}->{'preseed_dir'} . "/" . $filename
+ );
+ unless( $hdl ) {
+ carp qq{ERROR: Unable to open preseed $filename};
+ return;
+ }
$md5->addfile($hdl);
my $md5sum = $md5->hexdigest;
- close($hdl);
+ $hdl->close();
return $md5sum;
}
-sub Mk_PXE_bootfile ($$$$$$$) {
+sub Mk_PXE_bootfile {
my ( $hostname, $host_props, $pxe_tpl, $preseed_tpl, $default_preseed,
$pf_script, $pf_config )
= @_;
@@ -198,20 +201,17 @@
$host_props->{'deployment'}->{'dhcpvlan'}, $host_props );
my $mac = $host_props->{'interfaces'}->{$iface}->{'mac'};
my $pxe_boot_file = $mac;
- $pxe_boot_file =~ s/\:/\-/g;
+ $pxe_boot_file =~ s{:}{-}g;
if ( !-e $pxe_tpl ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to open PXE template file "
- . $pxe_tpl
- . " : no such file or directory" );
+ croak qq{ERROR: $pxe_tpl : no such file or directory};
}
- elsif ( !open( PXETPL, $pxe_tpl ) ) {
- Abort( $CODE->{'OPEN'},
- "Unable to open PXE template file " . $pxe_tpl );
+ my $pxetpl_hl = IO::File->new( $pxe_tpl );
+ unless( $pxetpl_hl ) {
+ croak qq{ERROR: Unable to open PXE template file $pxe_tpl};
}
- my $content_pxe = join( "", <PXETPL> );
- close(PXETPL);
+ my $content_pxe = join( "", <$pxetpl_hl> );
+ $pxetpl_hl->close();
my $preseed = Build_preseed_filename(
$hostname, $preseed_tpl, $host_props,
$default_preseed, $pf_script, $pf_config
@@ -219,7 +219,7 @@
my $preseed_md5 = Get_MD5SUM_for_preseedfile( $preseed, $pf_config );
my $tpl = Template::Tiny->new( TRIM => 1 );
my $cmdline = join( " ", Get_cmdline_from_hostprops($host_props) );
- $cmdline =~ s/^\s*//;
+ $cmdline =~ s{\A \s*}{}xms;
my $pxe_subst = {
'iface' => $iface,
'mode' => $host_props->{'deployment'}->{'mode'} . '-installer',
@@ -237,24 +237,25 @@
$pxe_subst->{'initrd'} = $host_props->{'boot'}->{'initrd'};
}
else {
- $content_pxe =~ s/initrd=(([^\/]+\/)+)?\[%\s*initrd\s*%\]//gs;
+ $content_pxe =~ s{initrd=(([^/]+/)+)?\[%\s*initrd\s*%\]}{}gs;
}
- $content_pxe = $tpl->process( \$content_pxe, $pxe_subst );
- if ( !open( PXETMP, ">/tmp/tmp_pxe" ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to open temporary PXE file /tmp/tmp_pxe" );
- return undef;
+ $tpl->process( \$content_pxe, $pxe_subst, \$content_pxe );
+ # FIXME with correct temporary filename handler
+ my $src = "/tmp/tmp_pxe";
+ my $dst_hl = IO::File->new ( ">" . $src );
+ unless( $dst_hl ) {
+ carp qq{ERROR :Unable to open temporary PXE file $src};
+ return;
}
- print PXETMP $content_pxe;
- close(PXETMP);
- my $src = "/tmp/tmp_pxe";
+ $dst_hl->print( $content_pxe );
+ $dst_hl->close();
my $dst = $pf_config->{'path'}->{'pxefiles_dir'} . "/" . $pxe_boot_file;
if ( compare( $src, $dst ) ) {
move( $src, $dst );
}
else {
- if ( !unlink($src) ) {
- Warn( $CODE->{'UNLINK'}, "Unable to unlink source file " . $src );
+ if ( !unlink( $src ) ) {
+ carp qq{WARN: Unable to unlink source file $src};
}
}
return $pxe_boot_file;
@@ -263,7 +264,7 @@
###############################################################
### Building zone file for IPv4 entries
-sub __Mk_zoneheader ($$$) {
+sub __Mk_zoneheader {
my ( $zone_name, $zone_site, $zone_part ) = @_;
my $zone_result = [];
@@ -411,44 +412,44 @@
return $zone_result;
}
-sub Mk_resolvconf ($$$$) {
+sub Mk_resolvconf {
my ( $hostname, $global_config, $site, $output ) = @_;
- my $host_props
- = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $host_props ) {
- Warn( $CODE->{'UNDEF_KEY'},
- "Unable to find hostname "
- . $hostname
- . " on site "
- . $site
- . " : no such host definition" );
- return 0;
+ my $host_props = Get_host_config_from_CONFIG(
+ $hostname, $global_config, $site
+ );
+ unless( $host_props ) {
+ carp qq{ERROR: Unknown hostname $hostname on site $site};
+ return;
}
my $domain = Get_zone_from_hostname( $hostname, $global_config, $site );
- if ( !defined $domain ) {
- Warn( $CODE->{'UNDEF_KEY'},
- "Unable to get domain from hostname " . $hostname );
- return 0;
+ unless( $domain ) {
+ carp qq{ERROR: Unable to get domain from hostname $hostname};
+ return;
}
- my @dns = split( /\s*,\s*/, $host_props->{'dns'}->{'resolver'} );
+ my @dns = split( m{\s*,\s*}, $host_props->{'dns'}->{'resolver'} );
- unless ( open( OUTPUT, ">" . $output ) ) {
- Warn( $CODE->{'OPEN'}, "Unable to open output file " . $output );
- return 0;
+ my $out_hl = IO::File->new( ">" . $output );
+ unless( $out_hl ) {
+ carp qq{ERROR: Unable to open output file $output};
+ return;
}
- print OUTPUT "###############################################\n";
- print OUTPUT "# This file was auto-genrated by mk_resolvconf\n";
- print OUTPUT "\n";
- print OUTPUT "search " . $domain . "\n";
+ my @header = (
+ "###############################################",
+ "# This file was auto-genrated by mk_resolvconf",
+ "",
+ "search " . $domain,
+ "",
+ );
+ $out_hl->print( join( "\n", @header ) );
foreach my $dns (@dns) {
my $resolved = Resolv( 'cnf', $dns, $global_config, $site );
foreach my $ip ( @{$resolved} ) {
- print OUTPUT "nameserver " . $ip . "\n";
+ $out_hl->print( "nameserver " . $ip . "\n" );
}
}
- close(OUTPUT);
+ $out_hl->close();
return 1;
}
@@ -464,44 +465,32 @@
return;
}
if ( $type_resolve eq 'cnf' ) {
- if ( !defined $site ) {
- my $ref_site_list
- = Get_site_from_hostname( $hostname, $global_config );
- if ( !defined $ref_site_list ) {
- Warn( $CODE->{'UNDEF_KEY'},
- "Hostname "
- . $hostname
- . " is not defined into the global configuration" );
- return undef;
- }
- elsif ( scalar @{$ref_site_list} > 1 ) {
- Warn( $CODE->{'DUPLICATE_VALUE'},
- "Hostname "
- . $hostname
- . " is defined into multiple sites : unable to choose the right one"
- );
- }
- else {
- ($site) = @{$ref_site_list};
+ $site ||= Get_uniq_site_from_hostname( $hostname, $global_config );
+ unless( $site ) {
+ carp qq{ERROR: Invalid site from hostname $hostname};
+ return;
+ }
+ my $zone = Get_zone_from_hostname( $hostname, $global_config, $site );
+ $hostname =~ s{\.$zone \Z}{}xms;
+ $hostname =~ m{\A ([^.]+)(\.([^.]+))? \Z}xms;
+ my ( $hostshort, $hostvlan ) = ( $1, $3 );
+ if ( !defined $hosttype
+ && $hostname !~ m{\A (network|netmask|broadcast|gateway)}xms )
+ {
+ $hosttype = Get_hosttype_from_hostname(
+ $hostshort, $global_config, $site
+ );
+ unless( $hosttype ) {
+ carp qq{ERROR: Unable to retrieve hosttype from $hostname};
+ return;
}
}
- my $zone = Get_zone_from_hostname( $hostname, $global_config, $site );
- $hostname =~ s/\.$zone$//;
- $hostname =~ /^([^.]+)(\.([^.]+))?$/;
- my ( $hostshort, $hostvlan ) = ( $1, $3 );
- if ( !defined $hosttype
- && $hostname !~ /^(network|netmask|broadcast|gateway)/ )
- {
- $hosttype
- = Get_hosttype_from_hostname( $hostshort, $global_config,
- $site );
- return undef if ( !defined $hosttype );
- }
- return Resolv_hostname_from_GLOBAL( $hostname, $global_config, $site,
- $zone, $hosttype );
+ return Resolv_hostname_from_GLOBAL(
+ $hostname, $global_config, $site, $zone, $hosttype
+ );
}
else {
- return Resolv_hostname_from_DNS($hostname);
+ return Resolv_hostname_from_DNS( $hostname );
}
}
@@ -775,9 +764,7 @@
'default_sections' => $pf_config->{$mode}->{'default_sections'},
'custom_sections' => $sections
};
- $sources_content = $tpl->process(
- \$sources_content, $sources_subst, \$sources_content
- );
+ $tpl->process( \$sources_content, $sources_subst, \$sources_content );
if( $backports ) {
my $back_src = ( $mode eq 'debian' )
More information about the pf-tools-commits
mailing list