/[vz-tools]/trunk/vz-create.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/vz-create.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 35 by dpavlin, Thu Dec 13 23:50:47 2007 UTC revision 38 by dpavlin, Fri Feb 8 21:45:37 2008 UTC
# Line 3  Line 3 
3  # Dobrica Pavlinusic <dpavlin@rot13.org> 2007-01-07  # Dobrica Pavlinusic <dpavlin@rot13.org> 2007-01-07
4  #  #
5  use strict;  use strict;
6  use Shell qw/host mkdir vzsplit rm/;  use Shell qw/mkdir vzsplit rm/;
7  use IO::Prompt;  use IO::Prompt;
8  use Regexp::Common qw/net/;  use Regexp::Common qw/net/;
9    use lib 'lib';
10    use VZ;
11    
12  # default debian distribution  # default debian distribution
13  my $dist = 'etch';  my $dist = 'etch';
14  # debian mirror to use  # debian mirror to use
15  my $debian_mirror_uri = 'http://www.debian.org/debian';  my $debian_mirror_uri = 'http://www.debian.org/debian';
16    my $arh = 'i386';
17  # split physicial machine in how meny virtual ones?  # split physicial machine in how meny virtual ones?
18  my $ve_total = 4;  my $ve_total = 4;
19  # swap size (Mb)  # swap size (Mb)
# Line 18  my $swap_size = 512; Line 21  my $swap_size = 512;
21  # diskspace  # diskspace
22  my $diskspace = '2G:4G';  my $diskspace = '2G:4G';
23    
24    $dist = 'testing';
25    $arh = 'amd64';
26    
27    check_root;
28    
29  my $config_file = $0;  my $config_file = $0;
30  $config_file =~ s!-create.pl!-tools.conf!;  $config_file =~ s!-create.pl!-tools.conf!;
31  warn "## $config_file\n";  warn "## $config_file\n";
# Line 30  if (-e $config_file) { Line 38  if (-e $config_file) {
38    
39  print "Creating new OpenVZ instance...\n";  print "Creating new OpenVZ instance...\n";
40    
 my $arg = shift @ARGV || '';  
   
41  my ($hostname, $ip) = ('localhost','');  my ($hostname, $ip) = ('localhost','');
42    
43  if ($arg =~ m/$RE{net}{IPv4}/) {  foreach my $arg ( @ARGV ) {
44          $ip = $arg;  
45          chomp($hostname);          if ($arg =~ m/$RE{net}{IPv4}/) {
46          $hostname = host($arg);                  $ip = $arg;
47          $hostname =~ s/^.*\s(\S+)$/$1/;                  if ( my $h = hostname2ip($arg) ) {
48  } elsif ($arg) {                          $hostname = $h;
49          $hostname = $arg;                  }
50          $ip = host($arg);          } elsif ($arg) {
51          chomp($ip);                  if ( my $addr = hostname2ip($arg) ) {
52          $ip =~ s/^.*?$RE{net}{IPv4}{-keep}.*$/$1/s;                          ( $hostname, $ip ) = ( $arg, $addr );
53                    } else {
54                            $hostname = $arg;
55                    }
56            }
57  }  }
58    
59  $ip ||= prompt('Enter IP: ', -require => {  $ip ||= prompt('Enter IP: ', -require => {
# Line 66  warn ">> creating directories\n"; Line 76  warn ">> creating directories\n";
76    
77  mkdir('-p', "$vz_root/root/$ve_id", "$vz_root/private/$ve_id");  mkdir('-p', "$vz_root/root/$ve_id", "$vz_root/private/$ve_id");
78    
79  warn ">> installing debian $dist from $debian_mirror_uri\n";  warn ">> installing debian $dist $arh from $debian_mirror_uri\n";
80    
81  if (! -e "$vz_root/private/$ve_id/etc/debian_version") {  if (! -e "$vz_root/private/$ve_id/etc/debian_version") {
82    
83          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";
84          warn "# $debootstrap\n";          warn "# $debootstrap\n";
85          system($debootstrap);          system($debootstrap);
86    
# Line 92  if (-e $conf_path) { Line 102  if (-e $conf_path) {
102  } else {  } else {
103          vzsplit('-n', $ve_total, '-s', $swap_size * 1024, '>', $conf_path);          vzsplit('-n', $ve_total, '-s', $swap_size * 1024, '>', $conf_path);
104    
105            die "configuration file not created" unless -e $conf_path;
106    
107          open(my $tmp, '>>', $conf_path) || die "can't open $conf_path: $!";          open(my $tmp, '>>', $conf_path) || die "can't open $conf_path: $!";
108          print $tmp "OSTEMPLATE=debian-3.1\n";          print $tmp "OSTEMPLATE=debian-3.1\n";
109          close($tmp);          close($tmp);

Legend:
Removed from v.35  
changed lines
  Added in v.38

  ViewVC Help
Powered by ViewVC 1.1.26