Cisco-UCS

 view release on metacpan or  search on metacpan

lib/Cisco/UCS/Common/SwitchCard.pm  view on Meta::CPAN

package Cisco::UCS::Common::SwitchCard;

use warnings;
use strict;

use Cisco::UCS::Common::EthernetPort;
use Scalar::Util qw(weaken);
use Carp qw(croak);

our $VERSION = '0.51';

our @ATTRIBUTES = qw(dn id model operability power presence revision serial 
state thermal vendor voltage);

our %ATTRIBUTES	= (
	description	=> 'descr',
	num_ports	=> 'numPorts',
	performance	=> 'perf',
	slot		=> 'id'
);


sub new {
        my ( $class, %args ) = @_;

        my $self = {}; 
        bless $self, $class;

        defined $args{dn}
		? $self->{dn} = $args{dn}
		: croak 'dn not defined';

        defined $args{ucs}
		? weaken($self->{ucs} = $args{ucs})
		: croak 'ucs not defined';

        my %attr = %{ $self->{ucs}->resolve_dn(
				dn => $self->{dn}
			)->{outConfig}->{equipmentSwitchCard} };
    
        while ( my ( $k, $v ) = each %attr ) { $self->{$k} = $v }
    
        return $self;
}

sub eth_port {
	my ( $self,$id ) = @_;

	return ( defined $self->{eth_port}->{$id}
			? $self->{eth_port}->{$id}
			: $self->get_eth_port($id) 
	)
}

sub get_eth_port {
	my ( $self, $id ) = @_;

	return ( $id 
		? $self->get_eth_ports($id) 
		: undef 
	)
}

sub get_eth_ports {
        my ( $self, $id ) = @_;

        return $self->{ucs}->_get_child_objects(
			id	=> $id,
			type	=> 'etherPIo',
			class	=> 'Cisco::UCS::Common::EthernetPort',
			attr	=> 'eth_port',
			self	=> $self,
			uid	=> 'portId',
			class_filter => { 
				classId		=> 'etherPIo',
				slotId		=> $self->{id},
				switchId	=> $self->{interconnect_id} 
			}
	)
}

{
        no strict 'refs';

        while ( my ( $pseudo, $attribute ) = each %ATTRIBUTES ) { 
                *{ __PACKAGE__ . '::' . $pseudo } = sub {
                        my $self = shift;
                        return $self->{$attribute}
                }   
        }   

        foreach my $attribute ( @ATTRIBUTES ) {
                *{ __PACKAGE__ . '::' . $attribute } = sub {
                        my $self = shift;



( run in 3.053 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )