Consul
view release on metacpan or search on metacpan
lib/Consul/API/Agent.pm view on Meta::CPAN
sub check_warn {
my ($self, $check_id, %args) = @_;
croak 'usage: $agent->check_warn($check_id, [%args])' if grep { !defined } ($check_id);
$$self->_api_exec($$self->_agent_endpoint."/check/warn/".$check_id, 'PUT', %args);
return;
}
sub check_fail {
my ($self, $check_id, %args) = @_;
croak 'usage: $agent->check_fail($check_id, [%args])' if grep { !defined } ($check_id);
$$self->_api_exec($$self->_agent_endpoint."/check/fail/".$check_id, 'PUT', %args);
return;
}
sub service_register {
my ($self, $service, %args) = @_;
croak 'usage: $agent->service_register($service, [%args])' if grep { !defined } ($service);
$service = Consul::Service->new($service) if !blessed $service;
$$self->_api_exec($$self->_agent_endpoint."/service/register", 'PUT', %args, _content => $service->to_json);
return;
}
sub service_deregister {
my ($self, $service_id, %args) = @_;
croak 'usage: $agent->service_deregister($check_id, [%args])' if grep { !defined } ($service_id);
$$self->_api_exec($$self->_agent_endpoint."/service/deregister/".$service_id, 'PUT', %args);
return;
}
sub service_maintenance {
my ($self, $service_id, $enable, %args) = @_;
croak 'usage: $agent->service_maintenance($service_id, $enable, [%args])' if grep { !defined } ($service_id, $enable);
$$self->_api_exec($$self->_agent_endpoint."/service/maintenance/".$service_id, 'PUT', enable => ($enable ? "true" : "false"), %args);
return;
}
package Consul::API::Agent::Check;
$Consul::API::Agent::Check::VERSION = '0.027';
use Moo;
use Types::Standard qw(Str);
has node => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 );
has id => ( is => 'ro', isa => Str, init_arg => 'CheckID', required => 1 );
has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 );
has status => ( is => 'ro', isa => Str, init_arg => 'Status', required => 1 );
has notes => ( is => 'ro', isa => Str, init_arg => 'Notes', required => 1 );
has output => ( is => 'ro', isa => Str, init_arg => 'Output', required => 1 );
has service_id => ( is => 'ro', isa => Str, init_arg => 'ServiceID', required => 1 );
has service_name => ( is => 'ro', isa => Str, init_arg => 'ServiceName', required => 1 );
package Consul::API::Agent::Service;
$Consul::API::Agent::Service::VERSION = '0.027';
use Moo;
use Types::Standard qw(Str Int ArrayRef);
has id => ( is => 'ro', isa => Str, init_arg => 'ID', required => 1 );
has service => ( is => 'ro', isa => Str, init_arg => 'Service', required => 1 );
has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 );
has port => ( is => 'ro', isa => Int, init_arg => 'Port', required => 1 );
has tags => ( is => 'ro', isa => ArrayRef[Str], init_arg => 'Tags', required => 1, coerce => sub { $_[0] || [] } );
package Consul::API::Agent::Member;
$Consul::API::Agent::Member::VERSION = '0.027';
use Moo;
use Types::Standard qw(Str Int HashRef);
has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 );
has addr => ( is => 'ro', isa => Str, init_arg => 'Addr', required => 1 );
has port => ( is => 'ro', isa => Int, init_arg => 'Port', required => 1 );
has tags => ( is => 'ro', isa => HashRef[Str], init_arg => 'Tags', required => 1, coerce => sub { $_[0] || {} } );
has status => ( is => 'ro', isa => Int, init_arg => 'Status', required => 1 );
has protocol_min => ( is => 'ro', isa => Int, init_arg => 'ProtocolMin', required => 1 );
has protocol_max => ( is => 'ro', isa => Int, init_arg => 'ProtocolMax', required => 1 );
has protocol_cur => ( is => 'ro', isa => Int, init_arg => 'ProtocolCur', required => 1 );
has delegate_min => ( is => 'ro', isa => Int, init_arg => 'DelegateMin', required => 1 );
has delegate_max => ( is => 'ro', isa => Int, init_arg => 'DelegateMax', required => 1 );
has delegate_cur => ( is => 'ro', isa => Int, init_arg => 'DelegateCur', required => 1 );
package Consul::API::Agent::Self;
$Consul::API::Agent::Self::VERSION = '0.027';
use Moo;
use Types::Standard qw(HashRef);
use Type::Utils qw(class_type);
# XXX raw hash. not happy about this, but the list of config keys don't seem to be consistent across environments
has config => ( is => 'ro', isa => HashRef, init_arg => 'Config', required => 1, coerce => sub { $_[0] || {} } );
has member => ( is => 'ro', isa => class_type('Consul::API::Agent::Member'), init_arg => 'Member', required => 1, coerce => sub { Consul::API::Agent::Member->new($_[0]) } );
1;
=pod
=encoding UTF-8
=head1 NAME
Consul::API::Agent - Agent API
=head1 SYNOPSIS
use Consul;
my $agent = Consul->agent;
$agent->self;
=head1 DESCRIPTION
The Agent API is used to interact with the local Consul agent.
This API is fully documented at L<https://www.consul.io/docs/agent/http/agent.html>.
=head1 METHODS
=head2 checks
=head2 services
=head2 members
=head2 self
=head2 maintenance
=head2 join
=head2 force_leave
=head2 check_register
=head2 check_deregister
=head2 check_pass
=head2 check_warn
=head2 check_fail
=head2 service_register
=head2 service_deregister
=head2 service_maintenance
=head1 SEE ALSO
L<Consul>
( run in 0.662 second using v1.01-cache-2.11-cpan-39bf76dae61 )