| 1 | package WWW::Hetzner::Cloud::Network; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Network object | ||||||||||||
| 3 | |||||||||||||
| 4 | 25 | our $VERSION = '0.100'; | |||||||||||
| 5 | |||||||||||||
| 6 | 25 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 25 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 25 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 25 | has _client => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | required => 1, | ||||||||||||
| 14 | weak_ref => 1, | ||||||||||||
| 15 | init_arg => 'client', | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | 25 | has id => ( is => 'ro' ); | |||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 25 | has name => ( is => 'rw' ); | |||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | 25 | has ip_range => ( is => 'ro' ); | |||||||||||
| 25 | |||||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | has subnets => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | has routes => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 31 | |||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | has servers => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | has labels => ( is => 'rw', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 37 | |||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | has protection => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 25 | has created => ( is => 'ro' ); | |||||||||||
| 43 | |||||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | has load_balancers => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 46 | |||||||||||||
| 47 | |||||||||||||
| 48 | 25 | has expose_routes_to_vswitch => ( is => 'ro', default => 0 ); | |||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | # Actions | ||||||||||||
| 52 | sub update { | ||||||||||||
| 53 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 54 | 0 | ▶ | croak "Cannot update network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 0 | my $result = $self->_client->put("/networks/" . $self->id, { | |||||||||||
| 57 | name => $self->name, | ||||||||||||
| 58 | labels => $self->labels, | ||||||||||||
| 59 | }); | ||||||||||||
| 60 | 0 | return $self; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | sub delete { | ||||||||||||
| 65 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 66 | 0 | ▶ | croak "Cannot delete network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | |||||||||||||
| 68 | 0 | $self->_client->delete("/networks/" . $self->id); | |||||||||||
| 69 | 0 | return 1; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | sub add_subnet { | ||||||||||||
| 74 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
add_subnet: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 75 | 0 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 0 | ▶ | croak "ip_range required" unless $opts{ip_range}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 0 | ▶ | croak "network_zone required" unless $opts{network_zone}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 0 | ▶ | croak "type required" unless $opts{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | my $body = { | ||||||||||||
| 81 | ip_range => $opts{ip_range}, | ||||||||||||
| 82 | network_zone => $opts{network_zone}, | ||||||||||||
| 83 | type => $opts{type}, | ||||||||||||
| 84 | 0 | }; | |||||||||||
| 85 | 0 | ▶ | $body->{vswitch_id} = $opts{vswitch_id} if $opts{vswitch_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | |||||||||||||
| 87 | 0 | $self->_client->post("/networks/" . $self->id . "/actions/add_subnet", $body); | |||||||||||
| 88 | 0 | return $self; | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | sub delete_subnet { | ||||||||||||
| 93 | 0 | ▶ | my ($self, $ip_range) = @_; | ||||||||||
|
Subroutine
delete_subnet: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 94 | 0 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | ▶ | croak "ip_range required" unless $ip_range; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | |||||||||||||
| 97 | 0 | $self->_client->post("/networks/" . $self->id . "/actions/delete_subnet", { | |||||||||||
| 98 | ip_range => $ip_range, | ||||||||||||
| 99 | }); | ||||||||||||
| 100 | 0 | return $self; | |||||||||||
| 101 | } | ||||||||||||
| 102 | |||||||||||||
| 103 | |||||||||||||
| 104 | sub add_route { | ||||||||||||
| 105 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
add_route: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 106 | 0 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | 0 | ▶ | croak "destination required" unless $opts{destination}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 0 | ▶ | croak "gateway required" unless $opts{gateway}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | |||||||||||||
| 110 | $self->_client->post("/networks/" . $self->id . "/actions/add_route", { | ||||||||||||
| 111 | destination => $opts{destination}, | ||||||||||||
| 112 | gateway => $opts{gateway}, | ||||||||||||
| 113 | 0 | }); | |||||||||||
| 114 | 0 | return $self; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | |||||||||||||
| 118 | sub delete_route { | ||||||||||||
| 119 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
delete_route: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 120 | 0 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | 0 | ▶ | croak "destination required" unless $opts{destination}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | 0 | ▶ | croak "gateway required" unless $opts{gateway}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | |||||||||||||
| 124 | $self->_client->post("/networks/" . $self->id . "/actions/delete_route", { | ||||||||||||
| 125 | destination => $opts{destination}, | ||||||||||||
| 126 | gateway => $opts{gateway}, | ||||||||||||
| 127 | 0 | }); | |||||||||||
| 128 | 0 | return $self; | |||||||||||
| 129 | } | ||||||||||||
| 130 | |||||||||||||
| 131 | |||||||||||||
| 132 | sub refresh { | ||||||||||||
| 133 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 134 | 0 | ▶ | croak "Cannot refresh network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | |||||||||||||
| 136 | 0 | my $result = $self->_client->get("/networks/" . $self->id); | |||||||||||
| 137 | 0 | my $data = $result->{network}; | |||||||||||
| 138 | |||||||||||||
| 139 | 0 | $self->name($data->{name}); | |||||||||||
| 140 | 0 | ▶ | $self->labels($data->{labels} // {}); | ||||||||||
|
Condition0%0/2
$data->{"labels"} // {}
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
| |||||||||||||
| 141 | |||||||||||||
| 142 | 0 | return $self; | |||||||||||
| 143 | } | ||||||||||||
| 144 | |||||||||||||
| 145 | |||||||||||||
| 146 | sub data { | ||||||||||||
| 147 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 148 | return { | ||||||||||||
| 149 | 1 | id => $self->id, | |||||||||||
| 150 | name => $self->name, | ||||||||||||
| 151 | ip_range => $self->ip_range, | ||||||||||||
| 152 | subnets => $self->subnets, | ||||||||||||
| 153 | routes => $self->routes, | ||||||||||||
| 154 | servers => $self->servers, | ||||||||||||
| 155 | labels => $self->labels, | ||||||||||||
| 156 | protection => $self->protection, | ||||||||||||
| 157 | created => $self->created, | ||||||||||||
| 158 | }; | ||||||||||||
| 159 | } | ||||||||||||
| 160 | |||||||||||||
| 161 | |||||||||||||
| 162 | |||||||||||||
| 163 | 25 | 1; | |||||||||||
| 164 | |||||||||||||
| 165 | __END__ | ||||||||||||