/[vz-tools]/trunk/lib/VZ.pm
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/lib/VZ.pm

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

revision 42 by dpavlin, Fri Feb 8 23:53:40 2008 UTC revision 59 by dpavlin, Mon Feb 2 15:10:11 2009 UTC
# Line 7  ip2hostname Line 7  ip2hostname
7  hostname2ip  hostname2ip
8    
9  conf_veids  conf_veids
10    runscript
11    
12  vzctl  vzctl
13  vzlist  vzlist
# Line 26  use Data::Dump qw/dump/; Line 27  use Data::Dump qw/dump/;
27  our $vz_root = '/vz';  our $vz_root = '/vz';
28  our $vz_conf = '/etc/vz/conf';  our $vz_conf = '/etc/vz/conf';
29    
30    $vz_root = '/var/lib/vz' if ! -e $vz_root && -e '/var/lib/vz';
31    
32  =head1 NAME  =head1 NAME
33    
34  VZ - helper functions for VZ tools  VZ - helper functions for VZ tools
# Line 87  sub conf_veids { Line 90  sub conf_veids {
90          open( my $cfgs, 'find /etc/vz/conf -maxdepth 1 -name "*.conf" |' ) || die "can't run find: $!";          open( my $cfgs, 'find /etc/vz/conf -maxdepth 1 -name "*.conf" |' ) || die "can't run find: $!";
91          while(<$cfgs>) {          while(<$cfgs>) {
92                  chomp;                  chomp;
93                  if ( m#^.+/(\d+)\.conf$# ) {                  if ( m{^.+/(\d+)\.conf$} ) {
94                          if ( -d "$vz_root/private/$1" ) {                          if ( -d "$vz_root/private/$1" ) {
95                                  push @c, $1;                                  push @c, $1;
96                          } else {                          } else {
# Line 100  sub conf_veids { Line 103  sub conf_veids {
103          return @c;          return @c;
104  }  }
105    
106    =head2 runscript
107    
108      runscript( $veid, '/path/to/script' );
109    
110    =cut
111    
112    sub runscript {
113            my ( $veid, $path ) = @_;
114    
115            if ( open(my $fh, $path) ) {
116                    while(<$fh>) {
117                            chomp;
118                            next if (m/^\s*$/);
119                            if (/^#\s+(.+)$/) {
120                                    warn ">> $1\n";
121                            } else {
122                                    vzctl('exec', $veid, $_);
123                            }
124                    }
125            } else {
126                    warn "can't open $path: $!";
127            }
128    }
129                    
130    
131  =head2 vzctl  =head2 vzctl
132    
133    vzctl('set','--something',42);    vzctl('set','--something',42);
# Line 108  sub conf_veids { Line 136  sub conf_veids {
136    
137  sub vzctl {  sub vzctl {
138          my @args = @_;          my @args = @_;
139          warn "## vzctl ", join(" ",@args), "\n";          my $a = join(' ', @args);
140            # hide passwords from output
141            $a =~ s/(--userpasswd\s+\w+:)\w+/$1********/;
142            warn "## vzctl $a\n";
143          system('vzctl',@args) == 0 or die "vzctl @args failed: $?"          system('vzctl',@args) == 0 or die "vzctl @args failed: $?"
144  }  }
145    
# Line 127  sub vzlist { Line 158  sub vzlist {
158    
159    
160          my $output;          my $output;
161            $output = {} if defined $args->{hash};
162    
163          if ( ! @vzlist_fields ) {          if ( ! @vzlist_fields ) {
164                  open(my $vzlist, 'vzlist -L |') || die "can't start vzlist -L: $!";                  open(my $vzlist, 'vzlist -L |') || die "can't start vzlist -L: $!";

Legend:
Removed from v.42  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26