| 1 | # | ||
| 2 | # This file is part of Net-Gandi | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2012 by Natal Ngétal. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | package Net::Gandi::Hosting; | ||
| 10 | { | ||
| 11 | $Net::Gandi::Hosting::VERSION = '1.122180'; | ||
| 12 | } | ||
| 13 | |||
| 14 | # ABSTRACT: Hosting interface | ||
| 15 | |||
| 16 | use Moose; | ||
| 17 | use MooseX::Params::Validate; | ||
| 18 | use namespace::autoclean; | ||
| 19 | |||
| 20 | use Net::Gandi::Types Client => { -as => 'Client_T' }; | ||
| 21 | use Net::Gandi::Hosting::Datacenter; | ||
| 22 | use Net::Gandi::Hosting::VM; | ||
| 23 | use Net::Gandi::Hosting::Disk; | ||
| 24 | use Net::Gandi::Hosting::Image; | ||
| 25 | use Net::Gandi::Hosting::Iface; | ||
| 26 | use Net::Gandi::Hosting::IP; | ||
| 27 | |||
| 28 | has client => ( | ||
| 29 | is => 'rw', | ||
| 30 | isa => Client_T, | ||
| 31 | required => 1, | ||
| 32 | ); | ||
| 33 | |||
| 34 | |||
| 35 | sub vm { | ||
| 36 | my ( $self, $id ) = validated_list( | ||
| 37 | \@_, | ||
| 38 | id => { isa => 'Int', optional => 1 } | ||
| 39 | ); | ||
| 40 | |||
| 41 | my %args = ( client => $self->client ); | ||
| 42 | $args{id} = $id if $id; | ||
| 43 | |||
| 44 | my $vm = Net::Gandi::Hosting::VM->new(%args); | ||
| 45 | |||
| 46 | return $vm; | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | sub disk { | ||
| 51 | my ( $self, $id ) = validated_list( | ||
| 52 | \@_, | ||
| 53 | id => { isa => 'Int', optional => 1 } | ||
| 54 | ); | ||
| 55 | |||
| 56 | my %args = ( client => $self->client ); | ||
| 57 | $args{id} = $id if $id; | ||
| 58 | |||
| 59 | my $disk = Net::Gandi::Hosting::Disk->new(%args); | ||
| 60 | |||
| 61 | return $disk; | ||
| 62 | } | ||
| 63 | |||
| 64 | |||
| 65 | sub image { | ||
| 66 | my ( $self, $id ) = validated_list( | ||
| 67 | \@_, | ||
| 68 | id => { isa => 'Int', optional => 1 } | ||
| 69 | ); | ||
| 70 | |||
| 71 | my %args = ( client => $self->client ); | ||
| 72 | $args{id} = $id if $id; | ||
| 73 | |||
| 74 | my $image = Net::Gandi::Hosting::Image->new(%args); | ||
| 75 | |||
| 76 | return $image; | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | sub iface { | ||
| 81 | my ( $self, $id ) = validated_list( | ||
| 82 | \@_, | ||
| 83 | id => { isa => 'Int', optional => 1 } | ||
| 84 | ); | ||
| 85 | |||
| 86 | my %args = ( client => $self->client ); | ||
| 87 | $args{id} = $id if $id; | ||
| 88 | |||
| 89 | my $iface = Net::Gandi::Hosting::Iface->new(%args); | ||
| 90 | |||
| 91 | return $iface; | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | sub ip { | ||
| 96 | my ( $self, $id ) = validated_list( | ||
| 97 | \@_, | ||
| 98 | id => { isa => 'Int', optional => 1 } | ||
| 99 | ); | ||
| 100 | |||
| 101 | my %args = ( client => $self->client ); | ||
| 102 | $args{id} = $id if $id; | ||
| 103 | |||
| 104 | my $ip = Net::Gandi::Hosting::IP->new(%args); | ||
| 105 | |||
| 106 | return $ip; | ||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | sub datacenter { | ||
| 111 | my ( $self ) = @_; | ||
| 112 | |||
| 113 | my $datacenter = Net::Gandi::Hosting::Datacenter->new( | ||
| 114 | client => $self->client, | ||
| 115 | ); | ||
| 116 | |||
| 117 | return $datacenter; | ||
| 118 | } | ||
| 119 | |||
| 120 | no Moose; | ||
| 121 | __PACKAGE__->meta->make_immutable; | ||
| 122 | |||
| 123 | 1; | ||
| 124 | |||
| 125 | __END__ |