1
0
mirror of synced 2026-02-12 02:17:12 +00:00

Merge master (mostly removal of the image-server install method) back into the febootstrap branch

This commit is contained in:
Axel Beckert
2010-05-18 17:35:40 +02:00
3 changed files with 13 additions and 170 deletions

View File

@@ -147,8 +147,15 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH.
--dist=dist Specify the distribution you wish to install.
--install-method=method
Specify the installation method to use. (Default
value for Debian and Ubuntu: debootstrap)
Specify the installation method to use. Valid methods are:
* debootstrap
* rinse
* rpmstrap (deprecated)
* tar (needs --install-source=tarball.tar)
* copy (needs --install-source=/path/to/copy/from)
(Default value for Debian and Ubuntu: debootstrap)
--install-source=tarball
Specify the source path to use when installing via
@@ -1716,18 +1723,16 @@ E_OR
if ( defined( $CONFIG{ 'install-method' } ) )
{
foreach my $recognised (
qw/ copy debootstrap image-server rinse febootstrap tar /)
qw/ copy debootstrap rinse febootstrap tar /)
{
$valid = 1
if ( lc( $CONFIG{ 'install-method' } ) eq lc($recognised) );
}
#
# If we have "copy", "image-server", or "tar" method
# then make sure we have a source.
# If we have "copy", or "tar" method then make sure we have a source.
#
if ( ( lc( $CONFIG{ 'install-method' } ) eq "copy" ) ||
( lc( $CONFIG{ 'install-method' } ) eq "image-server" ) ||
( lc( $CONFIG{ 'install-method' } ) eq "tar" ) )
{
@@ -3240,7 +3245,6 @@ sub installSystem
# And where from, if relevant.
#
if ( ( lc( $CONFIG{ 'install-method' } ) eq "copy" ) ||
( lc( $CONFIG{ 'install-method' } ) eq "image-server" ) ||
( lc( $CONFIG{ 'install-method' } ) eq "tar" ) )
{
logprint("(Source: $CONFIG{'install-source'})\n");

View File

@@ -135,9 +135,6 @@ my %dispatch = (
"debootstrap" => { sub => \&do_debootstrap,
needBinary => "/usr/sbin/debootstrap",
},
"image-server" => { sub => \&do_image_server,
needURL => 1,
},
"rinse" => { sub => \&do_rinse,
needBinary => "/usr/sbin/rinse",
},
@@ -740,164 +737,6 @@ sub do_debootstrap
=begin doc
Install a system using the image-server.
Note: NON-Advertised ....
=end doc
=cut
sub do_image_server
{
#
# Load the modules we require.
#
my $test = 'use LWP::UserAgent; use CGI;';
#
# Test loading the module, if it fails then
# we must abort. We don't want to insist the module
# is installed since that adds to the dependencies
# which users will not require for the typical installation
# method(s).
#
eval($test);
if ($@)
{
die "The module LDP::UserAgent wasn't found...\n";
}
#
# The number of attempts to request the image from our
# image server, and the time to sleep between them.
#
my $attempts = 30;
my $sleep = 30;
#
# Build up the request we're going to send.
#
my $request = $CONFIG{ 'install-source' } . "/create.cgi?submit=1";
#
# Some parameters are hard-wired.
#
$request .= "&arch=amd64";
$request .= "&root_device=/dev/sda";
$request .= "&ip1=" . $ENV{ 'ip1' };
$request .= "&dist=" . CGI::escapeHTML( $CONFIG{ 'dist' } );
$request .= "&hostname=" . CGI::escapeHTML( $CONFIG{ 'hostname' } );
#
# We only care about some keys
#
foreach my $k (qw/ dhcp broadcast gateway netmask /)
{
# Skip values which aren't defined.
next unless defined $ENV{ $k };
# CGI encode.
my $val = CGI::escapeHTML( $ENV{ $k } );
# Add on to the request
$request .= "&$k=$val";
}
#
# Create a new user agent.
#
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
#
# Do the creation step
#
my $response = $ua->get($request);
if ( $response->is_success )
{
my $content = $response->content;
if ( $content =~ /fetch.cgi\?session=([^"]+)"/ )
{
my $session = $1;
my $new = $CONFIG{ 'install-source' };
$new .= "/fetch.cgi?session=$session";
my $attempt = 1;
# Make sure we don't wait indefinitely.
while ( $attempt < $attempts )
{
$CONFIG{ 'verbose' } && print "Request: [$attempt/$attempts]\n";
#
# Make a request to see if our tar file is ready yet.
#
$response = $ua->head($new);
if ( $response->is_success )
{
#
# Get the headers
#
my $header = $response->headers();
my $type = $header->{ 'content-type' };
#
# OK our file is correct.
#
if ( $type =~ /tar/ )
{
#
# Download it to the installation root.
#
$ua->get( $new,
":content_file" => $CONFIG{ 'location' } .
"/$session.tar" );
#
# If it worked .. then untar, remove, and return.
#
system(
"cd $CONFIG{'location'} && tar --numeric-owner -xf $session.tar && rm -f $CONFIG{'location'}/$session.tar"
);
return 1;
}
}
sleep($sleep);
$attempt += 1;
}
print("ERROR: Timeout waiting for image to be ready.");
return 0;
}
else
{
print(
"ERROR: Failed to find session. Received this:\n$content\n");
return 0;
}
}
else
{
print( "ERROR: Submitting the image create request failed:\n" .
$response->status_line );
return 0;
}
}
=begin doc
Install a new distribution of GNU/Linux using the rinse tool.

View File

@@ -119,7 +119,7 @@ _xen_create_image()
return 0
;;
--install-method)
COMPREPLY=( $( compgen -W 'copy debootstrap image-server rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
COMPREPLY=( $( compgen -W 'copy debootstrap rinse rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--ip)
@@ -433,7 +433,7 @@ _xt-install-image()
return 0
;;
--install-method)
COMPREPLY=( $( compgen -W 'copy debootstrap rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
COMPREPLY=( $( compgen -W 'copy debootstrap rinse rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--location)