--- trunk/vz-create.pl 2007/12/13 23:50:47 35 +++ trunk/vz-create.pl 2008/02/08 21:45:37 38 @@ -3,14 +3,17 @@ # Dobrica Pavlinusic 2007-01-07 # use strict; -use Shell qw/host mkdir vzsplit rm/; +use Shell qw/mkdir vzsplit rm/; use IO::Prompt; use Regexp::Common qw/net/; +use lib 'lib'; +use VZ; # default debian distribution my $dist = 'etch'; # debian mirror to use my $debian_mirror_uri = 'http://www.debian.org/debian'; +my $arh = 'i386'; # split physicial machine in how meny virtual ones? my $ve_total = 4; # swap size (Mb) @@ -18,6 +21,11 @@ # diskspace my $diskspace = '2G:4G'; +$dist = 'testing'; +$arh = 'amd64'; + +check_root; + my $config_file = $0; $config_file =~ s!-create.pl!-tools.conf!; warn "## $config_file\n"; @@ -30,20 +38,22 @@ print "Creating new OpenVZ instance...\n"; -my $arg = shift @ARGV || ''; - my ($hostname, $ip) = ('localhost',''); -if ($arg =~ m/$RE{net}{IPv4}/) { - $ip = $arg; - chomp($hostname); - $hostname = host($arg); - $hostname =~ s/^.*\s(\S+)$/$1/; -} elsif ($arg) { - $hostname = $arg; - $ip = host($arg); - chomp($ip); - $ip =~ s/^.*?$RE{net}{IPv4}{-keep}.*$/$1/s; +foreach my $arg ( @ARGV ) { + + if ($arg =~ m/$RE{net}{IPv4}/) { + $ip = $arg; + if ( my $h = hostname2ip($arg) ) { + $hostname = $h; + } + } elsif ($arg) { + if ( my $addr = hostname2ip($arg) ) { + ( $hostname, $ip ) = ( $arg, $addr ); + } else { + $hostname = $arg; + } + } } $ip ||= prompt('Enter IP: ', -require => { @@ -66,11 +76,11 @@ mkdir('-p', "$vz_root/root/$ve_id", "$vz_root/private/$ve_id"); -warn ">> installing debian $dist from $debian_mirror_uri\n"; +warn ">> installing debian $dist $arh from $debian_mirror_uri\n"; if (! -e "$vz_root/private/$ve_id/etc/debian_version") { - my $debootstrap = "debootstrap --arch i386 $dist $vz_root/private/$ve_id $debian_mirror_uri"; + my $debootstrap = "debootstrap --arch $arh $dist $vz_root/private/$ve_id $debian_mirror_uri"; warn "# $debootstrap\n"; system($debootstrap); @@ -92,6 +102,8 @@ } else { vzsplit('-n', $ve_total, '-s', $swap_size * 1024, '>', $conf_path); + die "configuration file not created" unless -e $conf_path; + open(my $tmp, '>>', $conf_path) || die "can't open $conf_path: $!"; print $tmp "OSTEMPLATE=debian-3.1\n"; close($tmp);