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;
54 *clean_dle_str_for_client = *Amanda::Disklistc::clean_dle_str_for_client;
56 # ------- VARIABLE STUBS --------
58 package Amanda::Disklist;
67 Amanda::Disklist - interface to the Amanda disklist
71 use Amanda::Config qw( :init :getconf );
74 # .. call config_init()
75 my $cfgerr_level = Amanda::Disklist::read_disklist(
77 disk_class => "MyScript::Disk",
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);
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";
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.
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.
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
113 After calling C<Amanda::Config::config_init()>, call C<read_disklist>.
114 The following parameters are available:
120 Filename from which to read the disklist; defaults to the C<diskfile>
121 configuration parameter.
125 Class with which to bless disk objects; defaults to
126 C<Amanda::Disklist::Disk>.
130 Class with which to bless host objects; defaults to
131 C<Amanda::Disklist::Host>.
133 =item interface_class
135 Class with which to bless interface objects; defaults to
136 C<Amanda::Disklist::Interface>.
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.
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
153 =head2 Amanda::Disklist::Disk
155 A disk object has the following keys:
161 Host object for this DLE
169 The device, if one was specified separately from the disk name
173 The spindle specified in the disklist
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.
183 =head2 Amanda::Disklist::Host
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.
193 hostname of this host
197 =item client_username
205 configuration parameters
209 an array containing the names of all of the disks on this host.
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.
217 =head2 Amanda::Disklist::Interface
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.
227 use Amanda::Debug qw( :logging );
228 use Amanda::Config qw( :getconf config_dir_relative );
231 package Amanda::Disklist::Disk;
235 package Amanda::Disklist::Host;
238 my ($self, $disk) = @_;
239 return $Amanda::Disklist::disks{$self->{'hostname'}}{$disk};
244 return values %{$Amanda::Disklist::disks{$self->{'hostname'}}};
247 package Amanda::Disklist::Interface;
251 package Amanda::Disklist;
253 our (%disks, %hosts, %interfaces);
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"),
268 return $hosts{$hostname};
272 return values %hosts;
276 my ($hostname, $diskname) = @_;
277 return $disks{$hostname}->{$diskname};
282 foreach my $disk (values %disks) {
283 push @rv, (values %$disk);
289 my ($interfacename) = @_;
290 return $interfaces{$interfacename};
294 return values %interfaces;
297 push @EXPORT_OK, qw( read_disklist
300 get_interface all_interfaces);