| 1 | package EMC::WideSky::symmaskdb; | ||
| 2 | |||
| 3 | our @ISA = qw(Exporter); | ||
| 4 | our @EXPORT = qw(parse_symmaskdb new); # Symbols to be exported by default | ||
| 5 | our @EXPORT_OK = qw(); # Symbols to be exported on request | ||
| 6 | our $VERSION = 0.21; | ||
| 7 | |||
| 8 | 0 | ▶ | use XML::Parser; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use EMC::WideSky::Util; | ||
| 10 | |||
| 11 | sub new { | ||
| 12 | my $class=shift; | ||
| 13 | |||
| 14 | my $self={}; | ||
| 15 | bless $self,$class; | ||
| 16 | return $self; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub parse_symmaskdb (@) { | ||
| 20 | my $db=shift; | ||
| 21 | my %r=@_; | ||
| 22 | my $p = new XML::Parser(Handlers => {Start => \&handle_start, | ||
| 23 | End => \&handle_end, | ||
| 24 | Char => \&handle_char}); | ||
| 25 | $fa_restrict=$r{fa}; $host_restrict=$r{host}; $hba_restrict=$r{hba}; $dev_restrict=$r{dev}; $wwn_restrict=$r{wwn}; | ||
| 26 | if ($r{input}) { | ||
| 27 | open(DB,$r{input}) || die "Can't open symmaskdb\n"; | ||
| 28 | } else { | ||
| 29 | open(DB,'symmaskdb list database -out xml |') || die "Can't open symmaskdb\n"; | ||
| 30 | } | ||
| 31 | $p->parse(*DB); | ||
| 32 | sub handle_start { | ||
| 33 | my $p=shift @_; | ||
| 34 | my $el=shift @_; | ||
| 35 | my %att=@_; | ||
| 36 | |||
| 37 | if ($el eq 'Devmask_Database_Record') { | ||
| 38 | $att{director}=~ s/^FA-//; | ||
| 39 | $dir="$att{director}:$att{port}"; | ||
| 40 | $fa_read=1 if ($dir=~ /$fa_restrict/i || ! $fa_restrict) | ||
| 41 | } | ||
| 42 | |||
| 43 | if ($el eq 'Db_Record') { | ||
| 44 | if ($att{awwn_node_name}) { $host=$att{awwn_node_name} } else { $host=$att{originator_port_wwn} } | ||
| 45 | $host_read=1 if (($host=~ /$host_restrict/i || ! $host_restrict) && ($att{originator_port_wwn}=~ /$wwn_restrict/i || ! $wwn_restrict)); | ||
| 46 | if ($att{awwn_port_name}) { $hba="$att{awwn_port_name}" } else { $hba="$att{originator_port_wwn}" } | ||
| 47 | $hba_read=1 if ($hba=~ /$hba_restrict/i || ! $hba_restrict); | ||
| 48 | } | ||
| 49 | |||
| 50 | if ($el eq 'Devices') { | ||
| 51 | if ($att{start_dev} && $att{end_dev}) { | ||
| 52 | if ($att{start_dev} eq $att{end_dev}) { | ||
| 53 | $dev_read=1 if ($att{start_dev}=~ /$dev_restrict/i || ! $dev_restrict ); | ||
| 54 | $db->{$att{start_dev}}->{$dir}->{$host}->{$hba}=1 if ($fa_read && $host_read && $hba_read && $dev_read); | ||
| 55 | } else { | ||
| 56 | $att{start_dev}="0" x (4-length($att{start_dev})).$att{start_dev}; | ||
| 57 | $att{end_dev}="0" x (4-length($att{end_dev})).$att{end_dev}; | ||
| 58 | |||
| 59 | for ($i=&hex2dec($att{start_dev});$i<=&hex2dec($att{end_dev});$i++) { | ||
| 60 | my $dev=&dec2hex($i); | ||
| 61 | $dev_read=1 if ($dev=~ /$dev_restrict/i || ! $dev_restrict); | ||
| 62 | $db->{$dev}->{$dir}->{$host}->{$hba}=1 if ($fa_read && $host_read && $hba_read && $dev_read); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | $dev_read=0; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | sub handle_end { | ||
| 71 | my $p=shift @_; | ||
| 72 | my $el=shift @_; | ||
| 73 | |||
| 74 | if ($el eq 'Devmask_Database_Record') { $fa_read=0; } | ||
| 75 | if ($el eq 'Db_Record') { $host_read=0; $hba_read=0; } | ||
| 76 | } | ||
| 77 | |||
| 78 | sub handle_char { | ||
| 79 | my $p=shift @_; | ||
| 80 | my $str=shift @_; | ||
| 81 | |||
| 82 | print ' ' x $i."CHAR: $str\n" unless ($str=~ /^\s+$/); | ||
| 83 | } | ||
| 84 | |||
| 85 | } | ||
| 86 | |||
| 87 | __END__ | ||