Rex-Inline
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Rex/Inline.pm view on Meta::CPAN
#
# (c) Johnny Wang <johnnywang1991@msn.com>
#
# vim: set ts=2
# vim: set sw=2
# vim: set tw=0
# vim: set expandtab
=encoding UTF-8
=head1 NAME
Rex::Inline - write Rex in perl
=head1 DESCRIPTION
Rex::Inline is an API of I<Rex> module write with Moose.
when you want use rex in your perl program, and do not want to use the B<rex> command line, you can try to use this module.
=head1 GETTING HELP
=over 4
=item * Bug Tracker: L<https://github.com/johnnywang1991/RexInline/issues>
=back
=head1 SYNOPSIS
use Rex::Inline;
use Rex::Inline::Test;
my $rex_inline = Rex::Inline->new(
use_debug => 0
# now you can set default authentication
user => $user, # optional
password => $password, # optional
public_key => $public_key, # optional
private_key => $private_key,# optional
);
# add default authentication
# if you didn't provide authentication in your task, Rex::Inline will use this as default one
# or if your authentication is failed, Rex::Inline will use this retry the ssh connection
$rex_inline->add_auth({
user => $user,
password => $password,
sudo => TRUE,
});
$rex_inline->add_auth({
user => $user,
public_key => $public_key,
private_key => $private_key,
});
# data reference like this
$rex_inline->add_task(
{
name => 'something_uniq_string', # name is required when add data_reference task
func => sub { # func is required when add data_reference task
...
},
user => $user,
server => [@server],
# if need password
password => $password,
# optional
public_key => $public_key,
private_key => $private_key,
}
);
# or Rex::Inline::Test is based on Rex::Inline::Base module
# See Rex::Inline::Base Documents
$rex_inline->add_task(
Rex::Inline::Test->new(
user => $user,
server => [@server],
# if need password
password => $password,
# optional
public_key => $public_key,
private_key => $private_key,
# input param, in any format you want
input => $input,
)
);
$rex_inline->execute;
# get rex task reports
$rex_inline->reports;
=cut
package Rex::Inline;
use strict;
use warnings;
use utf8;
use FindBin;
use POSIX 'strftime';
our $VERSION = '0.0.8'; # VERSION
use Moose;
use MooseX::AttributeShortcuts;
use File::Temp 'mkdtemp';
use File::Path::Tiny;
use File::Spec::Functions;
use YAML::XS qw(LoadFile Dump);
use JSON;
use Parallel::ForkManager;
use Rex -feature => 0.31;
use Rex::Config;
use Rex::Group;
use Rex::TaskList;
# custom module
use Rex::Inline::Test;
use namespace::autoclean;
use Moose::Util::TypeConstraints;
subtype 'TaskType'
=> as 'ArrayRef[Object]';
coerce 'TaskType'
=> from 'ArrayRef',
=> via { [ map { (ref $_ eq 'HASH') ? Rex::Inline::Test->new($_) : $_ } @$_ ] };
no Moose::Util::TypeConstraints;
=head1 ATTRIBUTES
=over 4
=item user
set default ssh connection user
=item password
set default ssh connection password
=item private_key
set default private_key filename
=item public_key
set default public_key filename
=cut
has [qw(user password private_key public_key)] => (is => 'ro', predicate => 1);
=item use_debug
set/get debug option (Bool)
Print or not debug level log
see B<rex -d> option
default is 0 (disabled)
=cut
has use_debug => (is => 'rw', default => 0);
=item use_cache
set/get use_cache option (Bool)
Use or not B<rex -c> option
default is 1 (enable)
=cut
has use_cache => (is => 'rw', default => 1);
=item use_report
set/get use_report option (Bool)
show rex report result
default is 1 (enable)
=cut
has use_report => (is => 'rw', default => 1);
=item use_report_log
set/get use_report_log option (Bool)
report to log
default is 0 (false)
=cut
has use_report_log => (is => 'rw', default => 0);
=item log_dir
set/get log dir (String)
default is C<"./rexlogs/">
=cut
has log_dir => (is => 'rw', default => './rexlogs/');
=item parallelism
set/get parallelism nums (Int)
see B<rex -t> option
default is 5
=cut
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.246 second using v1.00-cache-2.02-grep-82fe00e-cpan-2cc899e4a130 )