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
« ACS.pm ↑ Summary 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 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
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.03';
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  
279 =item id
280  
281 =item name
282  
283 =item tacacsConnection
284  
285 =item groupInfo
286  
287 =item legacyTACACS
288  
289 =item tacacs_SharedSecret
290  
291 =item singleConnect
292  
293 =item radius_SharedSecret
294  
295 =item subnets
296  
297 =item ips
298  
299 =item location
300  
301 =item deviceType
302  
303 =item displayedInHex
304  
305 =item keyWrap
306  
307 =item portCOA
308  
309 =back
310  
311 Formatting rules may be in place & enforced by Cisco ACS.
312  
313 =over 3
314  
315 =item description
316  
317 The device description.
318  
319 =item id
320  
321 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.
322  
323 =item name
324  
325 The device name, typically something like the sysName or hostname.
326  
327 =item tacacsConnection
328  
329 Boolean value (0 / 1) to indicate if TACACS+ is used on this device.
330  
331 =item groupInfo
332  
333 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.
334  
335 =item legacyTACACS
336  
337 Boolean value (0 / 1) that indicates support for legacy versions of TACACS+.
338  
339 =item tacacs_SharedSecret
340  
341 The shared key for TACACS+. When retrieving this information, the key is masked as **********.
342  
343 =item singleConnect
344  
345 The TACACS+ singleConnect setting.
346  
347 =item radius_SharedSecret
348  
349 The shared key for RADIUS. When retrieving this information, the key is masked as **********.
350  
351 =item subnets
352  
353 Array reference that contains hash entries of all IP information for the device entry, separated as C<netMask> and C<ipAddress> keys.
354  
355 =item ips
356  
357 Cleaned up instance of C<subnet>.
358  
359 =item location
360  
361 The device location field, as defined in C<groupInfo>.
362  
363 =item deviceType
364  
365 The specific device Type field.
366  
367 =item displayedInHex
368  
369 Boolean value (0 / 1). Used for RADIUS configuration.
370  
371 =item keyWrap
372  
373 Boolean value (0 / 1). Used for RADIUS configuration.
374  
375 =item portCOA
376  
377 TCP port for specific RADIUS purposes.
378  
379 =item toXML
380  
381 Dump the record in ACS accept XML formatting (without header).
382  
383 =item header
384  
385 Generate the correct XML header. Takes output of C<toXML> as argument.
386  
387 =back
388  
389 =over 3
390  
391 =item description
392  
393 The device group account description, typically used for full device group name.
394  
395 =item groupType
396  
397 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>.
398  
399 =back
400  
401 =back
402  
403 =head1 BUGS
404  
405  
406  
407 =head1 SUPPORT
408  
409  
410  
411 =head1 AUTHOR
412  
413 Hendrik Van Belleghem
414 CPAN ID: BEATNIK
415 hendrik.vanbelleghem@gmail.com
416  
417 =head1 COPYRIGHT
418  
419 This program is free software licensed under the...
420  
421 The General Public License (GPL)
422 Version 2, June 1991
423  
424 The full text of the license can be found in the
425 LICENSE file included with this module.
426  
427  
428 =head1 SEE ALSO
429  
430 perl(1).
431  
432 =cut
433  
434 #################### main pod documentation end ###################
435 1 __PACKAGE__->meta->make_immutable();
436  
437 1 1;
438 # The preceding line will help the module return a true value
439  
« ACS.pm ↑ Summary ACS/User.pm »