blib/lib/Net/Cisco/ACS/Device.pm

filter: Statementstmt 42.3% 39 / 92 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 54.5% 6 / 11 Podpod 40.0% 2 / 5 totaltotal 29.9% 47 / 157 CC 23 SCAR 49.4
CC
23
Cov
30%
toXML
272.0
parseSubnet
30.0
parseGroupInfo
20.0
CRAP 139.2
« blib/lib/Net/Cisco/ACS.pm ↑ Summary blib/lib/Net/Cisco/ACS/User.pm »
1 package Net::Cisco::ACS::Device;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 BEGIN {
7 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %actions);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ $VERSION = '0.02';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 @ISA = qw(Exporter);
11 1 @EXPORT = qw();
12 1 @EXPORT_OK = qw();
13 1 %EXPORT_TAGS = ();
14 };
15  
16 1 %actions = ( "query" => "/Rest/NetworkDevice/Device",
17 "create" => "/Rest/NetworkDevice/Device",
18 "update" => "/Rest/NetworkDevice/Device",
19 "getByName" => "/Rest/NetworkDevice/Device/name/",
20 "getById" => "/Rest/NetworkDevice/Device/id/",
21 );
22  
23 # MOOSE!
24  
25 1 has 'description' => (
26 is => 'rw',
27 isa => 'Any',
28 );
29  
30 1 has 'id' => (
31 is => 'rw',
32 isa => 'Str',
33 );
34  
35 1 has 'name' => (
36 is => 'rw',
37 isa => 'Str',
38 );
39  
40 1 has 'tacacsConnection' => (
41 is => 'rw',
42 isa => 'HashRef',
43 trigger => \&parseTacacsConnection,
44 auto_deref => 1,
45 );
46  
47 sub parseTacacsConnection
48 0 ▶{ my $self = shift;
Subroutine parseTacacsConnection: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $new_ref = shift;
50 0 $self->singleConnect($self->tacacsConnection->{"singleConnect"});
51 0 $self->tacacs_SharedSecret($self->tacacsConnection->{"sharedSecret"});
52 0 $self->legacyTACACS($self->tacacsConnection->{"legacyTACACS"});
53 };
54  
55 1 has 'groupInfo' => (
56 isa => 'Any',
57 is => 'rw',
58 trigger => \&parseGroupInfo,
59 );
60  
61 sub parseGroupInfo # STILL TO DO: Implement non-default groups!
62 0 ▶{ my $self = shift;
Subroutine parseGroupInfo: not called CC=4 SCAR=30.0
Pod undocumented
63 0 my $new_ref = shift;
64 0 for my $entry (@{ $new_ref })
65 0 ▶ { if ($entry->{"groupType"} eq "Location")
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"groupType"} eq "Location") 0 0 0
66 0 { $self->location($entry->{"groupName"});
67 }
68 0 ▶ if ($entry->{"groupType"} eq "Device Type")
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"groupType"} eq "Device Type") 0 0 0
69 0 { $self->deviceType($entry->{"groupName"});
70 }
71 }
72 }
73
74 1 has 'legacyTACACS' => (
75 is => 'rw',
76 isa => 'Str',
77 );
78  
79 1 has 'tacacs_SharedSecret' => (
80 is => 'rw',
81 isa => 'Str',
82 );
83  
84 1 has 'singleConnect' => (
85 is => 'rw',
86 isa => 'Str',
87 );
88  
89 1 has 'radius_SharedSecret' => (
90 is => 'rw',
91 isa => 'Str',
92 );
93  
94 1 has 'subnets' => (
95 is => 'rw',
96 isa => 'Any',
97 trigger => \&parseSubnet, # trigger modifier is calling within constructor
98 );
99  
100 sub parseSubnet
101 0 ▶{ my $self = shift;
Subroutine parseSubnet: not called CC=5 SCAR=34.0
Pod undocumented
102 0 my $new_ref = shift;
103 0 my @ips = ();
104 0 ▶ if (ref($new_ref) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new_ref eq "HASH") 0 0 0
105 0 { push(@ips,{ netMask => $new_ref->{"netMask"}, ipAddress => $new_ref->{"ipAddress"} }); }
106 0 ▶ if (ref($new_ref) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new_ref eq "ARRAY") 0 0 0
107 0 { for my $entry (@ { $new_ref })
108 0 ▶ { if (ref($entry) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry eq "HASH") 0 0 0
109 0 { push(@ips,{ netMask => $entry->{"netMask"}, ipAddress => $entry->{"ipAddress"} }); }
110 }
111 }
112 0 $self->ips([@ips]);
113 }
114  
115 1 has 'ips' => (
116 is => 'rw',
117 isa => 'ArrayRef',
118 auto_deref => 1,
119 );
120
121 1 has 'location' => (
122 is => 'rw',
123 isa => 'Str',
124 );
125  
126 1 has 'deviceType' => (
127 is => 'rw',
128 isa => 'Str',
129 );
130  
131 1 has 'displayedInHex' => (
132 is => 'rw',
133 isa => 'Str',
134 );
135  
136 1 has 'keyWrap' => (
137 is => 'rw',
138 isa => 'Str',
139 );
140  
141 1 has 'portCOA' => (
142 is => 'rw',
143 isa => 'Str',
144 );
145  
146 # No Moose
147  
148 sub toXML
149 0 ▶{ my $self = shift;
Subroutine toXML: not called CC=16 SCAR=56.1
Pod documented
150 0 my $result = "";
151 0 my $id = $self->id;
152 0 ▶ my $description = $self->description || "";
Condition0%0/2
$self->description || ''
l!l
00
MC/DC0%0/1
$self->description || ''
$self->description
Truth table0%0/2
A
A= $self->description
Aresult
11
00
153 0 ▶ my $name = $self->name || "";
Condition0%0/2
$self->name || ''
l!l
00
MC/DC0%0/1
$self->name || ''
$self->name
Truth table0%0/2
A
A= $self->name
Aresult
11
00
154 0 ▶ my $location = $self->location || "All Locations";
Condition0%0/2
$self->location || 'All Locations'
l!l
00
MC/DC0%0/1
$self->location || 'All Locations'
$self->location
Truth table0%0/2
A
A= $self->location
Aresult
11
00
155 0 ▶ my $devicetype = $self->deviceType || "All Device Types";
Condition0%0/2
$self->deviceType || 'All Device Types'
l!l
00
MC/DC0%0/1
$self->deviceType || 'All Device Types'
$self->deviceType
Truth table0%0/2
A
A= $self->deviceType
Aresult
11
00
156  
157 0 ▶ my $legacytacacs = $self->legacyTACACS || "false";
Condition0%0/2
$self->legacyTACACS || 'false'
l!l
00
MC/DC0%0/1
$self->legacyTACACS || 'false'
$self->legacyTACACS
Truth table0%0/2
A
A= $self->legacyTACACS
Aresult
11
00
158 0 ▶ my $tacacs_sharedsecret = $self->tacacs_SharedSecret || "";
Condition0%0/2
$self->tacacs_SharedSecret || ''
l!l
00
MC/DC0%0/1
$self->tacacs_SharedSecret || ''
$self->tacacs_SharedSecret
Truth table0%0/2
A
A= $self->tacacs_SharedSecret
Aresult
11
00
159 0 ▶ my $singleconnect = $self->singleConnect || "false";
Condition0%0/2
$self->singleConnect || 'false'
l!l
00
MC/DC0%0/1
$self->singleConnect || 'false'
$self->singleConnect
Truth table0%0/2
A
A= $self->singleConnect
Aresult
11
00
160  
161 0 ▶ my $displayedinhex = $self->displayedInHex || "true";
Condition0%0/2
$self->displayedInHex || 'true'
l!l
00
MC/DC0%0/1
$self->displayedInHex || 'true'
$self->displayedInHex
Truth table0%0/2
A
A= $self->displayedInHex
Aresult
11
00
162 0 ▶ my $keywrap = $self->keyWrap || "false";
Condition0%0/2
$self->keyWrap || 'false'
l!l
00
MC/DC0%0/1
$self->keyWrap || 'false'
$self->keyWrap
Truth table0%0/2
A
A= $self->keyWrap
Aresult
11
00
163 0 ▶ my $portcoa = $self->portCOA || "1700";
Condition0%0/2
$self->portCOA || '1700'
l!l
00
MC/DC0%0/1
$self->portCOA || '1700'
$self->portCOA
Truth table0%0/2
A
A= $self->portCOA
Aresult
11
00
164 0 ▶ my $radius_sharedsecret = $self->radius_SharedSecret || "";
Condition0%0/2
$self->radius_SharedSecret || ''
l!l
00
MC/DC0%0/1
$self->radius_SharedSecret || ''
$self->radius_SharedSecret
Truth table0%0/2
A
A= $self->radius_SharedSecret
Aresult
11
00
165  
166 0 $result = <<XML;
167 <description>$description</description>
168 <name>$name</name>
169 <groupInfo>
170 <groupName>$devicetype</groupName>
171 <groupType>Device Type</groupType>
172 </groupInfo>
173 <groupInfo>
174 <groupName>$location</groupName>
175 <groupType>Location</groupType>
176 </groupInfo>
177 XML
178  
179 0 ▶ if (ref($self->ips) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->ips eq "ARRAY") 0 0 0
180 0 { for my $ref ( @{ $self->ips } )
181 0 { my $netmask = $ref->{'netMask'};
182 0 my $ipaddress = $ref->{'ipAddress'};
183 0 $result .= <<XML;
184 <subnets><ipAddress>$ipaddress</ipAddress><netMask>$netmask</netMask></subnets>
185 XML
186 }
187 }
188  
189 0 ▶ if ($tacacs_sharedsecret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tacacs_sharedsecret) 0 0 0
190 0 $result .= <<XML;
191 <tacacsConnection>
192 <legacyTACACS>$legacytacacs</legacyTACACS>
193 <sharedSecret>$tacacs_sharedsecret</sharedSecret>
194 <singleConnect>$singleconnect</singleConnect>
195 </tacacsConnection>
196 XML
197 }
198  
199 0 ▶ if ($radius_sharedsecret)
Branch: 1 branch
BranchTrueFalseTotal
if ($radius_sharedsecret) 0 0 0
200 0 { $result .= <<XML;
201 <radiusConnection>
202 <displayedInHex>$displayedinhex</displayedInHex>
203 <keyWrap>$keywrap</keyWrap>
204 <portCoA>$portcoa</portCoA>
205 <sharedSecret>$radius_sharedsecret</sharedSecret>
206 </radiusConnection>
207 XML
208 }
209  
210 0 return $result;
211 }
212  
213 sub header
214 0 ▶{ my $self = shift;
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
215 0 my $devices = shift;
216 0 return qq(<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns1:device xmlns:ns1="networkdevice.rest.mgmt.acs.nm.cisco.com">$devices</ns1:device>);
217 }
218
219 =head1 NAME
220  
221 Net::Cisco::ACS::Device - Access Cisco ACS functionality through REST API - Device fields
222  
223 =head1 SYNOPSIS
224  
225 use Net::Cisco::ACS;
226 use Net::Cisco::ACS::Device;
227
228 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
229
230 my %devices = $acs->devices;
231 # Retrieve all devices from ACS
232 # Returns hash with device name / Net::Cisco::ACS::Device pairs
233  
234 print $acs->devices->{"MAIN_Router"}->toXML;
235 # Dump in XML format (used by ACS for API calls)
236
237 my $device = $acs->devices("name","MAIN_Router");
238 # Faster call to request specific device information by name
239  
240 my $device = $acs->devices("id","250");
241 # Faster call to request specific device information by ID (assigned by ACS, present in Net::Cisco::ACS::Device)
242  
243 $device->id(0); # Required for new device!
244 my $id = $acs->create($device);
245 # Create new device based on Net::Cisco::ACS::Device instance
246 # Return value is ID generated by ACS
247 print "Record ID is $id" if $id;
248 print $Net::Cisco::ACS::ERROR unless $id;
249 # $Net::Cisco::ACS::ERROR contains details about failure
250  
251 my $id = $acs->update($device);
252 # Update existing device based on Net::Cisco::ACS::Device instance
253 # Return value is ID generated by ACS
254 print "Record ID is $id" if $id;
255 print $Net::Cisco::ACS::ERROR unless $id;
256 # $Net::Cisco::ACS::ERROR contains details about failure
257  
258 $acs->delete($device);
259 # Delete existing device based on Net::Cisco::ACS::Device instance
260  
261 =head1 DESCRIPTION
262  
263 The Net::Cisco::ACS::Device class holds all the device relevant information from Cisco ACS 5.x
264  
265 =head1 USAGE
266  
267 All calls are typically handled through an instance of the L<Net::Cisco::ACS> class. L<Net::Cisco::ACS::Device> acts as a container for device group related information.
268  
269 =over 3
270  
271 =item new
272  
273 Class constructor. Returns object of Net::Cisco::ACS::Device on succes. The following fields can be set / retrieved:
274  
275 =over 5
276  
277 =item description
278 =item id
279 =item name
280 =item tacacsConnection
281 =item groupInfo
282 =item legacyTACACS
283 =item tacacs_SharedSecret
284 =item singleConnect
285 =item radius_SharedSecret
286 =item subnets
287 =item ips
288 =item location
289 =item deviceType
290 =item displayedInHex
291 =item keyWrap
292 =item portCOA
293  
294 =back
295  
296 Formatting rules may be in place & enforced by Cisco ACS.
297  
298 =over 3
299  
300 =item description
301  
302 The device description.
303  
304 =item id
305  
306 The device ID. Cisco ACS generates a unique ID for each Host record. This field cannot be updated within ACS but is used for reference. Set to 0 when creating a new record or when duplicating an existing host.
307  
308 =item name
309  
310 The device name, typically something like the sysName or hostname.
311  
312 =item tacacsConnection
313  
314 Boolean value (0 / 1) to indicate if TACACS+ is used on this device.
315  
316 =item groupInfo
317  
318 Read-only value that contains C<deviceType>, C<location> and other device type information. Only C<deviceType>, C<location> are retrievable by the respective methods.
319  
320 =item legacyTACACS
321  
322 Boolean value (0 / 1) that indicates support for legacy versions of TACACS+.
323  
324 =item tacacs_SharedSecret
325  
326 The shared key for TACACS+. When retrieving this information, the key is masked as **********.
327  
328 =item singleConnect
329  
330 The TACACS+ singleConnect setting.
331  
332 =item radius_SharedSecret
333  
334 The shared key for RADIUS. When retrieving this information, the key is masked as **********.
335  
336 =item subnets
337  
338 Array reference that contains hash entries of all IP information for the device entry, separated as C<netMask> and C<ipAddress> keys.
339  
340 =item ips
341  
342 Cleaned up instance of C<subnet>.
343  
344 =item location
345  
346 The device location field, as defined in C<groupInfo>.
347  
348 =item deviceType
349  
350 The specific device Type field.
351  
352 =item displayedInHex
353  
354 Boolean value (0 / 1). Used for RADIUS configuration.
355  
356 =item keyWrap
357  
358 Boolean value (0 / 1). Used for RADIUS configuration.
359  
360 =item portCOA
361  
362 TCP port for specific RADIUS purposes.
363  
364 =item toXML
365  
366 Dump the record in ACS accept XML formatting (without header).
367  
368 =item header
369  
370 Generate the correct XML header. Takes output of C<toXML> as argument.
371  
372 =back
373  
374 =over 3
375  
376 =item description
377  
378 The device group account description, typically used for full device group name.
379  
380 =item name
381  
382 The device group name. This is a required value in the constructor but can be redefined afterwards.
383  
384 =item groupType
385  
386 This points to the type of Device Group, typically Location or Device Type but can be customized. See also L<Net::Cisco::ACS::Device> C<deviceType>.
387  
388 =item id
389  
390 Cisco ACS generates a unique ID for each Device Group record. This field cannot be updated within ACS but is used for reference. Set to 0 when creating a new record or when duplicating an existing device group.
391  
392 =item toXML
393  
394 Dump the record in ACS accept XML formatting (without header).
395  
396 =item header
397  
398 Generate the correct XML header. Takes output of C<toXML> as argument.
399  
400 =back
401  
402 =head1 BUGS
403  
404  
405  
406 =head1 SUPPORT
407  
408  
409  
410 =head1 AUTHOR
411  
412 Hendrik Van Belleghem
413 CPAN ID: BEATNIK
414 hendrik.vanbelleghem@gmail.com
415  
416 =head1 COPYRIGHT
417  
418 This program is free software licensed under the...
419  
420 The General Public License (GPL)
421 Version 2, June 1991
422  
423 The full text of the license can be found in the
424 LICENSE file included with this module.
425  
426  
427 =head1 SEE ALSO
428  
429 perl(1).
430  
431 =cut
432  
433 #################### main pod documentation end ###################
434 1 __PACKAGE__->meta->make_immutable();
435  
436 1 1;
437 # The preceding line will help the module return a true value
438  
« blib/lib/Net/Cisco/ACS.pm ↑ Summary blib/lib/Net/Cisco/ACS/User.pm »