export host selection per service, RT#17914
authorIvan Kohler <ivan@freeside.biz>
Mon, 24 Sep 2012 01:36:09 +0000 (18:36 -0700)
committerIvan Kohler <ivan@freeside.biz>
Mon, 24 Sep 2012 01:36:09 +0000 (18:36 -0700)
FS/FS/part_export.pm
FS/FS/part_export/shellcommands.pm
FS/FS/part_export/shellcommands_withdomain.pm

index c757d36..b0f708a 100644 (file)
@@ -9,6 +9,7 @@ use FS::Record qw( qsearch qsearchs dbh );
 use FS::part_svc;
 use FS::part_export_option;
 use FS::part_export_machine;
+use FS::svc_export_machine;
 use FS::export_svc;
 
 #for export modules, though they should probably just use it themselves
@@ -470,6 +471,26 @@ sub _rebless {
   $self;
 }
 
+=item svc_machine
+
+=cut
+
+sub svc_machine {
+  my( $self, $svc_x ) = @_;
+
+  return $self->machine unless $self->machine eq '_SVC_MACHINE';
+
+  my $svc_export_machine = qsearchs('svc_export_machine', {
+    'svcnum'    => $svc_x->svcnum,
+    'exportnum' => $self->exportnum,
+  })
+    #would only happen if you add this export to existing services without a
+    #machine set then try to run exports without setting it... right?
+    or die "No hostname selected for ".($self->exportname || $self->exporttype);
+
+  return $svc_export_machine->part_export_machine->machine;
+}
+
 #these should probably all go away, just let the subclasses define em
 
 =item export_insert SVC_OBJECT
index b9d6551..ca4e524 100644 (file)
@@ -98,8 +98,7 @@ tie my %options, 'Tie::IxHash',
 
 %info = (
   'svc'         => 'svc_acct',
-  'desc'        =>
-    'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
+  'desc'        => 'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
   'options'     => \%options,
   'nodomain'    => 'Y',
   'svc_machine' => 1,
@@ -344,7 +343,7 @@ sub _export_command {
 
   my @ssh_cmd_args = (
     user          => $self->option('user') || 'root',
-    host          => $self->machine,
+    host          => $self->svc_machine($svc_acct),
     command       => $command_string,
     stdin_string  => $stdin_string,
     ignored_errors    => $self->option('ignored_errors') || '',
@@ -357,7 +356,7 @@ sub _export_command {
     eval { ssh_cmd(@ssh_cmd_args) };
     $error = $@;
     $error = $error->full_message if ref $error; # Exception::Class::Base
-    return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+    return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($svc_acct). ')'
       if $error;
   }
   else {
@@ -417,7 +416,7 @@ sub _export_replace {
     #  $error ||= "can't change RADIUS groups";
     #}
   }
-  return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+  return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
     if $error;
 
   $new_agent_custid = $new_cust_main ? $new_cust_main->agent_custid : '';
@@ -441,7 +440,7 @@ sub _export_replace {
 
   my @ssh_cmd_args = (
     user          => $self->option('user') || 'root',
-    host          => $self->machine,
+    host          => $self->svc_machine($new),
     command       => $command_string,
     stdin_string  => $stdin_string,
     ignored_errors    => $self->option('ignored_errors') || '',
@@ -454,7 +453,7 @@ sub _export_replace {
     eval { ssh_cmd(@ssh_cmd_args) };
     $error = $@;
     $error = $error->full_message if ref $error; # Exception::Class::Base
-    return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+    return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
       if $error;
   }
   else {
index 1ebf5f6..1b59589 100644 (file)
@@ -80,10 +80,11 @@ tie my %options, 'Tie::IxHash',
 ;
 
 %info = (
-  'svc'     => 'svc_acct',
-  'desc'    => 'Real-time export via remote SSH (vpopmail, ISPMan)',
-  'options' => \%options,
-  'notes'   => <<'END'
+  'svc'         => 'svc_acct',
+  'desc'        => 'Real-time export via remote SSH (vpopmail, ISPMan, MagicMail)',
+  'options'     => \%options,
+  'svc_machine' => 1,
+  'notes'       => <<'END'
 Run remote commands via SSH.  username@domain (rather than just usernames) are
 considered unique (also see shellcommands).  You probably want this if the
 commands you are running will accept a domain as a parameter, and will allow