UCS.pm

filter: Statementstmt 18.9% 51 / 269 Branchbran 0.7% 1 / 136 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 24.5% 14 / 57 Podpod 100% 36 / 36 totaltotal 18.5% 102 / 549 CC 83 SCAR 41.0
CC
83
Cov
12%
_get_child_objects
240.0
_backup
210.0
new
72.0
CRAP 60.1
↑ Summary UCS/Common/Fan.pm »
1 package Cisco::UCS;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Cisco::UCS::Chassis;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Cisco::UCS::Interconnect;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Cisco::UCS::FEX;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Cisco::UCS::Blade;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Cisco::UCS::Fault;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Cisco::UCS::MgmtEntity;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Cisco::UCS::ServiceProfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Carp qw(croak carp cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 our $VERSION = '0.51';
20  
21 2 our @ATTRIBUTES = qw(dn cluster cookie);
22  
23 2 our %ATTRIBUTES = ();
24  
25 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
26 0 my ( $class, %args ) = @_;
27  
28 0 my $self = {};
29 0 bless $self, $class;
30  
31 defined $args{cluster}
32 ? $self->{cluster} = $args{cluster}
33 0 ▶ : croak 'cluster not defined';
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'cluster'} ? : 0 0 0
34  
35 defined $args{username}
36 ? $self->{username} = $args{username}
37 0 ▶ : croak 'username not defined';
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'username'} ? : 0 0 0
38  
39 defined $args{passwd}
40 ? $self->{passwd} = $args{passwd}
41 0 ▶ : croak 'passwd not defined';
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'passwd'} ? : 0 0 0
42  
43 defined $args{verify_hostname}
44 ? $self->{verify_hostname} = $args{verify_hostname}
45 0 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'verify_hostname'} ? : 0 0 0
46  
47 0 ▶ $self->{port} = ( $args{port} or 443 );
Condition0%0/2
$args{'port'} || 443
l!l
00
MC/DC0%0/1
$args{'port'} || 443
$args{'port'}
Truth table0%0/2
A
A= $args{'port'}
Aresult
11
00
48 0 ▶ $self->{proto} = ( $args{proto} or 'https' );
Condition0%0/2
$args{'proto'} || 'https'
l!l
00
MC/DC0%0/1
$args{'proto'} || 'https'
$args{'proto'}
Truth table0%0/2
A
A= $args{'proto'}
Aresult
11
00
49 0 ▶ $self->{dn} = ( $args{dn} or 'sys' );
Condition0%0/2
$args{'dn'} || 'sys'
l!l
00
MC/DC0%0/1
$args{'dn'} || 'sys'
$args{'dn'}
Truth table0%0/2
A
A= $args{'dn'}
Aresult
11
00
50  
51 0 return $self;
52 }
53  
54 {
55 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 2 ▶ while ( my ($pseudo, $attribute) = each %ATTRIBUTES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Cisco::UCS::ATTRIBUTES) 0 2 2
58 0 ▶ *{ __PACKAGE__ . '::' . $pseudo } = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 my $self = shift;
60 0 return $self->{$attribute}
61 }
62 0 }
63  
64 2 foreach my $attribute (@ATTRIBUTES) {
65 6 ▶ *{ __PACKAGE__ . '::' . $attribute } = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
66 0 my $self = shift;
67 0 return $self->{$attribute}
68 }
69 6 }
70 }
71  
72 0 ▶sub login {
Subroutine login: not called CC=4 SCAR=30.0
Pod documented
73 0 my $self = shift;
74  
75 0 undef $self->{error};
76  
77 $self->{ua} = LWP::UserAgent->new(
78 ssl_opts => {
79 verify_hostname => $self->{verify_hostname}
80 }
81 0 );
82  
83 $self->{uri} = $self->{proto}. '://' .$self->{cluster}
84 0 . ':' .$self->{port}. '/nuova';
85  
86 $self->{req} = HTTP::Request->new(
87 POST => $self->{uri}
88 0 );
89  
90 0 $self->{req}->content_type( 'application/x-www-form-urlencoded' );
91  
92 $self->{req}->content( '<aaaLogin inName="'. $self->{username}
93 0 .'" inPassword="'. $self->{passwd} .'"/>' );
94  
95 0 my $res = $self->{ua}->request( $self->{req} );
96  
97 0 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
98 0 $self->{error} = 'Login failure: '.$res->status_line;
99 0 return 0
100 }
101  
102 0 $self->{parser} = XML::Simple->new;
103 0 my $xml = $self->{parser}->XMLin( $res->content );
104  
105 0 ▶ if ( defined $xml->{'errorCode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xml->{"errorCode"}) 0 0 0
106 $self->{error} = 'Login failure: '
107 . ( defined $xml->{'errorDescr'}
108 0 ▶ ? $xml->{'errorDescr'}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'errorDescr'} ? : 0 0 0
109 : 'Unspecified error'
110 );
111 0 return 0
112 }
113  
114 0 $self->{cookie} = $xml->{'outCookie'};
115  
116 0 return 1
117 }
118  
119 0 ▶sub refresh {
Subroutine refresh: not called CC=4 SCAR=30.0
Pod documented
120 0 my $self = shift;
121  
122 0 undef $self->{error};
123 $self->{req}->content( '<aaaRefresh inName="'. $self->{username}
124 .'" inPassword="'. $self->{passwd}
125 0 .'" inCookie="' . $self->{cookie} . '"/>'
126 );
127  
128 0 my $res = $self->{ua}->request( $self->{req} );
129  
130 0 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
131 0 $self->{error} = 'Refresh failed: '. $res->status_line;
132 0 return 0
133 }
134  
135 0 my $xml = $self->{parser}->XMLin( $res->content() );
136  
137 0 ▶ if ( defined $xml->{'errorCode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xml->{"errorCode"}) 0 0 0
138 $self->{error} = 'Refresh failure: '
139 . ( defined $xml->{'errorDescr'}
140 0 ▶ ? $xml->{'errorDescr'}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'errorDescr'} ? : 0 0 0
141 : 'Unspecified error'
142 );
143 0 return 0
144 }
145  
146 0 $self->{cookie} = $xml->{'outCookie'};
147  
148 0 return 1
149 }
150  
151 0 ▶sub logout {
Subroutine logout: not called CC=3 SCAR=24.8
Pod documented
152 0 my $self = shift;
153  
154 0 ▶ return unless $self->{cookie};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cookie"} 0 0 0
155  
156 0 undef $self->{error};
157  
158 return ( $self->_ucsm_request( '<aaaLogout inCookie="'
159 0 ▶ . $self->{cookie} .'" />' ) ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$self->_ucsm_request('<aaaLogout inCookie="' . $self->{'cookie'} . '" />') ? : 0 0 0
160 )
161 }
162  
163 0 ▶sub _ucsm_request {
Subroutine _ucsm_request: not called CC=5 SCAR=34.0
164 0 my ( $self, $content, $class_id ) = @_;
165  
166 0 undef $self->{error};
167 0 $self->{req}->content( $content );
168 0 my $res = $self->{ua}->request( $self->{req} );
169  
170 0 ▶ $self->error( $res->status_line ) unless $res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
171  
172 my $xml = ( $class_id
173 ? $self->{parser}->XMLin(
174 $res->content,
175 KeyAttr => $class_id
176 )
177 : $self->{parser}->XMLin(
178 0 ▶ $res->content,
Branch: 1 branch
BranchTrueFalseTotal
$class_id ? : 0 0 0
179 KeyAttr => [ 'name', 'key', 'id', 'intId' ]
180 )
181 );
182  
183 return ( $xml->{errorCode}
184 0 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
$xml->{'errorCode'} ? : 0 0 0
185 $self->{error} = ( $xml->{'errorDescr'}
186 0 ▶ ? $xml->{'errorDescr'}
Branch: 1 branch
BranchTrueFalseTotal
$xml->{'errorDescr'} ? : 0 0 0
187 : 'Unspecified error'
188 );
189 undef
190 0 }
191 : $xml
192 );
193 }
194  
195 # This private method provides an abstract factory-type constructor for resolved child
196 # objects of the specified dn. To maintain compatibility with existing methods and to
197 # provide a single method for all child objects, there are a few important design
198 # considerations that have been made.
199 #
200 # Importantly we check for a 'class_filter' argument to the method which if present is
201 # used to call the 'resolve_class_filter' method rather than the 'resolve_children' method.
202 # This is necessary due to limitations and difficulties present in resolving child objects
203 # for some objects can lead to incorrect results. For example, resolving the child objects
204 # for a chassis to retrieve the blades in the chassis is difficult, instead we can use a much
205 # more efficient and simpler method of retrieving the blades in a specified chassis by
206 # resolving all objects in the specified class (i.e. computeBlade) and restricting the
207 # results returned using a filter method.
208 #
209 # The implication of doing this is that the call to 'resolve_class_filter' returns an array
210 # which cannot be processed using the same logic as for a hash returned by the 'resolve_children'
211 # method. Therefore we perform extra processing to convert the returned array results to a
212 # hash using a nominated attribute in the object as the hash index for the objects.
213 #
214 # SYNOPSIS
215 # get_child_object ( %ARGS )
216 #
217 # PARAMETERS
218 # id The optional identifier of a specific child object. This identifier is context
219 # dependent and may be either numerical (as in the case of a chassis) or alphanumeric
220 # (as is the case with a fabric interconnect - A or B).
221 #
222 # type The desired child object type to be resolved as according to the UCSM information
223 # management hierarchy name. e.g. etherPIo is the ethernet port child object type for line cards.
224 #
225 # class The class into which the child object will be blessed.
226 #
227 # attr The pseudo-namespace in the Cisco::UCS object in which the retrieved child onjects will be cached.
228 # For example; attr => 'interconnect' will mean that Cisco::UCS::Interconnect objects retrieved in
229 # a $ucs->get_interconnects method call will be stored in $ucs->{interconnects}->{$OBJ}.
230 #
231 # self A reference to a Cisco::UCS object. If not present $self is assumed to be a Cisco::UCS object.
232 #
233 # uid Where results are returned and parsed into an array and the array index is not aligned to an identifying
234 # attribute of the object (i.e. the array index has no relation to a unique identifier for the object) then
235 # the uid may be used to refer to a unique identifying attribute of the object that should be used.
236 # For example, in resolving all blades for a Cisco::UCS object, the uid value of bladeId is used to uniquely
237 # identify all Cisco::UCS::Blade objects as the array index has no relation to a uniquely identifying feature
238 # of the blade and is not guaranteed to be consistent.
239 #
240 # class_filter (%ARGS)
241 # A class filter may be specified to filter the results to a particular subset. This is useful for
242 # operations like retrieving all blades in a particular chassis rather than retrieving all blades and
243 # manually filtering the results.
244 #
245 # Where %ARGS:
246 #
247 # classId The UCSM class which should be used for the UCSM query. For example: classId => etherPio.
248 #
249 # filter Where filter is composed of any number of valid attribute/value pairs. For example: slotId => 1, switchId => $self->{id}.
250 #
251 # eattrs A hash containing key/value pairs that should be added to the retrieved child objects as additional
252 # attributes. This can be useful where child objects need to "know" some infomration about their
253 # parent object. e.g. an interconnect switchcard needs to know which interconnect it is located in (A or B)
254 # as this information is not exposed as an attribute of the switchcard.
255 #
256  
257 0 ▶sub _get_child_objects {
Subroutine _get_child_objects: not called CC=15 SCAR=54.8
258 0 my ( $self,%args ) = @_;
259  
260 my $ucs = ( defined $self->{ucs}
261 ? $self->{ucs}
262 0 ▶ : $self
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'ucs'} ? : 0 0 0
263 );
264  
265 my $ref = ( defined $args{self}
266 ? $args{self}
267 0 ▶ : $self
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'self'} ? : 0 0 0
268 );
269  
270 my $xml = ( defined $args{class_filter}
271 0 ? $ucs->resolve_class_filter( %{ $args{class_filter} } )
272 : $ucs->resolve_children( dn => $ref->{dn} )
273 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'class_filter'} ? : 0 0 0
274  
275 0 ▶ if ( ref( $xml->{outConfigs}->{ $args{type} } ) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $xml->{'outConfigs'}{$args{'type'}} eq 'ARRAY') { } 0 0 0
elsif (ref $xml->{'outConfigs'}{$args{'type'}} eq 'HASH' and exists $xml->{'outConfigs'}{$args{'type'}}{'dn'}) { } 0 0 0
276 0 ▶ $args{uid} ||= 'id';
Condition0%0/2
$args{"uid"} ||= "id"
l!l
00
MC/DC0%0/1
$args{"uid"} ||= "id"
$args{"uid"}
Truth table0%0/2
A
A= $args{"uid"}
Aresult
11
00
277 0 my $res;
278
279 0 foreach my $obj ( @{ $xml->{outConfigs}->{ $args{type} } } ) {
280 0 $res->{ $obj->{ $args{uid} } } = $obj
281 }
282  
283 0 $xml->{outConfigs}->{ $args{type} } = $res
284 }
285 ▶ elsif ( ( ref( $xml->{outConfigs}->{ $args{type} } ) eq 'HASH' )
Condition0%0/3
ref $xml->{"outConfigs"}{$args{"type"}} eq "HASH" and exists $xml->{"outConfigs"}{$args{"type"}}{"dn"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $xml->{"outConfigs"}{$args{"type"}} eq "HASH" and exists $xml->{"outConfigs"}{$args{"type"}}{"dn"}
ref $xml->{"outConfigs"}{$args{"type"}} eq "HASH" exists $xml->{"outConfigs"}{$args{"type"}}{"dn"}
Truth table0%0/3
A and B
A= ref $xml->{"outConfigs"}{$args{"type"}} eq "HASH"B= exists $xml->{"outConfigs"}{$args{"type"}}{"dn"}
ABresult
0X0
100
111
286 and ( exists $xml->{outConfigs}->{ $args{type} }->{dn} ) ) {
287 0 ▶ $args{uid} ||= 'id';
Condition0%0/2
$args{"uid"} ||= "id"
l!l
00
MC/DC0%0/1
$args{"uid"} ||= "id"
$args{"uid"}
Truth table0%0/2
A
A= $args{"uid"}
Aresult
11
00
288 0 my $res;
289 $res->{ $xml->{outConfigs}->{ $args{type} }->{ $args{uid} } }
290 0 = $xml->{outConfigs}->{ $args{type} };
291  
292 0 $xml->{outConfigs}->{ $args{type} } = $res
293 }
294  
295 return ( defined $xml->{outConfigs}->{ $args{type} }
296 0 ▶ ? do { my @res;
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'outConfigs'}{$args{'type'}} ? : 0 0 0
297 0 foreach my $res ( keys %{ $xml->{outConfigs}->{ $args{type} } } ) {
298 my $obj = $args{class}->new(
299 ucs => $ucs,
300 dn => $xml->{outConfigs}->{ $args{type} }->{$res}->{dn},
301 0 id => $res
302 );
303  
304 0 map { $obj->{ $_ } = $args{ eattrs }{ $_ } } keys %{ $args{ eattrs } };
305  
306 0 $ref->{ $args{attr} }->{$res} = $obj;
307 0 push @res, $obj;
308 }
309  
310 0 ▶ return @res unless $args{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"id"} 0 0 0
311  
312 return $ref->{ $args{attr} }->{ $args{id} }
313 0 ▶ if $args{id} and $ref->{ $args{attr} }->{ $args{id} };
Branch: 1 branch
BranchTrueFalseTotal
if $args{"id"} and $$ref{$args{"attr"}}{$args{"id"}} 0 0 0
Condition0%0/3
$args{"id"} and $$ref{$args{"attr"}}{$args{"id"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"id"} and $$ref{$args{"attr"}}{$args{"id"}}
$args{"id"} $$ref{$args{"attr"}}{$args{"id"}}
Truth table0%0/3
A and B
A= $args{"id"}B= $$ref{$args{"attr"}}{$args{"id"}}
ABresult
0X0
100
111
314  
315 return
316 0 }
317 : ()
318 );
319
320 }
321  
322 0 ▶sub get_error_id {
Subroutine get_error_id: not called CC=1 SCAR=6.9
Pod documented
323 0 warn "get_error_id has been deprecated in future releases";
324 0 return get_error( @_ )
325 }
326  
327 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
328 0 my ( $self, $id ) = @_;
329  
330 return (
331 defined $self->{fault}->{$id}
332 0 ▶ ? $self->{fault}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'fault'}{$id} ? : 0 0 0
333 : $self->get_error($id)
334 )
335 }
336  
337 0 ▶sub get_error {
Subroutine get_error: not called CC=1 SCAR=6.9
Pod documented
338 0 my ( $self, $id ) = @_;
339  
340 0 return $self->get_errors( $id )
341 }
342  
343 0 ▶sub get_errors {
Subroutine get_errors: not called CC=1 SCAR=6.9
Pod documented
344 0 my ( $self, $id ) = @_;
345  
346 0 return $self->_get_child_objects(
347 id => $id,
348 type => 'faultInst',
349 class => 'Cisco::UCS::Fault',
350 uid => 'id',
351 attr => 'fault',
352 class_filter => {
353 classId => 'faultInst'
354 }
355 );
356 }
357  
358 0 ▶sub _isInHierarchical {
Subroutine _isInHierarchical: not called CC=4 SCAR=30.0
359 0 my $inHierarchical = lc shift;
360  
361 0 ▶ return 'false' unless ( $inHierarchical =~ /true|false|0|1/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $inHierarchical =~ /true|false|0|1/ 0 0 0
362  
363 0 ▶ return $inHierarchical if ( $inHierarchical =~ /^true|false$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $inHierarchical =~ /^true|false$/ 0 0 0
364  
365 0 ▶ return ( $inHierarchical == 0 ? 'false' : 'true' );
Branch: 1 branch
BranchTrueFalseTotal
$inHierarchical == 0 ? : 0 0 0
366 }
367  
368 0 ▶sub _createFilter {
Subroutine _createFilter: not called CC=5 SCAR=34.0
369 0 my ( $self, %args ) = @_;
370  
371 0 ▶ unless ( defined $args{classId} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"classId"}) 0 0 0
372 0 $self->{error} = 'No classId specified';
373 return
374 0 }
375  
376 0 my $filter = '<inFilter><and>';
377  
378 0 ▶ while ( my( $property,$value ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
379 0 ▶ next if ( $property eq 'inHierarchical' or $property eq 'classId' );
Branch: 1 branch
BranchTrueFalseTotal
if $property eq "inHierarchical" or $property eq "classId" 0 0 0
Condition0%0/3
$property eq "inHierarchical" or $property eq "classId"
l!l&&r!l&&!r
000
MC/DC0%0/2
$property eq "inHierarchical" or $property eq "classId"
$property eq "inHierarchical" $property eq "classId"
Truth table0%0/3
A or B
A= $property eq "inHierarchical"B= $property eq "classId"
ABresult
1X1
011
000
380 0 $filter .= '<eq class="' . $args{classId} . '" property="'
381 . $property . '" value="' . $value . '" />';
382 }
383  
384 0 $filter .= '</and></inFilter>';
385  
386 0 return $filter;
387 }
388  
389 0 ▶sub resolve_class {
Subroutine resolve_class: not called CC=4 SCAR=30.0
Pod documented
390 0 my ( $self, %args ) = @_;
391  
392 0 ▶ unless ( defined $args{classId} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"classId"}) 0 0 0
393 0 $self->{error} = 'No classId specified';
394 return
395 0 }
396  
397 $args{inHierarchical} = (
398 defined $args{inHierarchical}
399 ? _isInHierarchical( $args{inHierarchical} )
400 0 ▶ : 'false'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inHierarchical'} ? : 0 0 0
401 );
402  
403 my $xml = $self->_ucsm_request( '<configResolveClass inHierarchical="'
404 . $args{inHierarchical} .'" cookie="'
405 . $self->{cookie} .'" classId="'
406 0 ▶ . $args{classId} .'" />' ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request('<configResolveClass inHierarchical="' . $args{"inHierarchical"} . '" cookie="' . $self->{"cookie"} . '" classId="' . $args{"classId"} . '" />') or return 0 0 0
407  
408 0 return $xml
409 }
410  
411 0 ▶sub resolve_classes {
Subroutine resolve_classes: not called CC=4 SCAR=30.0
Pod documented
412 0 my ( $self, %args ) = @_;
413  
414 0 ▶ unless ( defined $args{classId} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"classId"}) 0 0 0
415 0 $self->{error} = 'No classID specified';
416 return
417 0 }
418  
419 $args{inHierarchical} = (
420 defined $args{inHierarchical}
421 ? _isInHierarchical( $args{inHierarchical} )
422 0 ▶ : 'false'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inHierarchical'} ? : 0 0 0
423 );
424  
425 my $xml = $self->_ucsm_request( '<configResolveClasses inHierarchical="'
426 . $args{inHierarchical}
427 . '" cookie="'. $self->{cookie} .'">'
428 . '<inIds><Id value="'. $args{classId}
429 0 ▶ . '" /></inIds></configResolveClasses>', 'classId'
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request('<configResolveClasses inHierarchical="' . $args{"inHierarchical"} . '" cookie="' . $self->{"cookie"} . '">' . "<inIds><Id value=\"" . $args{"classId"} . '" /></inIds></configResolveClasses>', "classId") or return 0 0 0
430 ) or return;
431  
432 0 return $xml
433 }
434  
435 0 ▶sub resolve_dn {
Subroutine resolve_dn: not called CC=4 SCAR=30.0
Pod documented
436 0 my ( $self, %args ) = @_;
437  
438 0 ▶ unless ( defined $args{dn} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dn"}) 0 0 0
439 0 $self->{error} = 'No dn specified';
440 return
441 0 }
442  
443 $args{inHierarchical} = (
444 defined $args{inHierarchical}
445 ? _isInHierarchical( $args{inHierarchical} )
446 0 ▶ : 'false'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inHierarchical'} ? : 0 0 0
447 );
448  
449 my $xml = $self->_ucsm_request( '<configResolveDn dn="'. $args{dn}
450 . '" inHierarchical="'. $args{inHierarchical}
451 0 ▶ . '" cookie="'. $self->{cookie} .'" />'
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request('<configResolveDn dn="' . $args{"dn"} . '" inHierarchical="' . $args{"inHierarchical"} . '" cookie="' . $self->{"cookie"} . '" />') or return 0 0 0
452 ) or return;
453  
454 0 return $xml;
455 }
456  
457 0 ▶sub resolve_children {
Subroutine resolve_children: not called CC=4 SCAR=30.0
Pod documented
458 0 my ( $self, %args ) = @_;
459  
460 0 ▶ unless ( defined $args{dn} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dn"}) 0 0 0
461 0 $self->{error} = 'No dn specified';
462 return
463 0 }
464  
465 $args{inHierarchical} = (
466 defined $args{inHierarchical}
467 ? _isInHierarchical( $args{inHierarchical} )
468 0 ▶ : 'false'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inHierarchical'} ? : 0 0 0
469 );
470  
471 my $xml = $self->_ucsm_request( '<configResolveChildren inHierarchical="'
472 . $args{inHierarchical} .'" cookie="'
473 . $self->{cookie} .'" inDn="'
474 0 ▶ . $args{dn} .'"></configResolveChildren>'
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request('<configResolveChildren inHierarchical="' . $args{"inHierarchical"} . '" cookie="' . $self->{"cookie"} . '" inDn="' . $args{"dn"} . '"></configResolveChildren>') or return 0 0 0
475 ) or return;
476  
477 0 return $xml
478 }
479  
480 0 ▶sub resolve_class_filter {
Subroutine resolve_class_filter: not called CC=4 SCAR=30.0
Pod documented
481 0 my( $self, %args ) = @_;
482
483 $args{inHierarchical} = (
484 defined $args{inHierarchical}
485 ? _isInHierarchical( $args{inHierarchical} )
486 0 ▶ : 'false'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inHierarchical'} ? : 0 0 0
487 );
488  
489 0 ▶ my $filter = $self->_createFilter( %args ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $filter = $self->_createFilter(%args) or return 0 0 0
490  
491 my $xml = $self->_ucsm_request( '<configResolveClass classId="'
492 . $args{classId} .'" inHierarchical="'
493 . $args{inHierarchical} .'" cookie="'
494 . $self->{cookie} .'">' . $filter
495 . '</configResolveClass>', $args{classId}
496 0 ▶ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request('<configResolveClass classId="' . $args{"classId"} . '" inHierarchical="' . $args{"inHierarchical"} . '" cookie="' . $self->{"cookie"} . '">' . $filter . '</configResolveClass>', $args{"classId"}) or return 0 0 0
497  
498 0 return $xml
499 }
500  
501 0 ▶sub get_cluster_status {
Subroutine get_cluster_status: not called CC=3 SCAR=24.8
Pod documented
502 0 my $self = shift;
503  
504 0 ▶ my $xml = $self->resolve_dn( dn => 'sys' ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->resolve_dn("dn", "sys") or return 0 0 0
505  
506 return (
507 defined $xml->{outConfig}->{topSystem}
508 ? $xml->{outConfig}->{topSystem}
509 : undef
510 )
511 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'outConfig'}{'topSystem'} ? : 0 0 0
512  
513 0 ▶sub version {
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
514 0 my $self = shift;
515  
516 0 ▶ my $xml = $self->resolve_dn( dn => 'sys/mgmt/fw-system' ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->resolve_dn("dn", "sys/mgmt/fw-system") or return 0 0 0
517  
518 return (
519 defined $xml->{outConfig}->{firmwareRunning}->{version}
520 ? $xml->{outConfig}->{firmwareRunning}->{version}
521 : undef
522 )
523 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'outConfig'}{'firmwareRunning'}{'version'} ? : 0 0 0
524  
525 0 ▶sub mgmt_entity {
Subroutine mgmt_entity: not called CC=2 SCAR=17.9
Pod documented
526 0 my ( $self, $id ) = @_;
527  
528 return (
529 defined $self->{mgmt_entity}->{$id}
530 0 ▶ ? $self->{mgmt_entity}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'mgmt_entity'}{$id} ? : 0 0 0
531 : $self->mgmt_entity($id)
532 )
533 }
534  
535 0 ▶sub get_mgmt_entity {
Subroutine get_mgmt_entity: not called CC=1 SCAR=6.9
Pod documented
536 0 my ( $self, $id ) = @_;
537  
538 0 return $self->get_mgmt_entities( $id )
539 }
540  
541 0 ▶sub get_mgmt_entities {
Subroutine get_mgmt_entities: not called CC=1 SCAR=6.9
Pod documented
542 0 my ( $self, $id ) = @_;
543  
544 0 return $self->_get_child_objects(
545 id => $id,
546 type => 'mgmtEntity',
547 class => 'Cisco::UCS::MgmtEntity',
548 attr => 'mgmt_entity'
549 );
550 }
551  
552 0 ▶sub get_primary_mgmt_entity {
Subroutine get_primary_mgmt_entity: not called CC=3 SCAR=24.8
Pod documented
553 0 my $self = shift;
554  
555 0 ▶ my $xml = $self->resolve_class_filter(
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->resolve_class_filter("classId", "mgmtEntity", "leadership", "primary") or return 0 0 0
556 classId => 'mgmtEntity',
557 leadership => 'primary'
558 ) or return;
559  
560 return (
561 defined $xml->{outConfigs}->{mgmtEntity}
562 ? $xml->{outConfigs}->{mgmtEntity}
563 : undef
564 )
565 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'outConfigs'}{'mgmtEntity'} ? : 0 0 0
566  
567 0 ▶sub get_subordinate_mgmt_entity {
Subroutine get_subordinate_mgmt_entity: not called CC=3 SCAR=24.8
Pod documented
568 0 my $self = shift;
569  
570 0 ▶ my $xml = $self->resolve_class_filter(
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->resolve_class_filter("classId", "mgmtEntity", "leadership", "subordinate") or return 0 0 0
571 classId => 'mgmtEntity',
572 leadership => 'subordinate'
573 ) or return;
574  
575 return (
576 defined $xml->{outConfigs}->{mgmtEntity}
577 ? $xml->{outConfigs}->{mgmtEntity}
578 : undef
579 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'outConfigs'}{'mgmtEntity'} ? : 0 0 0
580 }
581  
582 0 ▶sub service_profile {
Subroutine service_profile: not called CC=2 SCAR=17.9
Pod documented
583 0 my ( $self, $id ) = @_;
584  
585 return (
586 defined $self->{service_profile}->{$id}
587 0 ▶ ? $self->{service_profile}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'service_profile'}{$id} ? : 0 0 0
588 : $self->get_service_profile($id)
589 )
590 }
591  
592 0 ▶sub get_service_profile {
Subroutine get_service_profile: not called CC=1 SCAR=6.9
Pod documented
593 0 my ( $self, $id ) = @_;
594  
595 0 return $self->get_service_profiles( $id )
596 }
597  
598 0 ▶sub get_service_profiles {
Subroutine get_service_profiles: not called CC=1 SCAR=6.9
Pod documented
599 0 my ( $self, $id ) = @_;
600  
601 0 return $self->_get_child_objects(
602 id => $id,
603 type => 'lsServer',
604 class => 'Cisco::UCS::ServiceProfile',
605 uid => 'name',
606 attr => 'service_profile',
607 class_filter => {
608 classId => 'lsServer'
609 }
610 );
611 }
612  
613 0 ▶sub interconnect {
Subroutine interconnect: not called CC=2 SCAR=17.9
Pod documented
614 0 my ( $self, $id ) = @_;
615  
616 return (
617 defined $self->{interconnect}->{$id}
618 0 ▶ ? $self->{interconnect}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'interconnect'}{$id} ? : 0 0 0
619 : $self->get_interconnect($id)
620 )
621 }
622  
623 0 ▶sub get_interconnect {
Subroutine get_interconnect: not called CC=1 SCAR=6.9
Pod documented
624 0 my ( $self, $id ) = @_;
625  
626 0 return $self->get_interconnects( $id )
627 }
628  
629 0 ▶sub get_interconnects {
Subroutine get_interconnects: not called CC=1 SCAR=6.9
Pod documented
630 0 my ( $self, $id ) = @_;
631  
632 0 return $self->_get_child_objects(
633 id => $id,
634 type => 'networkElement',
635 class => 'Cisco::UCS::Interconnect',
636 attr => 'interconnect'
637 );
638 }
639  
640 0 ▶sub blade {
Subroutine blade: not called CC=2 SCAR=17.9
Pod documented
641 0 my ( $self, $id ) = @_;
642  
643 return (
644 defined $self->{blade}->{$id}
645 0 ▶ ? $self->{blade}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'blade'}{$id} ? : 0 0 0
646 : $self->get_blade($id)
647 )
648 }
649  
650 0 ▶sub get_blade {
Subroutine get_blade: not called CC=1 SCAR=6.9
Pod documented
651 0 my ( $self, $id ) = @_;
652  
653 0 return $self->get_blades( $id )
654 }
655  
656 0 ▶sub get_blades {
Subroutine get_blades: not called CC=1 SCAR=6.9
Pod documented
657 0 my ( $self, $id, %args ) = @_;
658  
659 0 return $self->_get_child_objects(
660 id => $id,
661 type => 'computeBlade',
662 class => 'Cisco::UCS::Blade',
663 attr => 'blade',
664 uid => 'serverId',
665 class_filter => {
666 classId => 'computeBlade'
667 }
668 );
669 }
670  
671 0 ▶sub chassis {
Subroutine chassis: not called CC=2 SCAR=17.9
Pod documented
672 0 my ( $self, $id ) = @_;
673  
674 return (
675 defined $self->{chassis}->{$id}
676 0 ▶ ? $self->{chassis}->{$id}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'chassis'}{$id} ? : 0 0 0
677 : $self->get_chassis($id)
678 )
679 }
680  
681 0 ▶sub get_chassis {
Subroutine get_chassis: not called CC=1 SCAR=6.9
Pod documented
682 0 my ( $self, $id ) = @_;
683  
684 0 return $self->get_chassiss( $id )
685 }
686  
687 0 ▶sub get_chassiss {
Subroutine get_chassiss: not called CC=1 SCAR=6.9
Pod documented
688 0 my ( $self, $id ) = @_;
689  
690 0 return $self->_get_child_objects(
691 id => $id,
692 type => 'equipmentChassis',
693 class => 'Cisco::UCS::Chassis',
694 attr => 'chassis'
695 );
696 }
697  
698 0 ▶sub full_state_backup {
Subroutine full_state_backup: not called CC=1 SCAR=6.9
Pod documented
699 0 my ( $self, %args ) = @_;
700  
701 0 $args{backup_type} = 'full-state';
702  
703 0 return ( $self->_backup( %args ) );
704 }
705 0 ▶sub all_config_backup {
Subroutine all_config_backup: not called CC=1 SCAR=6.9
Pod documented
706 0 my ( $self, %args ) = @_;
707  
708 0 $args{backup_type} = 'config-all';
709  
710 0 return ( $self->_backup( %args ) );
711 }
712  
713 0 ▶sub system_config_backup {
Subroutine system_config_backup: not called CC=1 SCAR=6.9
Pod documented
714 0 my ( $self, %args ) = @_;
715  
716 0 $args{backup_type} = 'config-system';
717  
718 0 return ( $self->_backup( %args ) );
719 }
720  
721 0 ▶sub logical_config_backup {
Subroutine logical_config_backup: not called CC=1 SCAR=6.9
Pod documented
722 0 my ( $self, %args ) = @_;
723  
724 0 $args{backup_type} = 'config-logical';
725  
726 0 return ( $self->_backup( %args ) );
727 }
728  
729 0 ▶sub _backup {
Subroutine _backup: not called CC=14 SCAR=53.5
730 0 my ( $self, %args ) = @_;
731  
732 0 ▶ unless( defined $args{backup_type} and
Branch: 1 branch
BranchTrueFalseTotal
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"}) 0 0 0
Condition0%0/15
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"}
!ll&&!rl&&r
000
defined $args{"backup_type"} and defined $args{"backup_proto"} and defined $args{"backup_host"} and defined $args{"backup_target"} and defined $args{"backup_passwd"}
!ll&&!rl&&r
000
defined $args{"backup_type"} and defined $args{"backup_proto"} and defined $args{"backup_host"} and defined $args{"backup_target"}
!ll&&!rl&&r
000
defined $args{"backup_type"} and defined $args{"backup_proto"} and defined $args{"backup_host"}
!ll&&!rl&&r
000
defined $args{"backup_type"} and defined $args{"backup_proto"}
!ll&&!rl&&r
000
MC/DC0%0/6
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"}
defined $args{"backup_type"} defined $args{"backup_proto"} defined $args{"backup_host"} defined $args{"backup_target"} defined $args{"backup_passwd"} defined $args{"backup_username"}
Truth table0%0/7
A and B and C and D and E and F
A= defined $args{"backup_type"}B= defined $args{"backup_proto"}C= defined $args{"backup_host"}D= defined $args{"backup_target"}E= defined $args{"backup_passwd"}F= defined $args{"backup_username"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
733 defined $args{backup_proto} and
734 defined $args{backup_host} and
735 defined $args{backup_target} and
736 defined $args{backup_passwd} and
737 defined $args{backup_username} )
738 {
739 0 $self->{error} = 'Bad argument list';
740 return
741 0 }
742  
743 $args{admin_state} = (
744 defined $args{admin_state}
745 ? $args{admin_state}
746 0 ▶ : 'enabled'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'admin_state'} ? : 0 0 0
747 );
748  
749 $args{preserve_pooled_values} = (
750 defined $args{preserve_pooled_values}
751 ? $args{preserve_pooled_values}
752 0 ▶ : 'yes'
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'preserve_pooled_values'} ? : 0 0 0
753 );
754  
755 0 ▶ unless ( $args{backup_type} =~ /(config-all|full-state|config-system|config-logical)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"backup_type"} =~ /(config-all|full-state|config-system|config-logical)/i) 0 0 0
756 0 $self->{error} = "Bad backup type ($args{backup_type})";
757 return
758 0 }
759  
760 0 ▶ unless ( $args{backup_proto} =~ /^((t|s)?ftp)|(scp)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"backup_proto"} =~ /^((t|s)?ftp)|(scp)$/i) 0 0 0
761 0 $self->{error} = "Bad backup proto' ($args{backup_proto})";
762 return
763 0 }
764  
765 0 my $address = $self->get_cluster_status->{address};
766  
767 0 my $data = <<"XML";
768 <configConfMos cookie="$self->{cookie}" inHierarchical="false">
769 <inConfigs>
770 <pair key="sys">
771 <topSystem address="$address" dn="sys" name="$self->{cluster}">
772 <mgmtBackup adminState="$args{admin_state}" descr="" preservePooledValues="$args{preserve_pooled_values}"
773 proto="$args{backup_proto}" pwd="$args{backup_passwd}" remoteFile="$args{backup_target}"
774 rn="backup-$args{backup_host}" type="$args{backup_type}"
775 user="$args{backup_username}" policyOwner="local">
776 </mgmtBackup>
777 </topSystem>
778 </pair>
779 </inConfigs>
780 </configConfMos>
781 XML
782  
783 0 ▶ my $xml = $self->_ucsm_request( $data ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $xml = $self->_ucsm_request($data) or return 0 0 0
784  
785 0 ▶ if ( defined $xml->{'errorCode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xml->{"errorCode"}) 0 0 0
786 my $self->{error} = ( defined $xml->{'errorDescr'}
787 0 ▶ ? $xml->{'errorDescr'}
Branch: 1 branch
BranchTrueFalseTotal
defined $xml->{'errorDescr'} ? : 0 0 0
788 : "Unspecified error"
789 );
790 return
791 0 }
792  
793 0 return 1;
794 }
795  
796 2 1;
797  
798 __END__
↑ Summary UCS/Common/Fan.pm »