| 1 | package Net::HAProxy; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | $Net::HAProxy::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use IO::Scalar; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | subtype 'ReadWritableSocket', | ||||||||||||||||||||||||||||
| 13 | as 'Str', | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | where { -w $_ && -r $_ && -S $_ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
-w $_ and -r $_
MC/DC0%0/2
-w $_ and -r $_
-w $_
-r $_
Truth table0%0/3
A and B
A= -w $_B= -r $_
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | message { "'$_' is not a read/writable socket." }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | has socket => (is => 'ro', isa => 'ReadWritableSocket', required => 1); | |||||||||||||||||||||||||||
| 18 | 1 | has timeout => (is => 'ro', isa => 'Int', default => 1); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # ABSTRACT: control HAProxy through a socket | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub _send_command { | ||||||||||||||||||||||||||
|
Subroutine
_send_command: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $cmd) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | my $sock = IO::Socket::UNIX->new( | |||||||||||||||||||||||||||
| 27 | Peer => $self->socket, | ||||||||||||||||||||||||||||
| 28 | Type => SOCK_STREAM, | ||||||||||||||||||||||||||||
| 29 | Timeout => $self->timeout | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | $sock->write("$cmd\n"); | |||||||||||||||||||||||||||
| 33 | 0 | local $/ = undef; | |||||||||||||||||||||||||||
| 34 | 0 | my $data = (<$sock>); | |||||||||||||||||||||||||||
| 35 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return $data; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub stats { | ||||||||||||||||||||||||||
|
Subroutine
stats: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $iid = $args->{iid} || '-1'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'iid'} || '-1'
MC/DC0%0/1
$args->{'iid'} || '-1'
$args->{'iid'}
Truth table0%0/2
A
A= $args->{'iid'}
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $type = $args->{type} || '-1'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'type'} || '-1'
MC/DC0%0/1
$args->{'type'} || '-1'
$args->{'type'}
Truth table0%0/2
A
A= $args->{'type'}
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $sid = $args->{sid} || '-1'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'sid'} || '-1'
MC/DC0%0/1
$args->{'sid'} || '-1'
$args->{'sid'}
Truth table0%0/2
A
A= $args->{'sid'}
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $data = $self->_send_command("show stat $iid $type $sid"); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $sh = IO::Scalar->new(\$data); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $fields = $sh->getline; | |||||||||||||||||||||||||||
| 53 | 0 | $fields =~ s/^\# //; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $csv = Text::CSV->new; | |||||||||||||||||||||||||||
| 56 | 0 | $csv->parse($fields); | |||||||||||||||||||||||||||
| 57 | 0 | $csv->column_names(grep { length } $csv->fields); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $res = $csv->getline_hr_all($sh); pop @$res; | |||||||||||||||||||||||||||
| 60 | 0 | return $res; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub info { | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 67 | 0 | my $data = $self->_send_command("show info"); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $info = {}; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | for my $line (split /\n/, $data) { | |||||||||||||||||||||||||||
| 72 | 0 | chomp $line; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | next unless length $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($key, $value) = split /:\s+/, $line; | |||||||||||||||||||||||||||
| 75 | 0 | $info->{$key} = $value; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | return $info; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub set_weight { | ||||||||||||||||||||||||||
|
Subroutine
set_weight: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($self, $pxname, $svname, $weight) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | die "Invalid weight must be between 0 and 100" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$weight > 0 and $weight <= 100
MC/DC0%0/2
$weight > 0 and $weight <= 100
$weight > 0
$weight <= 100
Truth table0%0/3
A and B
A= $weight > 0B= $weight <= 100
| |||||||||||||||||||||||||||||
| 87 | unless $weight > 0 and $weight <= 100; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my $response = $self->_send_command("enable server $pxname/$svname $weight\%"); | |||||||||||||||||||||||||||
| 90 | 0 | chomp $response; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | die $response if length $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub enable_server { | ||||||||||||||||||||||||||
|
Subroutine
enable_server: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($self, $pxname, $svname) = @_; | |||||||||||||||||||||||||||
| 98 | 0 | my $response = $self->_send_command("enable server $pxname/$svname"); | |||||||||||||||||||||||||||
| 99 | 0 | chomp $response; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | die $response if length $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub disable_server { | ||||||||||||||||||||||||||
|
Subroutine
disable_server: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | my ($self, $pxname, $svname) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | my $response = $self->_send_command("disable server $pxname/$svname"); | |||||||||||||||||||||||||||
| 107 | 0 | chomp $response; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | die $response if length $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub errors { | ||||||||||||||||||||||||||
|
Subroutine
errors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 115 | 0 | return $self->_send_command("show errors"); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub sessions { | ||||||||||||||||||||||||||
|
Subroutine
sessions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 121 | 0 | return $self->_send_command("show sess"); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||