Net::Etcd - etcd v3 REST API.
Etcd v3.1.0 or greater is required. To use the v3 API make sure to set environment
variable ETCDCTL_API=3. Precompiled binaries can be downloaded at https://github.com/etcd-io/etcd/releases.
$etcd = Net::Etcd->new(); # host: 127.0.0.1 port: 2379
$etcd = Net::Etcd->new({ host => $host, port => $port, ssl => 1 });
# put key
$put_key = $etcd->put({ key =>'foo1', value => 'bar' });
# check for success of a transaction
$put_key->is_success;
# get single key
$key = $etcd->range({ key =>'test0' });
# return single key value or the first in a list.
$key->get_value
# get range of keys
$range = $etcd->range({ key =>'test0', range_end => 'test100' });
# return array { key => value } pairs from range request.
my @users = $range->all
# delete single key
$etcd->deleterange({ key => 'test0' });
# watch key range, streaming.
$watch = $etcd->watch( { key => 'foo', range_end => 'fop'}, sub {
my ($result) = @_;
print STDERR Dumper($result);
})->create;
# create/grant 20 second lease
$etcd->lease( { ID => 7587821338341002662, TTL => 20 } )->grant;
# attach lease to put
$etcd->put( { key => 'foo2', value => 'bar2', lease => 7587821338341002662 } );
# add new user
$etcd->user( { name => 'samba', password => 'foo' } )->add;
# add new user role
$role = $etcd->role( { name => 'myrole' } )->add;
# grant read permission for the foo key to myrole
$etcd->role_perm( { name => 'myrole', key => 'foo', permType => 'READWRITE' } )->grant;
# grant role
$etcd->user_role( { user => 'samba', role => 'myrole' } )->grant;
# defrag member's backend database
$defrag = $etcd->maintenance()->defragment;
print "Defrag request complete!" if $defrag->is_success;
# member version
$v = $etcd->version;
# list members
$etcd->member()->list;
Net::Etcd is object oriented interface to the v3 REST API provided by the etcd grpc-gateway.
The etcd host. Defaults to 127.0.0.1
Default 2379.
Username for authentication, defaults to $ENV{ETCD_CLIENT_USERNAME}
Authentication credentials, defaults to $ENV{ETCD_CLIENT_PASSWORD}
Path to ca_file, defaults to $ENV{ETCD_CLIENT_CA_FILE}
Path to key_file, defaults to $ENV{ETCD_CLIENT_KEY_FILE}
Path to cert_file, defaults to $ENV{ETCD_CLIENT_CERT_FILE}
Path to cacert, defaults to $ENV{ETCD_CLIENT_CACERT_FILE}.
To enable set to 1
defaults to /v3beta
The full api path. Defaults to http://127.0.0.1:2379/v3alpha
The token that is passed during authentication. This is generated during the authentication process and stored until no longer valid or username is changed.
Returns the etcd member version
$etcd->version()
See Net::Etcd::Watch
$etcd->watch({ key =>'foo', range_end => 'fop' })
$etcd->role({ role => 'foo' });
See Net::Etcd::Auth::RolePermission
Grants or revoke permission of a specified key or range to a specified role.
$etcd->role_perm(
{ name => 'myrole', key => 'bar', permType => 'READ', prefix => 1 } )->grant;
$etcd->user_role({ name => 'samba', role => 'foo' });
See Net::Etcd::Auth
$etcd->auth({ name => 'samba', password => 'foo' })->authenticate;
$etcd->auth()->enable;
$etcd->auth()->disable
See Net::Etcd::Lease
$etcd->lease( { ID => 7587821338341002662, TTL => 20 } )->grant;
$etcd->maintenance()->snapshot
$etcd->member()->list
See Net::Etcd::User
$etcd->user( { name => 'samba', password => 'foo' } )->add;
$etcd->put({ key =>'foo1', value => 'bar' });
See Net::Etcd::KV::DeleteRange
$etcd->deleterange({ key=>'test0' });
$etcd->range({ key =>'test0', range_end => 'test100' });
$etcd->txn({ compare => \@compare, success => \@op });
$etcd->op({ request_put => $put });
$etcd->op({ request_delete_range => $range });
$etcd->compare( { key => 'foo', result => 'EQUAL', target => 'VALUE', value => 'baz' });
$etcd->compare( { key => 'foo', target => 'CREATE', result => 'NOT_EQUAL', create_revision => '2' });
Initialize configuration checks to see if etcd is installed locally.
Sam Batschelet (hexfusion)
Ananth Kavuri
Michael Fung
The etcd developers and community.
The etcd v3 API is in heavy development and can change at anytime please see api_reference_v3 for latest details.
Authentication provided by this module will only work with etcd v3.3.0+
Copyright 2018 Sam Batschelet (hexfusion).
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.