]> git.proxmox.com Git - pve-guest-common.git/commitdiff
VZDump/Plugin: avoid cyclic dependency
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 13 Sep 2017 08:30:14 +0000 (10:30 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 21 Sep 2017 07:48:08 +0000 (09:48 +0200)
pve-guest-common is above qemu-server, pve-container and thus also
pve-manager in the package hierarchy.
The latter hosts PVE::VZDump, so using it here adds a cyclic
dependency between pve-manager and pve-guest-common.

Move the log method to the base plugin class and inline the
run_command function directly do the plugins cmd method.

pve-manager's PVE::VZDump may use this plugins static log function
then instead of its own copy.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/VZDump/Plugin.pm

index 989135222f2f90295b7cdb3f1b3afb6adf3fbaa6..772b619e445a18d3e67fb018fc9ec859001c82be 100644 (file)
@@ -2,7 +2,36 @@ package PVE::VZDump::Plugin;
 
 use strict;
 use warnings;
-use PVE::VZDump;
+
+use POSIX qw(strftime);
+
+use PVE::Tools;
+use PVE::SafeSyslog;
+
+my $log_level = {
+    err =>  'ERROR:',
+    info => 'INFO:',
+    warn => 'WARN:',
+};
+
+sub debugmsg {
+    my ($mtype, $msg, $logfd, $syslog) = @_;
+
+    chomp $msg;
+
+    return if !$msg;
+
+    my $pre = $log_level->{$mtype} || $log_level->{'err'};
+
+    my $timestr = strftime ("%F %H:%M:%S", CORE::localtime);
+
+    syslog ($mtype eq 'info' ? 'info' : 'err', "$pre $msg") if $syslog;
+
+    foreach my $line (split (/\n/, $msg)) {
+       print STDERR "$pre $line\n";
+       print $logfd "$timestr $pre $line\n" if $logfd;
+    }
+}
 
 sub set_logfd {
     my ($self, $logfd) = @_;
@@ -13,7 +42,12 @@ sub set_logfd {
 sub cmd {
     my ($self, $cmdstr, %param) = @_;
 
-    return PVE::VZDump::run_command($self->{logfd}, $cmdstr, %param);   
+    my $logfunc = sub {
+       my $line = shift;
+       debugmsg ('info', $line, $self->{logfd});
+    };
+
+    PVE::Tools::run_command($cmdstr, %param, logfunc => $logfunc);
 }
 
 sub cmd_noerr {
@@ -28,13 +62,13 @@ sub cmd_noerr {
 sub loginfo {
     my ($self, $msg) = @_;
 
-    PVE::VZDump::debugmsg('info', $msg, $self->{logfd}, 0);
+    debugmsg('info', $msg, $self->{logfd}, 0);
 }
 
 sub logerr {
     my ($self, $msg) = @_;
 
-    PVE::VZDump::debugmsg('err', $msg, $self->{logfd}, 0);
+    debugmsg('err', $msg, $self->{logfd}, 0);
 }
 
 sub type {