Cisco-UCS

 view release on metacpan or  search on metacpan

lib/Cisco/UCS/MgmtEntity.pm  view on Meta::CPAN

package Cisco::UCS::MgmtEntity;

use strict;
use warnings;

use Carp		qw(croak);
use Scalar::Util	qw(weaken);

our $VERSION = '0.51';

our @ATTRIBUTES	= qw(chassis1 chassis2 chassis3 dn id leadership state);

our %ATTRIBUTES = (
	chassis1_device_io_state	=> 'chassisDeviceIoState1',
	chassis2_device_io_state	=> 'chassisDeviceIoState2',
	chassis3_device_io_state	=> 'chassisDeviceIoState3',
	ha_failure_reason		=> 'haFailureReason',
	ha_readiness			=> 'haReadiness',
	ha_ready			=> 'haReady',
	mgmt_services_state		=> 'mgmtServicesState',
	umbilical_state			=> 'umbilicalState',
	version_mismatch		=> 'versionMismatch'
);

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 'dn not defined';

	my %attr = %{ $self->{ucs}->resolve_dn(
				dn => $self->{dn}
			)->{outConfig}->{mgmtEntity} };

	while ( my ($k, $v) = each %attr ) { $self->{$k} = $v }

	return $self
}

{
        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;
                        return $self->{$attribute}
                }   
        }   
}

1;

__END__

=head1 NAME

Cisco::UCS::MgmtEntity - Class for operations with a Cisco UCSM Management 
Entity

=head1 SYNOPSIS
	
	map {
		print "Management entity " 
			. $_->id . " HA state is " 
			. $_->ha_readiness . "\n"
	} $ucs->get_mgmt_entities;

	# prints...
	# Management entity A HA state is ready
	# Management entity B HA state is ready

	print $ucs->mgmt_entity('B')->umbilical_state;

=head1 DECRIPTION

Cisco::UCS::MgmtEntity is a class providing operations with a Cisco UCSM 
Management Entity.

Note that you are not supposed to call the constructor yourself, rather a 
Cisco::UCS::MgmtEntity object is created automatically by method calls via 
methods in Cisco::UCS.



( run in 0.910 second using v1.01-cache-2.11-cpan-d8267643d1d )