Skip to content

Commit

Permalink
Merge pull request #11 from hexfusion/maint
Browse files Browse the repository at this point in the history
Add Maintenance class.
  • Loading branch information
hexfusion authored Jun 12, 2017
2 parents f83fd49 + 2ecc5cc commit 590124a
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: required
env:
global:
- ETCD_VER=v3.2.0-rc.0
- ETCD_VER=v3.2.0
- ETCDCTL_API=3
- ETCD_TEST_HOST=127.0.0.1
- ETCD_TEST_PORT=2379
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib/Net/Etcd/Auth.pm
lib/Net/Etcd/Auth/Role.pm
lib/Net/Etcd/Config.pm
lib/Net/Etcd/Lease.pm
lib/Net/Etcd/Maintenance.pm
lib/Net/Etcd/Role/Actions.pm
lib/Net/Etcd/KV.pm
lib/Net/Etcd/KV/Put.pm
Expand Down
17 changes: 17 additions & 0 deletions lib/Net/Etcd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use Net::Etcd::Auth;
use Net::Etcd::Config;
use Net::Etcd::Watch;
use Net::Etcd::Lease;
use Net::Etcd::Maintenance;
use Net::Etcd::User;
use Types::Standard qw(Str Int Bool HashRef);

Expand Down Expand Up @@ -257,6 +258,22 @@ sub lease {
);
}

=head2 maintenance
Returns a L<Net::Etcd::Maintenance> object.
=cut

sub maintenance {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
return Net::Etcd::Maintenance->new(
etcd => $self,
cb => $cb,
( $options ? %$options : () ),
);
}

=head2 user
Returns a L<Net::Etcd::User> object.
Expand Down
46 changes: 46 additions & 0 deletions lib/Net/Etcd/Maintenance.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use utf8;
package Net::Etcd::Maintenance;

use strict;
use warnings;

=encoding utf8
=cut
use Moo;

with 'Net::Etcd::Role::Actions';
use namespace::clean;

=head1 NAME
Net::Etcd::Maintenance
=cut

our $VERSION = '0.009';

=head1 DESCRIPTION
Provides support for maintenance related actions.
=cut

=head1 PUBLIC METHODS
=head2 snapshot
Snapshot sends a snapshot of the entire backend from a member over a stream to a client.
=cut

sub snapshot {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/snapshot';
$self->{json_args} = '{}';
$self->request;
return $self;
}

1;
33 changes: 33 additions & 0 deletions t/maint.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!perl

use strict;
use warnings;
use Net::Etcd;
use Test::More;
use Test::Exception;
use Data::Dumper;
my ($host, $port);

if ( $ENV{ETCD_TEST_HOST} and $ENV{ETCD_TEST_PORT}) {
$host = $ENV{ETCD_TEST_HOST};
$port = $ENV{ETCD_TEST_PORT};
plan tests => 2;
}
else {
plan skip_all => "Please set environment variable ETCD_TEST_HOST and ETCD_TEST_PORT.";
}

my $maint;
my $etcd = Net::Etcd->new( { host => $host, port => $port } );

lives_ok(
sub {
$maint = $etcd->maintenance()->snapshot;
},
"snapshot create"
);

#print STDERR Dumper($maint);
cmp_ok( $maint->{response}{content}, 'ne', "", "snapshot create" );

1;

0 comments on commit 590124a

Please sign in to comment.