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