Permalink
Browse files

Merge branch '0.29' of https://github.com/krimdomu/Rex into learning

  • Loading branch information...
2 parents 57e707b + a10efb5 commit d7ac9dc81684e5a8033aa2d92c6eec86387456ff @SvenDowideit committed May 22, 2012
View
@@ -1,3 +1,18 @@
+2012-05-17 Jan Gehring <jan.gehring, gmail.com> (0.29.0)
+ * Fixed wrong error message in LibVirt/create.pm - Sven Dowideit
+ * Added dumpxml command (LibVirt) - Sven Dowideit
+ * Updated docs - Sven Dowideit
+ * Default listening on all ip's for vnc (LibVirt) - Sven Dowideit
+ * Added more colorized output options - Samuele Tognini
+ * Fixed a logging bug - Samuele Tognini
+ * -Tv command line option output information about requested task - Samuele Tognini
+ * -Tv command line option output information about batches and environments - Samuele Tognini
+ * Updated some error messages output - Samuele Tognini
+ * Added iflist command (LibVirt) - Jean Charles Passard
+ * Added blklist command (LibVirt) - Jean Charles Passard
+ * Added vncdisplay command (LibVirt) - Sven Dowideit
+ * Fixed a bug with hooks and packages #41 - Jan Gehring
+
2012-05-08 Jan Gehring <jan.gehring, gmail.com> (0.28.0)
* fixed a bug with relative source file names inside external modules
* new parameter -Tv to display more information about tasks
View
@@ -152,7 +152,7 @@ if($opts{'e'}) {
$code = eval($code);
if($@) {
- Rex::Logger::info("Error in eval line: $@\n");
+ Rex::Logger::info("Error in eval line: $@\n", "warn");
exit 1;
}
@@ -302,27 +302,35 @@ Rex::Logger::debug("Initializing Logger from parameters found in $::rexfile");
if($opts{'T'}) {
Rex::Logger::debug("Listing Tasks and Batches");
- print "Tasks\n";
+ _print_color("Tasks\n", "yellow");
my @tasks = Rex::Task->get_tasks;
unless(@tasks) {
print " no tasks defined.\n";
exit;
}
- for my $task (Rex::Task->get_tasks) {
+ if(defined $ARGV[0]) {
+ @tasks = map { Rex::Task->is_task($_) ? $_ : () } @ARGV;
+ }
+ for my $task (@tasks) {
printf " %-30s %s\n", $task, Rex::Task->get_desc($task);
if($opts{'v'}) {
- if(! $no_color) {
- print colored(['green'], " Servers: " . join(", ", @{ Rex::Task->get_task($task)->{'server'} }) . "\n");
- }
- else {
- print " Servers: " . join(", ", @{ Rex::Task->get_task($task)->{'server'} }) . "\n";
- }
+ _print_color(" Servers: " . join(", ", @{ Rex::Task->get_task($task)->{'server'} }) . "\n");
}
}
- print "Batches\n";
+ _print_color("Batches\n", 'yellow');
for my $batch (Rex::Batch->get_batchs) {
printf " %-30s %s\n", $batch, Rex::Batch->get_desc($batch);
+ if($opts{'v'}) {
+ _print_color(" " . join(" ", Rex::Batch->get_batch($batch)) . "\n");
+ }
}
+ _print_color("Environments\n", "yellow");
+ print " " . join("\n ", Rex::Commands->get_environments()) . "\n";
+
+ Rex::global_sudo(0);
+ Rex::Logger::debug("Removing lockfile") if(! exists $opts{'F'});
+ unlink("$::rexfile.lock") if(! exists $opts{'F'});
+ CORE::exit 0;
}
eval {
@@ -345,7 +353,7 @@ eval {
};
if($@) {
- Rex::Logger::info("Error running task/batch: $@");
+ Rex::Logger::info("Error running task/batch: $@", "warn");
}
# lock loeschen
@@ -355,6 +363,18 @@ unlink("$::rexfile.lock") if(! exists $opts{'F'});
select STDOUT;
+sub _print_color {
+ my ($msg, $color) = @_;
+ $color = 'green' if !defined($color);
+
+ if($no_color) {
+ print $msg;
+ }
+ else {
+ print colored([$color], $msg);
+ }
+};
+
__END__
=pod
View
@@ -82,7 +82,7 @@ our (@EXPORT,
@CONNECTION_STACK,
$GLOBAL_SUDO);
-$VERSION = "0.28.0";
+$VERSION = "0.28.99.0";
sub push_connection {
push @CONNECTION_STACK, $_[0];
@@ -234,7 +234,7 @@ sub connect {
# auth unsuccessfull
unless($conn->is_authenticated) {
- Rex::Logger::info("Wrong username or password. Or wrong key.");
+ Rex::Logger::info("Wrong username or password. Or wrong key.", "warn");
# after jobs
die("Wrong username or password. Or wrong key.");
@@ -308,6 +308,8 @@ Many thanks to the contributors for their work (alphabetical order).
=item Hiroaki Nakamura
+=item Jean Charles Passard
+
=item Jeen Lee
=item Jose Luis Martinez
@@ -316,6 +318,8 @@ Many thanks to the contributors for their work (alphabetical order).
=item Sascha Guenther
+=item Sven Dowideit
+
=back
=cut
@@ -296,7 +296,7 @@ sub _request {
my $res = $ua->post("http://" . $self->{'__endpoint'}, \%param);
if($res->code >= 500) {
- Rex::Logger::info("Error on request");
+ Rex::Logger::info("Error on request", "warn");
Rex::Logger::debug($res->content);
return;
}
View
@@ -273,9 +273,8 @@ sub task {
use strict;
}
- unless($dont_register_tasks) {
- Rex::Task->create_task($task_name, @_, $options);
- }
+ $options->{'dont_register'} = $dont_register_tasks;
+ Rex::Task->create_task($task_name, @_, $options);
}
=item desc($description)
@@ -788,7 +787,10 @@ sub get {
=item before($task => sub {})
-Run code before connecting to the server.
+Run code before executing the specified task.
+(if called repeatedly, each sub will be appended to a list of 'before' functions)
+
+Note: must come after the definition of the specified task
before mytask => sub {
my ($server) = @_;
@@ -798,12 +800,23 @@ Run code before connecting to the server.
=cut
sub before {
my ($task, $code) = @_;
+ my ($package, $file, $line) = caller;
+ if($package ne "main") {
+ if($task !~ m/:/) {
+ $package =~ s/::/:/g;
+ $task = $package . ":" . $task;
+ }
+ }
+
Rex::Task->modify_task($task, "before", $code);
}
=item after($task => sub {})
Run code after the task is finished.
+(if called repeatedly, each sub will be appended to a list of 'after' functions)
+
+Note: must come after the definition of the specified task
after mytask => sub {
my ($server, $failed) = @_;
@@ -815,12 +828,23 @@ Run code after the task is finished.
=cut
sub after {
my ($task, $code) = @_;
+ my ($package, $file, $line) = caller;
+ if($package ne "main") {
+ if($task !~ m/:/) {
+ $package =~ s/::/:/g;
+ $task = $package . ":" . $task;
+ }
+ }
+
Rex::Task->modify_task($task, "after", $code);
}
=item around($task => sub {})
Run code before and after the task is finished.
+(if called repeatedly, each sub will be appended to a list of 'around' functions)
+
+Note: must come after the definition of the specified task
around mytask => sub {
my ($server, $position) = @_;
@@ -836,6 +860,14 @@ Run code before and after the task is finished.
=cut
sub around {
my ($task, $code) = @_;
+ my ($package, $file, $line) = caller;
+ if($package ne "main") {
+ if($task !~ m/:/) {
+ $package =~ s/::/:/g;
+ $task = $package . ":" . $task;
+ }
+ }
+
Rex::Task->modify_task($task, "around", $code);
}
@@ -921,6 +953,12 @@ sub get_environment {
}
}
+sub get_environments {
+ my $class = shift;
+
+ return sort { $a cmp $b } keys %{$environments};
+}
+
sub say {
return unless $_[0];
print @_, "\n";
@@ -224,7 +224,7 @@ sub iptables {
run "iptables $cmd";
if($? != 0) {
- Rex::Logger::info("Error setting iptable rule: $cmd");
+ Rex::Logger::info("Error setting iptable rule: $cmd", "warn");
die("Error setting iptable rule: $cmd");
}
}
@@ -112,7 +112,7 @@ sub kmod {
Rex::Logger::debug("Loading Kernel Module: $module");
run "$load_command $module";
unless($? == 0) {
- Rex::Logger::info("Error loading Kernel Module: $module");
+ Rex::Logger::info("Error loading Kernel Module: $module", "warn");
die("Error loading Kernel Module: $module");
}
else {
@@ -128,7 +128,7 @@ sub kmod {
run "$unload_command_str $module";
unless($? == 0) {
- Rex::Logger::info("Error unloading Kernel Module: $module");
+ Rex::Logger::info("Error unloading Kernel Module: $module", "warn");
die("Error unloading Kernel Module: $module");
}
else {
@@ -85,7 +85,7 @@ sub checkout {
eval "use $class;";
if($@) {
- Rex::Logger::info("Error loading SCM: $@\n");
+ Rex::Logger::info("Error loading SCM: $@\n", "warn");
die("Error loading SCM: $@");
}
@@ -142,7 +142,7 @@ sub service {
return 1 if ! $is_multiple;
}
else {
- Rex::Logger::info("Error starting $service.");
+ Rex::Logger::info("Error starting $service.", "warn");
return 0 if ! $is_multiple;
}
}
@@ -156,7 +156,7 @@ sub service {
return 1 if ! $is_multiple;
}
else {
- Rex::Logger::info("Error restarting $service.");
+ Rex::Logger::info("Error restarting $service.", "warn");
return 0 if ! $is_multiple;
}
@@ -169,7 +169,7 @@ sub service {
return 1 if ! $is_multiple;
}
else {
- Rex::Logger::info("Error stopping $service.");
+ Rex::Logger::info("Error stopping $service.", "warn");
return 0 if ! $is_multiple;
}
@@ -182,7 +182,7 @@ sub service {
return 1 if ! $is_multiple;
}
else {
- Rex::Logger::info("Error $service does not support reload");
+ Rex::Logger::info("Error $service does not support reload", "warn");
return 0 if ! $is_multiple;
}
@@ -82,7 +82,7 @@ sub sysctl {
return $ret;
}
else {
- Rex::Logger::info("Error getting sysctl key: $key");
+ Rex::Logger::info("Error getting sysctl key: $key", "warn");
die("Error getting sysctl key: $key");
}
@@ -71,7 +71,7 @@ sub connect {
sleep 1;
goto CON_SSH if($fail_connect < Rex::Config->get_max_connect_fails(server => $server)); # try connecting 3 times
- Rex::Logger::info("Can't connect to $server");
+ Rex::Logger::info("Can't connect to $server", "warn");
$self->{connected} = 0;
View
@@ -83,7 +83,7 @@ my $log_opened = 0;
sub init {
return if $silent;
eval {
- die if(Rex::Config->get_log_filename);
+ die if(Rex::Config->get_log_filename || ! Rex::Config->get_log_facility);
require Sys::Syslog;
Sys::Syslog->import;
openlog("rex", "ndelay,pid", Rex::Config->get_log_facility);
@@ -94,11 +94,19 @@ sub init {
}
sub info {
- my ($msg) = @_;
- return if $silent;
+ my ($msg, $type) = @_;
+ my $color = 'green';
+
+ if (defined($type)) {
+ CHECK_COLOR: {
+ $type eq 'warn' && do { $color = 'yellow'; last CHECK_COLOR; };
+ $type eq 'error' && do { $color = 'red'; last CHECK_COLOR; };
+ }
+ }
+ return if $silent;
+
$msg = format_string($msg, "INFO");
-
# workaround for windows Sys::Syslog behaviour on forks
# see: #6
unless($log_opened) {
@@ -120,7 +128,7 @@ sub info {
print STDERR "$msg\n" unless($::QUIET);
}
else {
- print STDERR colored(['green'], "$msg\n") unless($::QUIET);
+ print STDERR colored([$color], "$msg\n") unless($::QUIET);
}
# workaround for windows Sys::Syslog behaviour on forks
@@ -60,7 +60,7 @@ sub update {
my $f = run("DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::=--force-confold --force-yes -y install $pkg" . ($version?"=$version":""));
unless($? == 0) {
- Rex::Logger::info("Error installing $pkg.");
+ Rex::Logger::info("Error installing $pkg.", "warn");
Rex::Logger::debug($f);
die("Error installing $pkg");
}
@@ -80,7 +80,7 @@ sub remove {
run("dpkg --purge $pkg");
unless($? == 0) {
- Rex::Logger::info("Error removing $pkg.");
+ Rex::Logger::info("Error removing $pkg.", "warn");
Rex::Logger::debug($f);
die("Error removing $pkg");
}
Oops, something went wrong.

0 comments on commit d7ac9dc

Please sign in to comment.