1 # This file was automatically generated by SWIG (http://www.swig.org).
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
7 package Amanda::Disklist;
9 use base qw(DynaLoader);
10 require Amanda::Config;
11 package Amanda::Disklistc;
12 bootstrap Amanda::Disklist;
13 package Amanda::Disklist;
16 # ---------- BASE METHODS -------------
18 package Amanda::Disklist;
21 my ($classname,$obj) = @_;
22 return bless $obj, $classname;
32 my ($self,$field) = @_;
33 my $member_func = "swig_${field}_get";
34 $self->$member_func();
38 my ($self,$field,$newval) = @_;
39 my $member_func = "swig_${field}_set";
40 $self->$member_func($newval);
49 # ------- FUNCTION WRAPPERS --------
51 package Amanda::Disklist;
53 *read_disklist_internal = *Amanda::Disklistc::read_disklist_internal;
55 # ------- VARIABLE STUBS --------
57 package Amanda::Disklist;
66 Amanda::Disklist - interface to the Amanda disklist
70 use Amanda::Config qw( :init :getconf );
73 # .. call config_init()
74 my $cfgerr_level = Amanda::Disklist::read_disklist(
76 disk_class => "MyScript::Disk",
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);
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";
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.
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.
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
112 After calling C<Amanda::Config::config_init()>, call C<read_disklist>.
113 The following parameters are available:
119 Filename from which to read the disklist; defaults to the C<diskfile>
120 configuration parameter.
124 Class with which to bless disk objects; defaults to
125 C<Amanda::Disklist::Disk>.
129 Class with which to bless host objects; defaults to
130 C<Amanda::Disklist::Host>.
132 =item interface_class
134 Class with which to bless interface objects; defaults to
135 C<Amanda::Disklist::Interface>.
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.
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
152 =head2 Amanda::Disklist::Disk
154 A disk object has the following keys:
160 Host object for this DLE
168 The device, if one was specified separately from the disk name
172 The spindle specified in the disklist
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.
182 =head2 Amanda::Disklist::Host
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.
192 hostname of this host
196 =item client_username
204 configuration parameters
208 an array containing the names of all of the disks on this host.
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.
216 =head2 Amanda::Disklist::Interface
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.
226 use Amanda::Debug qw( :logging );
227 use Amanda::Config qw( :getconf config_dir_relative );
230 package Amanda::Disklist::Disk;
234 package Amanda::Disklist::Host;
237 my ($self, $disk) = @_;
238 return $Amanda::Disklist::disks{$self->{'hostname'}}{$disk};
243 return values %{$Amanda::Disklist::disks{$self->{'hostname'}}};
246 package Amanda::Disklist::Interface;
250 package Amanda::Disklist;
252 our (%disks, %hosts, %interfaces);
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"),
267 return $hosts{$hostname};
271 return values %hosts;
275 my ($hostname, $diskname) = @_;
276 return $disks{$hostname}->{$diskname};
281 foreach my $disk (values %disks) {
282 push @rv, (values %$disk);
288 my ($interfacename) = @_;
289 return $interfaces{$interfacename};
293 return values %interfaces;
296 push @EXPORT_OK, qw( read_disklist
299 get_interface all_interfaces);