--- trunk/lib/VZ.pm 2008/02/08 23:53:40 42 +++ trunk/lib/VZ.pm 2008/08/14 22:47:54 49 @@ -7,6 +7,7 @@ hostname2ip conf_veids +runscript vzctl vzlist @@ -87,7 +88,7 @@ open( my $cfgs, 'find /etc/vz/conf -maxdepth 1 -name "*.conf" |' ) || die "can't run find: $!"; while(<$cfgs>) { chomp; - if ( m#^.+/(\d+)\.conf$# ) { + if ( m{^.+/(\d+)\.conf$} ) { if ( -d "$vz_root/private/$1" ) { push @c, $1; } else { @@ -100,6 +101,31 @@ return @c; } +=head2 runscript + + runscript( $veid, '/path/to/script' ); + +=cut + +sub runscript { + my ( $veid, $path ) = @_; + + if ( open(my $fh, $path) ) { + while(<$fh>) { + chomp; + next if (m/^\s*$/); + if (/^#\s+(.+)$/) { + warn ">> $1\n"; + } else { + vzctl('exec', $veid, $_); + } + } + } else { + warn "can't open $path: $!"; + } +} + + =head2 vzctl vzctl('set','--something',42); @@ -108,7 +134,10 @@ sub vzctl { my @args = @_; - warn "## vzctl ", join(" ",@args), "\n"; + my $a = join(' ', @args); + # hide passwords from output + $a =~ s/(--userpasswd\s+\w+:)\w+/$1********/; + warn "## vzctl $a\n"; system('vzctl',@args) == 0 or die "vzctl @args failed: $?" }