| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package BoxBackup::Config::DiskSets; | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Config::Scoped; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | BoxBackup::Config::DiskSets - Access to Box Backup diskset config files | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use BoxBackup::Config::DiskSets; | ||||||||||||||||||||||||||||
| 15 | $diskSets = BoxBackup::Config::DiskSets->new(); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | or | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | use BoxBackup::Config::DiskSets; | ||||||||||||||||||||||||||||
| 20 | $file = "/etc/bbox/raidfile.conf"; | ||||||||||||||||||||||||||||
| 21 | $diskSets = BoxBackup::Config::DiskSets->new($file); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | @diskNames = $diskSets->getListofDisks(); | ||||||||||||||||||||||||||||
| 24 | foreach $i (@diskNames) | ||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||
| 26 | print "Block size of " . $i . " is " . $disksets->getParamVal($i, "BlockSize) . " bytes.\n"; | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | BoxBackup::Config::DiskSets is a rather simple package that lets the user | ||||||||||||||||||||||||||||
| 32 | have access to the data from the disk set configuration file for | ||||||||||||||||||||||||||||
| 33 | Box Backup. It provides methods to retrieve the data only. No creation | ||||||||||||||||||||||||||||
| 34 | or editing is supported. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 REQUIRES | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | L<Config::Scoped>. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Allows for programmatic access to the information stored in the Box | ||||||||||||||||||||||||||||
| 43 | Backup 'disk set' config file, which holds the information related to | ||||||||||||||||||||||||||||
| 44 | each disk set in the Box Backup installation. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 Methods | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =over | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item * | ||||||||||||||||||||||||||||
| 51 | new(). The new() method parses the disksets file given as the first (and only) | ||||||||||||||||||||||||||||
| 52 | parameter, or, if no parameter is given, parses /etc/box/raidfile.conf, and | ||||||||||||||||||||||||||||
| 53 | creates the object. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item * | ||||||||||||||||||||||||||||
| 56 | getListofDisks(). The getListofDisks() method returns an array of the names of all the disk sets | ||||||||||||||||||||||||||||
| 57 | found in the config file. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item * | ||||||||||||||||||||||||||||
| 60 | getParamVal(). The getParamVal() method returns the value of a paramter for a given disk. | ||||||||||||||||||||||||||||
| 61 | 2 paramters are passed to this method | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item * | ||||||||||||||||||||||||||||
| 66 | disk. This diskset for which the parameter should be retrieved. Normally | ||||||||||||||||||||||||||||
| 67 | 'disc0' or 'disc1', although anything is possible. Use getListofDisks() to | ||||||||||||||||||||||||||||
| 68 | retrieve the names from the file. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =item * | ||||||||||||||||||||||||||||
| 71 | parameter. The parameter you wish to retrieve from the config file, for a | ||||||||||||||||||||||||||||
| 72 | given disk (see above). Currently, the following parameters are available | ||||||||||||||||||||||||||||
| 73 | in the file: | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =over | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item - | ||||||||||||||||||||||||||||
| 78 | SetNumber. This is the disk set number, that's used in the accounts config file. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =item - | ||||||||||||||||||||||||||||
| 81 | BlockSize. The size of the data blocks used on this diskset. Measured in bytes. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =item - | ||||||||||||||||||||||||||||
| 84 | Dir0. The first of the RAID drives. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =item - | ||||||||||||||||||||||||||||
| 87 | Dir1. The second RAID drive. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =item - | ||||||||||||||||||||||||||||
| 90 | Dir2. The third RAID drive. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =back | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =back | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =back | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Per Reedtz Thomsen (L<mailto:pthomsen@reedtz.com>) | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | our $VERSION = v0.03; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | sub new | ||||||||||||||||||||||||||||
| 107 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 109 | 1 | ▶ | my $disksetFile = $args[0] || "/etc/box/raidfile.conf"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args[0] || '/etc/box/raidfile.conf'
MC/DC0%0/1
$args[0] || '/etc/box/raidfile.conf'
$args[0]
Truth table50%1/2
A
A= $args[0]
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | my $parser = Config::Scoped->new( file => $disksetFile ); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | $self = $parser->parse; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | return bless $self; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub getListofDisks | ||||||||||||||||||||||||||||
| 121 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getListofDisks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # Return an array of disk names from $self. | ||||||||||||||||||||||||||||
| 125 | 1 | return keys %$self; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub getParamVal | ||||||||||||||||||||||||||||
| 130 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getParamVal: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 5 | my ($self, $disk, $parm) = @_; | |||||||||||||||||||||||||||
| 132 | 5 | ▶ | return 0 if(!defined($disk) || !defined($parm)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $disk and defined $parm
MC/DC0%0/2
defined $disk and defined $parm
defined $disk
defined $parm
Truth table33%1/3
A and B
A= defined $diskB= defined $parm
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | ▶ | return -1 if(!defined($self->{$disk}{$parm})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 5 | return $self->{$disk}{$parm}; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||