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