| 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::Disk; | ||
| 10 | { | ||
| 11 | $Net::Gandi::Hosting::Disk::VERSION = '1.122180'; | ||
| 12 | } | ||
| 13 | |||
| 14 | # ABSTRACT: Disk 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::Error qw(_validated_params); | ||
| 22 | |||
| 23 | use Carp; | ||
| 24 | |||
| 25 | |||
| 26 | has 'id' => ( is => 'rw', isa => 'Int' ); | ||
| 27 | |||
| 28 | has client => ( | ||
| 29 | is => 'rw', | ||
| 30 | isa => Client_T, | ||
| 31 | required => 1, | ||
| 32 | ); | ||
| 33 | |||
| 34 | |||
| 35 | sub list { | ||
| 36 | my ( $self, $params ) = validated_list( | ||
| 37 | \@_, | ||
| 38 | opts => { isa => 'HashRef', optional => 1 } | ||
| 39 | ); | ||
| 40 | |||
| 41 | $params ||= {}; | ||
| 42 | return $self->client->api_call( "disk.list", $params ); | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | sub count { | ||
| 47 | my ( $self, $params ) = validated_list( | ||
| 48 | \@_, | ||
| 49 | opts => { isa => 'HashRef', optional => 1 } | ||
| 50 | ); | ||
| 51 | |||
| 52 | $params ||= {}; | ||
| 53 | return $self->client->api_call('disk.count', $params); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub info { | ||
| 58 | my ( $self ) = @_; | ||
| 59 | |||
| 60 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 61 | |||
| 62 | return $self->client->api_call( 'disk.info', $self->id ); | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | sub get_options { | ||
| 67 | my ( $self ) = @_; | ||
| 68 | |||
| 69 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 70 | return $self->client->api_call( 'disk.get_options', $self->id ); | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | sub create { | ||
| 75 | my ( $self, $params ) = validated_list( | ||
| 76 | \@_, | ||
| 77 | disk_spec => { isa => 'HashRef', optional => 1 } | ||
| 78 | ); | ||
| 79 | |||
| 80 | _validated_params('disk_create', $params); | ||
| 81 | |||
| 82 | return $self->client->api_call( "disk.create", $params ); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | sub create_from { | ||
| 87 | my ( $self, $params, $src_disk_id ) = validated_list( | ||
| 88 | \@_, | ||
| 89 | disk_spec => { isa => 'HashRef', optional => 1 }, | ||
| 90 | src_disk_id => { isa => 'Int'} | ||
| 91 | ); | ||
| 92 | |||
| 93 | _validated_params('disk_create_from', $params); | ||
| 94 | |||
| 95 | return $self->client->api_call( "disk.create_from", $params, $src_disk_id ); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | sub update { | ||
| 100 | my ( $self, $params ) = validated_list( | ||
| 101 | \@_, | ||
| 102 | disk_spec => { isa => 'HashRef', optional => 1 } | ||
| 103 | ); | ||
| 104 | |||
| 105 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 106 | return $self->client->api_call('disk.update', $self->id, $params); | ||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | sub delete { | ||
| 111 | my ( $self ) = @_; | ||
| 112 | |||
| 113 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 114 | return $self->client->api_call('disk.delete', $self->id); | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | sub attach { | ||
| 119 | my ( $self, $vm_id, $params ) = validated_list( | ||
| 120 | \@_, | ||
| 121 | vm_id => { isa => 'Int'}, | ||
| 122 | opts => { isa => 'HashRef'}, | ||
| 123 | ); | ||
| 124 | |||
| 125 | carp 'Required parameter id is not defined' if ( ! $vm_id ); | ||
| 126 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 127 | |||
| 128 | return $params | ||
| 129 | ? $self->client->api_call('vm.disk_attach', $vm_id, $self->id, $params) | ||
| 130 | : $self->client->api_call('vm.disk_attach', $vm_id, $self->id); | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | sub detach { | ||
| 135 | my ( $self, $vm_id ) = validated_list( | ||
| 136 | \@_, | ||
| 137 | vm_id => { isa => 'Int'} | ||
| 138 | ); | ||
| 139 | |||
| 140 | carp 'Required parameter id is not defined' if ( ! $vm_id ); | ||
| 141 | carp 'Required parameter id is not defined' if ( ! $self->id ); | ||
| 142 | |||
| 143 | return $self->client->api_call('vm.disk_detach', $vm_id, $self->id); | ||
| 144 | } | ||
| 145 | |||
| 146 | no Moose; | ||
| 147 | __PACKAGE__->meta->make_immutable; | ||
| 148 | |||
| 149 | 1; | ||
| 150 | |||
| 151 | __END__ |