Cisco-UCS
view release on metacpan or search on metacpan
lib/Cisco/UCS.pm view on Meta::CPAN
}
sub blade {
my ( $self, $id ) = @_;
return (
defined $self->{blade}->{$id}
? $self->{blade}->{$id}
: $self->get_blade($id)
)
}
sub get_blade {
my ( $self, $id ) = @_;
return $self->get_blades( $id )
}
sub get_blades {
my ( $self, $id, %args ) = @_;
return $self->_get_child_objects(
id => $id,
type => 'computeBlade',
class => 'Cisco::UCS::Blade',
attr => 'blade',
uid => 'serverId',
class_filter => {
classId => 'computeBlade'
}
);
}
sub chassis {
my ( $self, $id ) = @_;
return (
defined $self->{chassis}->{$id}
? $self->{chassis}->{$id}
: $self->get_chassis($id)
)
}
sub get_chassis {
my ( $self, $id ) = @_;
return $self->get_chassiss( $id )
}
sub get_chassiss {
my ( $self, $id ) = @_;
return $self->_get_child_objects(
id => $id,
type => 'equipmentChassis',
class => 'Cisco::UCS::Chassis',
attr => 'chassis'
);
}
sub full_state_backup {
my ( $self, %args ) = @_;
$args{backup_type} = 'full-state';
return ( $self->_backup( %args ) );
}
sub all_config_backup {
my ( $self, %args ) = @_;
$args{backup_type} = 'config-all';
return ( $self->_backup( %args ) );
}
sub system_config_backup {
my ( $self, %args ) = @_;
$args{backup_type} = 'config-system';
return ( $self->_backup( %args ) );
}
sub logical_config_backup {
my ( $self, %args ) = @_;
$args{backup_type} = 'config-logical';
return ( $self->_backup( %args ) );
}
sub _backup {
my ( $self, %args ) = @_;
unless( defined $args{backup_type} and
defined $args{backup_proto} and
defined $args{backup_host} and
defined $args{backup_target} and
defined $args{backup_passwd} and
defined $args{backup_username} )
{
$self->{error} = 'Bad argument list';
return
}
$args{admin_state} = (
defined $args{admin_state}
? $args{admin_state}
: 'enabled'
);
$args{preserve_pooled_values} = (
defined $args{preserve_pooled_values}
? $args{preserve_pooled_values}
: 'yes'
);
unless ( $args{backup_type} =~ /(config-all|full-state|config-system|config-logical)/i ) {
$self->{error} = "Bad backup type ($args{backup_type})";
return
}
unless ( $args{backup_proto} =~ /^((t|s)?ftp)|(scp)$/i ) {
$self->{error} = "Bad backup proto' ($args{backup_proto})";
return
}
my $address = $self->get_cluster_status->{address};
my $data = <<"XML";
<configConfMos cookie="$self->{cookie}" inHierarchical="false">
<inConfigs>
<pair key="sys">
<topSystem address="$address" dn="sys" name="$self->{cluster}">
<mgmtBackup adminState="$args{admin_state}" descr="" preservePooledValues="$args{preserve_pooled_values}"
proto="$args{backup_proto}" pwd="$args{backup_passwd}" remoteFile="$args{backup_target}"
rn="backup-$args{backup_host}" type="$args{backup_type}"
user="$args{backup_username}" policyOwner="local">
</mgmtBackup>
</topSystem>
</pair>
</inConfigs>
</configConfMos>
XML
my $xml = $self->_ucsm_request( $data ) or return;
if ( defined $xml->{'errorCode'} ) {
my $self->{error} = ( defined $xml->{'errorDescr'}
? $xml->{'errorDescr'}
: "Unspecified error"
);
return
}
return 1;
}
1;
__END__
=pod
=head1 NAME
Cisco::UCS - A Perl interface to the Cisco UCS XML API
=head1 SYNOPSIS
use Cisco::UCS;
my $ucs = Cisco::UCS->new (
cluster => $cluster,
username => $username,
passwd => $password
);
$ucs->login();
@errors = $ucs->get_errors(severity=>"critical",ack="no");
foreach my $error_id (@errors) {
my %this_error = $ucs->get_error_id($error_id);
print "Error ID: $error_id. Severity: $this_error{severity}."
. " Description: $this_error{descr}\n";
}
print "Interconnect A serial : "
. $ucs->interconnect(A)->serial
. "\n";
# prints "Interconnect A serial : BFG9000"
foreach my $chassis ($ucs->chassis) {
print "Chassis " . $chassis->id
. " serial : " . $chassis->serial . "\n"
}
lib/Cisco/UCS.pm view on Meta::CPAN
=head3 get_blades ()
my @blades = $ucs->get_blades();
foreach my $blade ( @blades ) {
print "Model: $blade->{model}\n";
}
Returns an array of B<Cisco::UCS::Blade> objects with each object representing
a blade within the UCS cluster.
=head3 chassis ( $ID )
my $chassis = $ucs->chassis(1);
print "Chassis 1 serial : " . $chassis->serial . "\n";
# or
print "Chassis 1 serial : " . $ucs->chassis(1)->serial . "\n";
foreach my $psu ( $ucs->chassis(1)->get_psus ) {
print $psu->id . " thermal : " . $psu->thermal . "\n"
}
Returns a Cisco::UCS::Chassis object representing the chassis identified by by
the specified value of ID.
Note that this is a caching method and the default behaviour of this method is
to return a cached copy of a previously retrieved Cisco::UCS::Chassis object if
one is available. If a non-cached object is required, then please consider
using the equivalent B<get_chassis> method below.
Please see the B<Caching Methods> section in B<NOTES> for further information.
=head3 get_chassis ( $ID )
my $chassis = $ucs->get_chassis(1);
print "Chassis 1 label : " . $chassis->label . "\n";
# or
print "Chassis 1 label : " . $ucs->get_chassis(1)->label . "\n";
Returns a Cisco::UCS::Chassis object representing the chassis identified by the
specified value of ID.
Note that this method is non-caching and always queries the UCSM for
information. Consequently may be more expensive than the equivalent caching
B<chassis> method described above.
=head3 get_chassiss
my @chassis = $ucs->get_chassiss();
foreach my $chassis (@chassis) {
print "Chassis $chassis->{id} serial number: $chassis->{serial}\n";
}
Returns an array of Cisco::UCS::Chassis objects representing all chassis
present within the cluster.
Note that this method is named get_chassiss (spelt with two sets of double-s's)
as there exists no English language collective plural for the word chassis.
=head3 full_state_backup
This method generates a new "full state" type backup for the target UCS
cluster. Internally, this method is implemented as a wrapper method around the
private backup method. Required parameters for this method:
=over 3
=item backup_proto
The protocol to use for transferring the backup from the target UCS cluster to
the backup host. Must be one of: ftp, tftp, scp or sftp.
=item backup_host
The host to which the backup will be transferred.
=item backup_target
The fully qualified name of the file to which the backup is to be saved on the
backup host. This should include the full directory path and the target
filename.
=item backup_username
The username to be used for creation of the backup file on the backup host.
This username should have write/modify file system access to the backup target
location on the backup host using the protocol specified in the backup-proto
attribute.
=item backup_passwd
The plaintext password of the user specified for the backup_username attribute.
=back
=head3 all_config_backup
This method generates a new "all configuration" backup for the target UCS
cluster. Internally, this method is implemented as a wrapper method around the
private backup method. For the required parameters for this method, please
refer to the documentation of the B<full_state_backup> method.
=head3 system_config_backup
This method generates a new "system configuration" backup for the target UCS
cluster. Internally, this method is implemented as a wrapper method around the
private backup method. For the required parameters for this method, please
refer to the documentation of the B<full_state_backup> method.
=head3 logical_config_backup
This method generates a new "logical configuration" backup for the target UCS
cluster. Internally, this method is implemented as a wrapper method around the
private backup method. For the required parameters for this method, please
refer to the documentation of the B<full_state_backup> method.
=head1 NOTES
=head2 Caching Methods
Several methods in the module return cached objects that have been previously
retrieved by querying UCSM, this is done to improve the performance of methods
where a cached copy is satisfactory for the intended purpose. The trade off
for the speed and lower resource requirement is that the cached copy is not
guaranteed to be an up-to-date representation of the current state of the
object.
As a matter of convention, all caching methods are named after the singular
object (i.e. interconnect(), chassis()) whilst non-caching methods are named
I<get_<object>>. Non-caching methods will always query UCSM for the object,
as will requests for cached objects not present in cache.
=cut
=over 3
=item *
The documentation could be cleaner and more thorough. The module was written
some time ago with only minor amounts of time and effort invested since.
There's still a vast opportunity for improvement.
=item *
Better error detection and handling. Liberal use of Carp::croak should ensure
that we get some minimal diagnostics and die nicely, and if used according to
instructions, things should generally work. When they don't however, it would
be nice to know why.
=item *
Detection of request and return type. Most of the methods are fairly
explanatory in what they return, however it would be nice to make better use of
wantarray to detect what the user wants and handle it accordingly.
=item *
Clean up of the UCS package to remove unused methods and improve the ones that
we keep. I'm still split on leaving some of the methods common to most object
type (fans, psus) in the main package.
=back
=head1 AUTHOR
Luke Poskitt, C<< <ltp at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-cisco-ucs at rt.cpan.org>,
or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cisco-UCS>. I will be
notified, and then you'll automatically be notified of progress on your bug as
I make changes.
( run in 2.069 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )