2007-03-11 15:40:58 by steve
Allow last octet of each IP address to be dynamically determined. This allows : "--ip=192.168.1" to be specified and the last octet will automatically increment for each invokation.
This commit is contained in:
parent
a41e116e88
commit
0565a278ae
@ -504,7 +504,7 @@ Install an X11 server, using VNC and XDM
|
||||
--
|
||||
http://www.steve.org.uk/
|
||||
|
||||
$Id: xen-create-image,v 1.134 2007-02-26 14:48:36 steve Exp $
|
||||
$Id: xen-create-image,v 1.135 2007-03-11 15:40:58 steve Exp $
|
||||
|
||||
=cut
|
||||
|
||||
@ -945,6 +945,7 @@ sub setupDefaultOptions
|
||||
$CONFIG{'pid'} = 0;
|
||||
$CONFIG{'template'} = '';
|
||||
$CONFIG{'roledir'} = '/etc/xen-tools/role.d';
|
||||
$CONFIG{'ipfile'} = '/etc/xen-tools/ips.txt';
|
||||
|
||||
#
|
||||
# Installation method defaults to "debootstrap".
|
||||
@ -1141,7 +1142,7 @@ sub parseCommandLineArguments
|
||||
|
||||
if ( $VERSION )
|
||||
{
|
||||
my $REVISION = '$Revision: 1.134 $';
|
||||
my $REVISION = '$Revision: 1.135 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -2324,7 +2325,29 @@ sub runCustomisationHooks
|
||||
|
||||
foreach my $i ( @$ips )
|
||||
{
|
||||
#
|
||||
# Here we have special handling for the case where
|
||||
# IP addresses are xx.yy.zz - we automatically add
|
||||
# in the next octet using /etc/xen-tools/ips.txt
|
||||
#
|
||||
#
|
||||
if ( $i =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ )
|
||||
{
|
||||
# NOP
|
||||
$CONFIG{'verbose'} && logprint( "IP address is complete: $i\n" );
|
||||
}
|
||||
elsif ( $i =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/ )
|
||||
{
|
||||
$CONFIG{'verbose'} &&
|
||||
logprint( "Automatically determining the last octet for $i\n" );
|
||||
|
||||
$i = findNextIP( $i );
|
||||
|
||||
$CONFIG{'verbose'} && logprint( "Found $i\n" );
|
||||
}
|
||||
|
||||
$ENV{'ip' . $count } = $i;
|
||||
|
||||
$count += 1;
|
||||
}
|
||||
$ENV{'ip_count'} = ($count - 1);
|
||||
@ -2360,6 +2383,44 @@ sub runCustomisationHooks
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
Find the next usable IP address for the given host.
|
||||
|
||||
This works by reading the last octet from a global file, incrementing
|
||||
it and writing it back to the file. So we have a running total of the
|
||||
last IP.
|
||||
|
||||
=cut
|
||||
|
||||
sub findNextIP
|
||||
{
|
||||
my( $ip ) = (@_);
|
||||
|
||||
# Abort if we don't have the IP file.
|
||||
return $ip if ( ! -e $CONFIG{'ipfile'} );
|
||||
|
||||
# Read the number.
|
||||
open( OCTET, "<", $CONFIG{'ipfile'} ) or return $ip;
|
||||
my $line = <OCTET>;
|
||||
$line = 1 if ( ( ! defined( $line ) ) || ( $line !~ /^([0-9]+)$/ ) );
|
||||
close( OCTET );
|
||||
chomp( $line );
|
||||
|
||||
# Add it
|
||||
$ip .= ".$line";
|
||||
|
||||
# Increment + write
|
||||
$line += 1 ;
|
||||
open( OCTET, ">", $CONFIG{'ipfile'} );
|
||||
print OCTET $line . "\n";
|
||||
close( OCTET );
|
||||
|
||||
return( $ip );
|
||||
}
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
If the user specified a role for the new instance then execute it.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user