Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Changer / null.pm
1 # Copyright (c) 2009-2012 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10 # for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 #
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
18
19 package Amanda::Changer::null;
20
21 use strict;
22 use warnings;
23 use vars qw( @ISA );
24 @ISA = qw( Amanda::Changer );
25
26 use File::Glob qw( :glob );
27 use File::Path;
28 use Amanda::Config qw( :getconf );
29 use Amanda::Debug;
30 use Amanda::Changer;
31 use Amanda::MainLoop;
32
33 =head1 NAME
34
35 Amanda::Changer::null
36
37 =head1 DESCRIPTION
38
39 This changer always returns reservations for null devices.  It is useful to add
40 a null device to a RAIT device configuration.  It takes no arguments.
41
42 Note that this changer's constructor is guaranteed not to return an error.
43
44 See the amanda-changers(7) manpage for usage information.
45
46 =cut
47
48 sub new {
49     my $class = shift;
50     my ($config, $tpchanger) = @_;
51
52     return bless ({}, $class);
53 }
54
55 sub load {
56     my $self = shift;
57     my %params = @_;
58     return if $self->check_error($params{'res_cb'});
59
60     $params{'res_cb'}->(undef, Amanda::Changer::null::Reservation->new()) if $params{'res_cb'};
61 }
62
63 sub info_key {
64     my $self = shift;
65     my ($key, %params) = @_;
66     my %results;
67     return if $self->check_error($params{'info_cb'});
68
69     if ($key eq 'num_slots') {
70         $results{$key} = 1;
71     } elsif ($key eq 'fast_search') {
72         $results{$key} = 1;
73     }
74
75     $params{'info_cb'}->(undef, %results) if $params{'info_cb'};
76 }
77
78 sub reset {
79     my $self = shift;
80     my %params = @_;
81     return if $self->check_error($params{'finished_cb'});
82
83     $params{'finished_cb'}->() if $params{'finished_cb'};
84 }
85
86 package Amanda::Changer::null::Reservation;
87 use vars qw( @ISA );
88 @ISA = qw( Amanda::Changer::Reservation );
89
90 sub new {
91     my $class = shift;
92     my $self = Amanda::Changer::Reservation::new($class);
93
94     $self->{'device'} = Amanda::Device->new("null:");
95     $self->{'this_slot'} = "null";
96
97     return $self;
98 }