diff --git a/.travis.yml b/.travis.yml index a799d2e..71b9ab0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/MANIFEST b/MANIFEST index d0cd1c4..36e7146 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 diff --git a/lib/Net/Etcd.pm b/lib/Net/Etcd.pm index bd5125e..448bda3 100644 --- a/lib/Net/Etcd.pm +++ b/lib/Net/Etcd.pm @@ -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); @@ -257,6 +258,22 @@ sub lease { ); } +=head2 maintenance + +Returns a L 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 object. diff --git a/lib/Net/Etcd/Maintenance.pm b/lib/Net/Etcd/Maintenance.pm new file mode 100644 index 0000000..a4ba139 --- /dev/null +++ b/lib/Net/Etcd/Maintenance.pm @@ -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; diff --git a/t/maint.t b/t/maint.t new file mode 100644 index 0000000..c849841 --- /dev/null +++ b/t/maint.t @@ -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;