pf-tools/pf-tools: 3 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Sep 14 15:25:51 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/0d276770a22a
changeset: 760:0d276770a22a
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 15:52:19 2010 +0200
description:
Coding style applied and tested with sbin/mk_grubopt : I know it is not with a Test file
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/c3aa3297fd1a
changeset: 761:c3aa3297fd1a
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 16:36:36 2010 +0200
description:
Coding style for sbin/mk_interfaces
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/c8777cc0448e
changeset: 762:c8777cc0448e
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Sep 14 17:14:03 2010 +0200
description:
Coding style for sbin/mk_pxelinuxcfg and lib/PFTools/Utils.pm
diffstat:
2 files changed, 3 deletions(-)
sbin/mk_interfaces | 1 -
sbin/mk_pxelinuxcfg | 2 --
diffs (417 lines):
diff -r f0075a070f36 -r c8777cc0448e lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Tue Sep 14 10:33:15 2010 +0200
+++ b/lib/PFTools/Utils.pm Tue Sep 14 17:14:03 2010 +0200
@@ -25,6 +25,7 @@
use Exporter;
use File::Compare;
use File::Copy;
+use IO::File;
use Template::Tiny;
use PFTools::Conf;
@@ -229,6 +230,8 @@
);
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*//;
my $pxe_subst = {
'iface' => $iface,
'mode' => $host_props->{'deployment'}->{'mode'} . '-installer',
@@ -239,7 +242,7 @@
'preseed_md5' => $preseed_md5,
'console' => $host_props->{'boot'}->{'console'},
'install_cmdline' => $host_props->{'boot'}->{'cmdline'},
- 'cmdline' => join( " ", Get_cmdline_from_hostprops($host_props) ),
+ 'cmdline' => $cmdline,
'kernel' => $host_props->{'boot'}->{'kernel'}
};
if ( $host_props->{'boot'}->{'initrd'} ) {
@@ -792,56 +795,48 @@
$pf_config )
= @_;
my $tmp_grub = [];
- my ($cmd_line);
my $host_props
= Get_host_config_from_CONFIG( $hostname, $global_config, $site );
- if ( !defined $host_props ) {
+ unless( $host_props ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Unable to find hostname "
- . $hostname
- . " on site "
- . $site
- . " : no such host definition" );
+ "Unknown hostname $hostname on site $site" );
}
my $mode = $host_props->{'deployment'}->{'mode'};
- my ( $cmdline, $bond_cmdline ) = Get_cmdline_from_hostprops($host_props);
+ my $cmdline = join( " ", Get_cmdline_from_hostprops($host_props) );
+ $cmdline =~ s/^\s*//; # Removing trailing space
$grub_version = "" if ( $grub_version == 1 );
$grub_src = $pf_config->{$mode}->{ 'grub' . $grub_version }
if ( $grub_src eq '' );
- if ( !-e $grub_src ) {
- Abort( $CODE->{'UNDEF_KEY'},
- "Unable to modify GRUB option(s) on file "
- . $grub_src
- . " : no such file or directory" );
+ my $src_hdl = IO::File->new( $grub_src );
+ unless( $src_hdl ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to open GRUB source $grub_src : $OS_ERROR" );
+ return;
}
-
- unless ( open( MENU, $grub_src ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to open current file "
- . $grub_src
- . " for modifying GRUB option(s)" );
- return 0;
- }
- @{$tmp_grub} = <MENU>;
- close(MENU);
+ @{$tmp_grub} = <$src_hdl>;
+ $src_hdl->close();
foreach ( @{$tmp_grub} ) {
chomp;
next
if ( $grub_version == 2 && !/^GRUB_CMDLINE_LINUX_DEFAULT=".*"$/ );
next if ( $grub_version == 1 && !/^\# kopt=.*$/ );
- s/\"$/ $cmd_line\"/ if ( defined $cmd_line && !/\Q$cmd_line\E\"$/ );
+ s/\"$/ $cmdline\"/ if ( $cmdline && !/\Q$cmdline\E\"$/ );
}
my $tmp_dst = ( $dst eq "-" ) ? $dst : "/tmp/menulst";
- unless ( open( TMPDST, ">" . $tmp_dst ) ) {
+ my $dst_hdl = IO::File->new( ">$tmp_dst" );
+ unless( $dst_hdl ) {
Warn( $CODE->{'OPEN'},
- "Unable to open temporary destination file /tmp/menulst" );
- return 0;
+ "Unable to open tmp destination $tmp_dst : $OS_ERROR" );
+ return;
}
- print TMPDST join( "\n", @{$tmp_grub} );
- close(TMPDST);
+ unless( $dst_hdl->print( join( "\n", @{$tmp_grub} ) ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to write on tmp destination $tmp_dst : $OS_ERROR" );
+ }
+ $dst_hdl->close();
if ( $tmp_dst ne "-" ) {
if ( compare( $tmp_dst, $dst ) ) {
return move( $tmp_dst, $dst );
@@ -849,11 +844,11 @@
else {
if ( !unlink($tmp_dst) ) {
Warn( $CODE->{'UNLINK'},
- "Unable to unlink source file " . $tmp_dst );
+ "Unable to unlink tmp destination $tmp_dst : $OS_ERROR" );
}
- return 1;
}
}
+ return 1;
}
#
diff -r f0075a070f36 -r c8777cc0448e sbin/mk_interfaces
--- a/sbin/mk_interfaces Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_interfaces Tue Sep 14 17:14:03 2010 +0200
@@ -1,7 +1,6 @@
#!/usr/bin/perl
##
-## $Id$
-##
+## Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
##
@@ -17,7 +16,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -34,13 +34,24 @@
#################################
# VARS
-my $HELP = 0;
-my $HOSTNAME = hostname;
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
+
+my @options_specs = (
+ 'help',
+ 'host|h=s',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+ 'output|o=s',
+);
+
+# Default options values
+my $options = {
+ 'help' => 0,
+ 'host' => hostname,
+ 'output' => '-',
+};
+
my $PF_CONFIG = {};
-my $OUTPUT_FILE = '/etc/network/interfaces';
my $GLOBAL_STRUCT = {};
my @HEADER_DEST = (
"#################################################",
@@ -51,14 +62,11 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
-
###################################
# Funtions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -74,68 +82,68 @@
##################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'host|h=s' => \$HOSTNAME,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
- 'output|o=s' => \$OUTPUT_FILE
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( $HOSTNAME, $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+ = Init_TOOLS( $options->{'host'}, $options->{'config'}, $options->{'store'} );
-if ( $SITE eq '' ) {
+if ( $options->{'site'} eq '' ) {
if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
- my $site_list = Get_site_from_hostname( $HOSTNAME, $GLOBAL_STRUCT );
+ my $site_list = Get_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
if ( !defined $site_list ) {
Abort( $CODE->{'UNDEF_KEY'},
"Unable to retrieve site for hostname "
- . $HOSTNAME
+ . $options->{'host'}
. " : hostname not defined" );
}
elsif ( scalar @{$site_list} > 1 ) {
Abort( $CODE->{'DUPLICATE_VALUE'},
"Unable to retrieve site for hostname "
- . $HOSTNAME
+ . $options->{'host'}
. " : hostname appeared in multiple sites : "
. join( ",", @{$site_list} ) . ".\n"
. "Please relaunch this command with the right site" );
}
else {
- ($SITE) = @{$site_list};
+ ($options->{'site'}) = @{$site_list};
}
}
else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
}
-my $iface = Mk_interfaces( $HOSTNAME, $GLOBAL_STRUCT, $PF_CONFIG, $SITE );
-if ( !defined $iface ) {
+my $iface = Mk_interfaces(
+ $options->{'host'},
+ $GLOBAL_STRUCT,
+ $PF_CONFIG,
+ $options->{'site'}
+);
+unless( $iface ) {
Abort( $CODE->{'EXEC'},
- "An error occured during building interfaces file " . $OUTPUT_FILE );
+ "Error occured during building interfaces file" );
}
-my $output_fh = IO::File->new( '>' . $OUTPUT_FILE )
+my $output_fh = IO::File->new( '>' . $options->{'output'} )
or Abort( $CODE->{'OPEN'},
- "Unable to open destination $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to open file $options->{'output'} : $OS_ERROR" );
$output_fh->print( join "\n", @HEADER_DEST )
or Abort( $CODE->{'OPEN'},
- "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to write on file $options->{'output'} : $OS_ERROR" );
foreach my $if ( @{ $iface->{'__order'} } ) {
- $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" )
- or Abort( $CODE->{'OPEN'},
- "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+ unless( $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" ) ) {
+ Abort( $CODE->{'OPEN'},
+ "Unable to write on file $options->{'output'} : $OS_ERROR" );
+ }
}
$output_fh->close()
or Abort( $CODE->{'OPEN'},
- "Unable to close destination file $OUTPUT_FILE : $OS_ERROR" );
+ "Unable to close file $options->{'output'} : $OS_ERROR" );
exit 0;
diff -r f0075a070f36 -r c8777cc0448e sbin/mk_pxelinuxcfg
--- a/sbin/mk_pxelinuxcfg Tue Sep 14 10:33:15 2010 +0200
+++ b/sbin/mk_pxelinuxcfg Tue Sep 14 17:14:03 2010 +0200
@@ -1,6 +1,4 @@
#!/usr/bin/perl
-##
-## $Id$
##
## Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
@@ -18,7 +16,8 @@
##
## 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
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+## USA
##
use strict;
@@ -35,14 +34,22 @@
############################################
# Vars
+my @options_specs = (
+ 'help',
+ 'script=s',
+ 'site|s=s',
+ 'config|c=s',
+ 'store=s',
+);
+
+my $options = {
+ 'help' => 0,
+ 'script' => 'pf-tools-config.sh',
+};
+
my $DEPLOY_DOCROOT = "/var/www";
-my $HELP = 0;
-my $PF_SCRIPT = 'pf-tools-config.sh';
my $PXE_TPL = '';
my $PRESEED_TPL = '';
-my $SITE = '';
-my $GLOBAL_STORE_FILE = '';
-my $PF_CONFIG_FILE = '';
my $PF_CONFIG = {};
my $GLOBAL_STRUCT = {};
my $DEFAULT_PRESEED = '';
@@ -50,14 +57,12 @@
my $program = $0;
$program =~ s%.*/%%; # cheap basename
-my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
############################################
# Functions
sub Do_help {
print STDERR << "# ENDHELP";
- $program - version $version
Usage: $program [options]
--help : print help and exit
@@ -72,21 +77,16 @@
############################################
### MAIN
-GetOptions(
- 'help' => \$HELP,
- 'script=s' => \$PF_SCRIPT,
- 'site|s=s' => \$SITE,
- 'config|c=s' => \$PF_CONFIG_FILE,
- 'store=s' => \$GLOBAL_STORE_FILE,
-) or die "Didn't grok options (see --help).\n";
+GetOptions( $options, @options_specs )
+ or die "Didn't grok options (see --help).\n";
-if ($HELP) {
+if ($options->{'help'}) {
Do_help();
exit 0;
}
( $PF_CONFIG, $GLOBAL_STRUCT )
- = Init_TOOLS( "", $PF_CONFIG_FILE, $GLOBAL_STORE_FILE );
+ = Init_TOOLS( "", $options->{'config'}, $options->{'store'} );
if ( !-e $PF_CONFIG->{'path'}->{'preseed_dir'} ) {
make_path( $PF_CONFIG->{'path'}->{'preseed_dir'} );
@@ -97,22 +97,22 @@
}
$DEFAULT_PRESEED
= $PF_CONFIG->{'path'}->{'preseed_dir'} . "/default_preseed.txt";
-if ( $SITE eq '' ) {
+if ( $options->{'site'} eq '' ) {
if ( !defined $PF_CONFIG->{'location'}->{'site'} ) {
Abort( $CODE->{'UNDEF_KEY'},
"A site MUST BE defined for building DNS zone forward" );
}
else {
- $SITE = $PF_CONFIG->{'location'}->{'site'};
+ $options->{'site'} = $PF_CONFIG->{'location'}->{'site'};
}
}
-if ( !defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
+unless( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
Abort( $CODE->{'UNDEF_KEY'},
- "Site " . $SITE . " is not defined into global configuration" );
+ "Unknown site $options->{'site'}" );
}
-my $site_part = $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$SITE};
+my $site_part = $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$options->{'site'}};
my $host_part = $site_part->{'HOST'}->{'BY_NAME'};
foreach my $hostclass ( @{ $site_part->{'HOST'}->{'__hostclass_pxe'} } ) {
foreach my $host ( keys %{ $host_part->{$hostclass} } ) {
@@ -123,10 +123,11 @@
. $PF_CONFIG->{$mode}->{'pxe'};
my $preseed_tpl = $PF_CONFIG->{'path'}->{'templates_dir'} . '/'
. $PF_CONFIG->{$mode}->{'preseed'};
- my $pxe_file
- = Mk_PXE_bootfile( $host, $host_part->{$hostclass}->{$host},
- $pxe_template, $preseed_tpl, $DEFAULT_PRESEED, $PF_SCRIPT,
- $PF_CONFIG );
+ my $pxe_file = Mk_PXE_bootfile(
+ $host, $host_part->{$hostclass}->{$host},
+ $pxe_template, $preseed_tpl,
+ $DEFAULT_PRESEED, $options->{'script'}, $PF_CONFIG
+ );
}
}
More information about the pf-tools-commits
mailing list