Imported Upstream version 3.1.0
[debian/amanda] / perl / Amanda / Disklist.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.39
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6
7 package Amanda::Disklist;
8 use base qw(Exporter);
9 use base qw(DynaLoader);
10 require Amanda::Config;
11 package Amanda::Disklistc;
12 bootstrap Amanda::Disklist;
13 package Amanda::Disklist;
14 @EXPORT = qw();
15
16 # ---------- BASE METHODS -------------
17
18 package Amanda::Disklist;
19
20 sub TIEHASH {
21     my ($classname,$obj) = @_;
22     return bless $obj, $classname;
23 }
24
25 sub CLEAR { }
26
27 sub FIRSTKEY { }
28
29 sub NEXTKEY { }
30
31 sub FETCH {
32     my ($self,$field) = @_;
33     my $member_func = "swig_${field}_get";
34     $self->$member_func();
35 }
36
37 sub STORE {
38     my ($self,$field,$newval) = @_;
39     my $member_func = "swig_${field}_set";
40     $self->$member_func($newval);
41 }
42
43 sub this {
44     my $ptr = shift;
45     return tied(%$ptr);
46 }
47
48
49 # ------- FUNCTION WRAPPERS --------
50
51 package Amanda::Disklist;
52
53 *read_disklist_internal = *Amanda::Disklistc::read_disklist_internal;
54
55 # ------- VARIABLE STUBS --------
56
57 package Amanda::Disklist;
58
59
60 @EXPORT_OK = ();
61 %EXPORT_TAGS = ();
62
63
64 =head1 NAME
65
66 Amanda::Disklist - interface to the Amanda disklist
67
68 =head1 SYNOPSIS
69
70   use Amanda::Config qw( :init :getconf );
71   use Amanda::Disklist;
72
73   # .. call config_init()
74   my $cfgerr_level = Amanda::Disklist::read_disklist(
75     filename => $ARGV[0],
76     disk_class => "MyScript::Disk",
77   );
78   die("Config errors") if ($cfgerr_level >= $CFGERR_WARNINGS);
79   my $dle = Amanda::Disklist::get_disk($ARGV[1], $ARGV[2]);
80   die "No such DLE" unless defined($dle);
81
82   print "Diskname for this DLE: ", $dle->{name}, "\n";
83   print "Auth for this DLE's host: ", $dle->{host}->{auth}, "\n";
84   print "'record':", dumptype_getconf($dle->{config}, $DUMPTYPE_RECORD), "\n";
85
86 =head1 OVERVIEW
87
88 The Amanda disklist is a part of its configuration, so this module is
89 similar in function to L<Amanda::Config>.  In particular,
90 C<read_disklist> loads the disklist into process-global variables, and
91 returns an error status similar to that of L<Amanda::Config>.  Those
92 global variables are then used by the acces functions described below.
93
94 Amanda parses all DLE's as a simple tuple (host, diskname, device,
95 dumptype, interface, spindle), linked to a dumptype.  DLE's which
96 specify additional dumptype parameters within the C<disklist> file
97 result in the creation of a "hidden" dumptype with those parameters.
98 Consequently, most configuration data about a particular disk is
99 available in an C<Amanda::Config::dumptype_t> object, and that data is
100 not reproduced by this package.
101
102 This package differs from the underlying C code in that it separates
103 I<disk> configuration from I<host> configuration.  Furthermore, the
104 package does not provide storage for runtime parameters you might want
105 to associate with hosts or disks.  However, the objects this packages
106 creates are simple hashrefs that can be blessed with arbitrary class
107 names, so you can add whatever data and behaviors you like to these
108 objects.
109
110 =head1 FUNCTIONS
111
112 After calling C<Amanda::Config::config_init()>, call C<read_disklist>.
113 The following parameters are available:
114
115 =over 4
116
117 =item filename
118
119 Filename from which to read the disklist; defaults to the C<diskfile>
120 configuration parameter.
121
122 =item disk_class
123
124 Class with which to bless disk objects; defaults to
125 C<Amanda::Disklist::Disk>.
126
127 =item host_class
128
129 Class with which to bless host objects; defaults to
130 C<Amanda::Disklist::Host>.
131
132 =item interface_class
133
134 Class with which to bless interface objects; defaults to
135 C<Amanda::Disklist::Interface>.
136
137 =back
138
139 C<read_disklist> returns a config error level just like
140 C<config_init>. Once the disklist is loaded, call one of the following
141 functions to access the disklist.
142
143   get_host($host)           get the corresponding host object
144   all_hosts()               get a list of all host objects
145   get_disk($host, $disk)    get a specific disk object
146   all_disks()               get a list of all disk objects
147   get_interface($name)      get a specific interface object
148   all_interfaces()          get a list of all interface objects
149
150 =head1 Objects
151
152 =head2 Amanda::Disklist::Disk
153
154 A disk object has the following keys:
155
156 =over 4
157
158 =item host
159
160 Host object for this DLE
161
162 =item name
163
164 The disk name
165
166 =item device
167
168 The device, if one was specified separately from the disk name
169
170 =item spindle
171
172 The spindle specified in the disklist
173
174 =item config
175
176 An C<Amanda::Config::dumptype_t> object giving the configuration for
177 the disk; use C<dumptype_getconf> and other functions from
178 L<Amanda::Config> to examine it.
179
180 =back
181
182 =head2 Amanda::Disklist::Host
183
184 Note that, because host configuration parameters are specified in
185 dumptypes, there is no C<config> key for a host object.  Instead, the
186 relevant parameters are available as attributes of the object.
187
188 =over 4
189
190 =item hostname
191
192 hostname of this host
193
194 =item amandad_path
195
196 =item client_username
197
198 =item ssh_keys
199
200 =item auth
201
202 =item maxdumps
203
204 configuration parameters
205
206 =item disks
207
208 an array containing the names of all of the disks on this host.
209
210 =back
211
212 As a convenience, the C<Amanda::Disklist::Host> class also provides
213 methods C<get_disk($disk)>, to get a disk object on the host, and
214 C<all_disks()>, to get a list of all disk objects on this host.
215
216 =head2 Amanda::Disklist::Interface
217
218 Interface objects have only one key, C<config>, containing a
219 C<Amanda::Config::interface_t> object; use C<interface_getconf> and
220 other functions from L<Amanda::Config> to examine it.
221
222 =cut
223
224
225
226 use Amanda::Debug qw( :logging );
227 use Amanda::Config qw( :getconf config_dir_relative );
228
229
230 package Amanda::Disklist::Disk;
231
232 # methods
233
234 package Amanda::Disklist::Host;
235
236 sub get_disk {
237     my ($self, $disk) = @_;
238     return $Amanda::Disklist::disks{$self->{'hostname'}}{$disk};
239 }
240
241 sub all_disks {
242     my ($self) = @_;
243     return values %{$Amanda::Disklist::disks{$self->{'hostname'}}};
244 }
245
246 package Amanda::Disklist::Interface;
247
248 # methods
249
250 package Amanda::Disklist;
251
252 our (%disks, %hosts, %interfaces);
253
254 sub read_disklist {
255     my %params = @_;
256
257     return read_disklist_internal(
258         ($params{filename} or config_dir_relative(getconf($CNF_DISKFILE))),
259         \%disks, ($params{disk_class} or "Amanda::Disklist::Disk"),
260         \%hosts, ($params{host_class} or "Amanda::Disklist::Host"),
261         \%interfaces, ($params{interface_class} or "Amanda::Disklist::Interface"),
262     );
263 }
264
265 sub get_host {
266     my ($hostname) = @_;
267     return $hosts{$hostname};
268 }
269
270 sub all_hosts {
271     return values %hosts;
272 }
273
274 sub get_disk {
275     my ($hostname, $diskname) = @_;
276     return $disks{$hostname}->{$diskname};
277 }
278
279 sub all_disks {
280     my @rv;
281     foreach my $disk (values %disks) {
282         push @rv, (values %$disk);
283     }
284     return @rv;
285 }
286
287 sub get_interface {
288     my ($interfacename) = @_;
289     return $interfaces{$interfacename};
290 }
291
292 sub all_interfaces {
293     return values %interfaces;
294 }
295
296 push @EXPORT_OK, qw( read_disklist
297         get_host all_hosts
298         get_disk all_disks
299         get_interface all_interfaces);
300
301 1;