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