| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package AIX::ODM; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | $^W++; | 
| 4 | 1 |  |  | 1 |  | 5069 | use strict; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 91 |  | 
| 5 | 1 |  |  | 1 |  | 7 | use vars qw(@ISA @EXPORT $VERSION); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 3170 |  | 
| 6 |  |  |  |  |  |  | require Exporter; | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | @ISA = qw(Exporter); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # %EXPORT_TAGS = ( 'all' => [ qw(   ) ] ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | @EXPORT = qw( odm_dump ); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | $VERSION = "1.0.2"; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | #====================================================================== | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | $^O =~ /aix/i || die "This module only runs on AIX systems.\n"; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub odm_classes { | 
| 23 | 0 | 0 |  | 0 |  |  | my ${corp} = ${_[0]}?${_[0]}:'C'; | 
| 24 | 0 |  |  |  |  |  | my @classes; | 
| 25 |  |  |  |  |  |  | my @devlist; | 
| 26 | 0 |  |  |  |  |  | my $class; | 
| 27 | 0 |  |  |  |  |  | my $devname; | 
| 28 | 0 |  |  |  |  |  | my %dev; | 
| 29 |  |  |  |  |  |  | # Retrieve the list of classes from the ODM | 
| 30 | 0 |  |  |  |  |  | @classes = `lsdev -${corp} -r class`; | 
| 31 | 0 |  |  |  |  |  | foreach ${class} (@classes) { | 
| 32 | 0 |  |  |  |  |  | chomp(${class}); | 
| 33 |  |  |  |  |  |  | # Retrieve the list of devices associated with each class from the ODM | 
| 34 | 0 |  |  |  |  |  | @devlist = `lsdev -Cc ${class} -F name`; | 
| 35 | 0 |  |  |  |  |  | foreach ${devname} (@devlist) { | 
| 36 | 0 |  |  |  |  |  | chomp(${devname}); | 
| 37 | 0 |  |  |  |  |  | ${dev{${devname}}} = ${class}; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 0 |  |  |  |  |  | return %dev; | 
| 41 |  |  |  |  |  |  | }; | 
| 42 |  |  |  |  |  |  | ################################################################ | 
| 43 |  |  |  |  |  |  | sub odm_class { | 
| 44 | 0 | 0 |  | 0 |  |  | my ${corp} = ${_[0]}?${_[0]}:'C'; | 
| 45 | 0 | 0 |  |  |  |  | return -1 if ( ${corp} ne 'C' ); | 
| 46 | 0 | 0 |  |  |  |  | return -1 if (!${_[1]}); | 
| 47 |  |  |  |  |  |  | # Retrieve the class of a device from the ODM | 
| 48 | 0 |  |  |  |  |  | my ${devclass} = `lsdev -${corp} -r class -l ${_[1]}`; | 
| 49 | 0 |  |  |  |  |  | chomp(${devclass}); | 
| 50 | 0 |  |  |  |  |  | return ${devclass}; | 
| 51 |  |  |  |  |  |  | }; | 
| 52 |  |  |  |  |  |  | ################################################################ | 
| 53 |  |  |  |  |  |  | sub odm_subclass { | 
| 54 | 0 | 0 |  | 0 |  |  | my ${corp} = ${_[0]}?${_[0]}:'C'; | 
| 55 | 0 | 0 |  |  |  |  | return -1 if ( ${corp} ne 'C' ); | 
| 56 | 0 | 0 |  |  |  |  | return -1 if (!${_[1]}); | 
| 57 |  |  |  |  |  |  | # Retrieve the subclass of a device from the ODM | 
| 58 | 0 |  |  |  |  |  | my ${devsub} = `lsdev -${corp} -r subclass -l ${_[1]}`; | 
| 59 | 0 |  |  |  |  |  | chomp(${devsub}); | 
| 60 | 0 |  |  |  |  |  | return ${devsub}; | 
| 61 |  |  |  |  |  |  | }; | 
| 62 |  |  |  |  |  |  | ################################################################ | 
| 63 |  |  |  |  |  |  | sub odm_attributes { | 
| 64 | 0 |  |  | 0 |  |  | my @{line}; | 
| 65 |  |  |  |  |  |  | my ${ndx}; | 
| 66 | 0 |  |  |  |  |  | my ${aname}; | 
| 67 | 0 |  |  |  |  |  | my %attrib; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # Retrieve the attributes associated with the device from the ODM | 
| 70 |  |  |  |  |  |  | # Two lines are returned, the attribute names are returned on the | 
| 71 |  |  |  |  |  |  | # first line, the attribute values returned on the second. | 
| 72 | 0 |  |  |  |  |  | my @lines = `lsattr -EOl ${_[0]}`; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 0 |  |  |  |  |  | chomp(${lines[0]}); | 
| 75 | 0 |  |  |  |  |  | ${lines[0]} =~ s/^#//g; | 
| 76 | 0 |  |  |  |  |  | my (@attr_name) = split(/:/,${lines[0]}); | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  |  | chomp(${lines[1]}); | 
| 79 | 0 |  |  |  |  |  | ${lines[1]} =~ s/^#//g; | 
| 80 | 0 |  |  |  |  |  | my (@attr_valu) = split(/:/,${lines[1]}); | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 0 |  |  |  |  |  | ${ndx} = 0; | 
| 83 | 0 |  |  |  |  |  | foreach ${aname} (@attr_name) { | 
| 84 | 0 |  |  |  |  |  | ${attrib{${aname}}} = ${attr_valu[${ndx}]}; | 
| 85 | 0 |  |  |  |  |  | ${ndx} = ${ndx} + 1; | 
| 86 |  |  |  |  |  |  | } | 
| 87 | 0 |  |  |  |  |  | return %{attrib}; | 
| 88 |  |  |  |  |  |  | }; | 
| 89 |  |  |  |  |  |  | ################################################################ | 
| 90 |  |  |  |  |  |  | sub odm_dump { | 
| 91 |  |  |  |  |  |  | # Create a hash of devices by their associated class | 
| 92 | 0 | 0 |  | 0 |  |  | my ${corp} = ${_[0]}?${_[0]}:'C'; | 
| 93 | 0 |  |  |  |  |  | my %devlist = &odm_classes(${corp}); | 
| 94 | 0 |  |  |  |  |  | my %attrout; | 
| 95 |  |  |  |  |  |  | my %devices; | 
| 96 | 0 |  |  |  |  |  | my $ndx; | 
| 97 | 0 |  |  |  |  |  | my $subndx; | 
| 98 | 0 |  |  |  |  |  | foreach $ndx (keys %devlist) { | 
| 99 |  |  |  |  |  |  | # create a hash of attributes associated with each device | 
| 100 | 0 |  |  |  |  |  | %{attrout} = &odm_attributes(${ndx}); | 
| 101 |  |  |  |  |  |  | # Add a hash value for 'class' and 'devname' | 
| 102 | 0 |  |  |  |  |  | ${devices{${ndx}}{'class'}} = ${devlist{${ndx}}}; | 
| 103 | 0 |  |  |  |  |  | ${devices{${ndx}}{'subclass'}} = odm_subclass(${corp},${ndx}); | 
| 104 | 0 |  |  |  |  |  | chomp(${devices{${ndx}}{'subclass'}}); | 
| 105 | 0 |  |  |  |  |  | ${devices{${ndx}}{'devname'}} = $ndx; | 
| 106 | 0 |  |  |  |  |  | foreach ${subndx} (keys %attrout) { | 
| 107 | 0 |  |  |  |  |  | ${devices{${ndx}}{${subndx}}} = ${attrout{${subndx}}}; | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  | } | 
| 110 | 0 |  |  |  |  |  | return %devices; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | 1; | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | __END__ |