« lib/WWW/Hetzner/CLI/Cmd/Firewall/Cmd/AddRule.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/Zone/Cmd/Create.pm »
| 1 | package WWW::Hetzner::Cloud::Network; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Network object | ||||||||||||
| 3 | |||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 60 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 60 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 60 | has _client => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | required => 1, | ||||||||||||
| 14 | weak_ref => 1, | ||||||||||||
| 15 | init_arg => 'client', | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | 60 | has id => ( is => 'ro' ); | |||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 60 | has name => ( is => 'rw' ); | |||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | 60 | 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 | 60 | 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 | 60 | has expose_routes_to_vswitch => ( is => 'ro', default => 0 ); | |||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | # Actions | ||||||||||||
| 52 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 53 | 0 | my ($self) = @_; | |||||||||||
| 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 | 0 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 65 | 0 | my ($self) = @_; | |||||||||||
| 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 | 1 | ▶ | sub add_subnet { | ||||||||||
|
Subroutine
add_subnet: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||
| 74 | 1 | my ($self, %opts) = @_; | |||||||||||
| 75 | 1 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 1 | ▶ | croak "ip_range required" unless $opts{ip_range}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 1 | ▶ | croak "network_zone required" unless $opts{network_zone}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 1 | ▶ | croak "type required" unless $opts{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | 1 | return $self->_client->networks->add_subnet($self->id, %opts); | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | 1 | ▶ | sub delete_subnet { | ||||||||||
|
Subroutine
delete_subnet: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 85 | 1 | my ($self, $ip_range) = @_; | |||||||||||
| 86 | 1 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 1 | ▶ | croak "ip_range required" unless $ip_range; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | |||||||||||||
| 89 | 1 | return $self->_client->networks->delete_subnet($self->id, $ip_range); | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | |||||||||||||
| 93 | 1 | ▶ | sub add_route { | ||||||||||
|
Subroutine
add_route: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 94 | 1 | my ($self, %opts) = @_; | |||||||||||
| 95 | 1 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 1 | ▶ | croak "destination required" unless $opts{destination}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 1 | ▶ | croak "gateway required" unless $opts{gateway}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | |||||||||||||
| 99 | 1 | return $self->_client->networks->add_route($self->id, %opts); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 1 | ▶ | sub delete_route { | ||||||||||
|
Subroutine
delete_route: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 104 | 1 | my ($self, %opts) = @_; | |||||||||||
| 105 | 1 | ▶ | croak "Cannot modify network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 1 | ▶ | croak "destination required" unless $opts{destination}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | 1 | ▶ | croak "gateway required" unless $opts{gateway}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | |||||||||||||
| 109 | 1 | return $self->_client->networks->delete_route($self->id, %opts); | |||||||||||
| 110 | } | ||||||||||||
| 111 | |||||||||||||
| 112 | |||||||||||||
| 113 | 0 | ▶ | sub refresh { | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 114 | 0 | my ($self) = @_; | |||||||||||
| 115 | 0 | ▶ | croak "Cannot refresh network without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 116 | |||||||||||||
| 117 | 0 | my $result = $self->_client->get("/networks/" . $self->id); | |||||||||||
| 118 | 0 | my $data = $result->{network}; | |||||||||||
| 119 | |||||||||||||
| 120 | 0 | $self->name($data->{name}); | |||||||||||
| 121 | 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"}
| |||||||||||||
| 122 | |||||||||||||
| 123 | 0 | return $self; | |||||||||||
| 124 | } | ||||||||||||
| 125 | |||||||||||||
| 126 | |||||||||||||
| 127 | 1 | ▶ | sub data { | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 128 | 1 | my ($self) = @_; | |||||||||||
| 129 | return { | ||||||||||||
| 130 | 1 | id => $self->id, | |||||||||||
| 131 | name => $self->name, | ||||||||||||
| 132 | ip_range => $self->ip_range, | ||||||||||||
| 133 | subnets => $self->subnets, | ||||||||||||
| 134 | routes => $self->routes, | ||||||||||||
| 135 | servers => $self->servers, | ||||||||||||
| 136 | labels => $self->labels, | ||||||||||||
| 137 | protection => $self->protection, | ||||||||||||
| 138 | created => $self->created, | ||||||||||||
| 139 | }; | ||||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | |||||||||||||
| 143 | |||||||||||||
| 144 | 60 | 1; | |||||||||||
| 145 | |||||||||||||
| 146 | __END__ | ||||||||||||