| 1 | package Helm::Task::rsync_put; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Moose; | ||
| 5 | use Net::OpenSSH; | ||
| 6 | |||
| 7 | extends 'Helm::Task'; | ||
| 8 | |||
| 9 | sub validate { | ||
| 10 | my $self = shift; | ||
| 11 | my $helm = $self->helm; | ||
| 12 | my $extra_options = $helm->extra_options; | ||
| 13 | |||
| 14 | # make sure we have local and remote options and that the local file exists and is readable | ||
| 15 | my $local = $extra_options->{local}; | ||
| 16 | $helm->die('Missing option: local') unless $local; | ||
| 17 | $helm->die('Missing option: remote') unless $extra_options->{remote}; | ||
| 18 | $helm->die("Invalid option: local - Directory \"$local\" does not exist") unless -d $local; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub help { | ||
| 22 | my $self = shift; | ||
| 23 | return <<END; | ||
| 24 | Sync a local directory to a remote server(s) using rysnc. Takes the | ||
| 25 | following required options: | ||
| 26 | |||
| 27 | --local | ||
| 28 | The name of the local directory being synced. | ||
| 29 | |||
| 30 | --remote | ||
| 31 | The full path to the directory on the remote server. | ||
| 32 | END | ||
| 33 | } | ||
| 34 | |||
| 35 | sub execute { | ||
| 36 | my ($self, %args) = @_; | ||
| 37 | my $server = $args{server}; | ||
| 38 | my $ssh = $args{ssh}; | ||
| 39 | my $options = $self->helm->extra_options; | ||
| 40 | my $local = $options->{local}; | ||
| 41 | my $remote = $options->{remote}; | ||
| 42 | |||
| 43 | # send our file over there | ||
| 44 | $ssh->rsync_put({archive => 1}, $local, $remote) | ||
| 45 | || $helm->die("Can't rsync directory ($local) to server $server: " . $ssh->error); | ||
| 46 | $helm->log->info("Directory $local rsync'ed to $server:$remote"); | ||
| 47 | } | ||
| 48 | |||
| 49 | __PACKAGE__->meta->make_immutable; | ||
| 50 | |||
| 51 | 1; |