2 * Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
26 Amanda::Disklist - interface to the Amanda disklist
30 use Amanda::Config qw( :init :getconf );
33 # .. call config_init()
34 my $cfgerr_level = Amanda::Disklist::read_disklist(
36 disk_class => "MyScript::Disk",
38 die("Config errors") if ($cfgerr_level >= $CFGERR_WARNINGS);
39 my $dle = Amanda::Disklist::get_disk($ARGV[1], $ARGV[2]);
40 die "No such DLE" unless defined($dle);
42 print "Diskname for this DLE: ", $dle->{name}, "\n";
43 print "Auth for this DLE's host: ", $dle->{host}->{auth}, "\n";
44 print "'record':", dumptype_getconf($dle->{config}, $DUMPTYPE_RECORD), "\n";
48 The Amanda disklist is a part of its configuration, so this module is
49 similar in function to L<Amanda::Config>. In particular,
50 C<read_disklist> loads the disklist into process-global variables, and
51 returns an error status similar to that of L<Amanda::Config>. Those
52 global variables are then used by the acces functions described below.
54 Amanda parses all DLE's as a simple tuple (host, diskname, device,
55 dumptype, interface, spindle), linked to a dumptype. DLE's which
56 specify additional dumptype parameters within the C<disklist> file
57 result in the creation of a "hidden" dumptype with those parameters.
58 Consequently, most configuration data about a particular disk is
59 available in an C<Amanda::Config::dumptype_t> object, and that data is
60 not reproduced by this package.
62 This package differs from the underlying C code in that it separates
63 I<disk> configuration from I<host> configuration. Furthermore, the
64 package does not provide storage for runtime parameters you might want
65 to associate with hosts or disks. However, the objects this packages
66 creates are simple hashrefs that can be blessed with arbitrary class
67 names, so you can add whatever data and behaviors you like to these
72 After calling C<Amanda::Config::config_init()>, call C<read_disklist>.
73 The following parameters are available:
79 Filename from which to read the disklist; defaults to the C<diskfile>
80 configuration parameter.
84 Class with which to bless disk objects; defaults to
85 C<Amanda::Disklist::Disk>.
89 Class with which to bless host objects; defaults to
90 C<Amanda::Disklist::Host>.
94 Class with which to bless interface objects; defaults to
95 C<Amanda::Disklist::Interface>.
99 C<read_disklist> returns a config error level just like
100 C<config_init>. Once the disklist is loaded, call one of the following
101 functions to access the disklist.
103 get_host($host) get the corresponding host object
104 all_hosts() get a list of all host objects
105 get_disk($host, $disk) get a specific disk object
106 all_disks() get a list of all disk objects
107 get_interface($name) get a specific interface object
108 all_interfaces() get a list of all interface objects
112 =head2 Amanda::Disklist::Disk
114 A disk object has the following keys:
120 Host object for this DLE
128 The device, if one was specified separately from the disk name
132 The spindle specified in the disklist
136 An C<Amanda::Config::dumptype_t> object giving the configuration for
137 the disk; use C<dumptype_getconf> and other functions from
138 L<Amanda::Config> to examine it.
142 =head2 Amanda::Disklist::Host
144 Note that, because host configuration parameters are specified in
145 dumptypes, there is no C<config> key for a host object. Instead, the
146 relevant parameters are available as attributes of the object.
152 hostname of this host
156 =item client_username
164 configuration parameters
168 an array containing the names of all of the disks on this host.
172 As a convenience, the C<Amanda::Disklist::Host> class also provides
173 methods C<get_disk($disk)>, to get a disk object on the host, and
174 C<all_disks()>, to get a list of all disk objects on this host.
176 =head2 Amanda::Disklist::Interface
178 Interface objects have only one key, C<config>, containing a
179 C<Amanda::Config::interface_t> object; use C<interface_getconf> and
180 other functions from L<Amanda::Config> to examine it.