blib/lib/Net/Cisco/ACS.pm

filter: Statementstmt 14.2% 60 / 420 Branchbran 0.0% 0 / 162 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 56.6% 17 / 30 Podpod 84.6% 11 / 13 totaltotal 13.7% 88 / 638 CC 90 SCAR 54.0
CC
90
Cov
10%
query
552.0
parse_xml
420.0
update
156.0
CRAP 221.7
↑ Summary blib/lib/Net/Cisco/ACS/Device.pm »
1 package Net::Cisco::ACS;
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  
5 # REST IO stuff here
6 1 ▶use IO::Socket::SSL qw( SSL_VERIFY_NONE );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Generics
11 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Net::Cisco::ACS::*
16 1 ▶use Net::Cisco::ACS::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Net::Cisco::ACS::IdentityGroup;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Net::Cisco::ACS::Device;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Net::Cisco::ACS::DeviceGroup;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Net::Cisco::ACS::Host;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 BEGIN {
23 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $ERROR %actions);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶ $VERSION = '0.03';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 @ISA = qw(Exporter);
27 1 @EXPORT = qw();
28 1 @EXPORT_OK = qw();
29 1 %EXPORT_TAGS = ();
30
31 1 $ERROR = ""; # TODO: Document error properly!
32 1 %actions = ( "version" => "/Rest/Common/AcsVersion",
33 "serviceLocation" => "/Rest/Common/ServiceLocation",
34 "errorMessage" => "/Rest/Common/ErrorMessage",
35 );
36 }
37  
38 # Moose!
39  
40 has 'ssl_options' => (
41 is => 'rw',
42 isa => 'HashRef',
43 1 ▶ default => sub { { 'SSL_verify_mode' => SSL_VERIFY_NONE, 'verify_hostname' => '0' } }
Subroutine __ANON__: called CC=1 SCAR=0.0
44 1 );
45  
46 1 has 'ssl' => (
47 is => 'rw',
48 isa => 'Str',
49 default => '1',
50 );
51  
52 1 has 'hostname' => (
53 is => 'rw',
54 isa => 'Str',
55 required => '1',
56 );
57  
58 sub users # No Moose here :(
59 0 ▶{ my $self = shift;
Subroutine users: not called CC=4 SCAR=30.0
Pod documented
60 0 $ERROR = "";
61 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
62 0 { my %args = @_;
63 0 $self->{"Users"} = $args{"users"};
64 0 ▶ if ($args{"name"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 0 0 0
65 0 { $self->{"Users"} = $self->query("User","name",$args{"name"}); }
66 0 ▶ if ($args{"id"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"id"}) 0 0 0
67 0 { $self->{"Users"} = $self->query("User","id",$args{"id"}); }
68 } else
69 0 { $self->{"Users"} = $self->query("User");
70 }
71 0 return $self->{"Users"};
72 }
73  
74 sub identitygroups # No Moose here :(
75 0 ▶{ my $self = shift;
Subroutine identitygroups: not called CC=4 SCAR=30.0
Pod documented
76 0 $ERROR = "";
77 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
78 0 { my %args = @_;
79 0 $self->{"IdentityGroups"} = $args{"identitygroups"};
80 0 ▶ if ($args{"name"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 0 0 0
81 0 { $self->{"IdentityGroups"} = $self->query("IdentityGroup","name",$args{"name"}); }
82 0 ▶ if ($args{"id"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"id"}) 0 0 0
83 0 { $self->{"IdentityGroups"} = $self->query("IdentityGroup","id",$args{"id"}); }
84 } else
85 0 { $self->{"IdentityGroups"} = $self->query("IdentityGroup");
86 }
87 0 return $self->{"IdentityGroups"};
88 }
89  
90 sub devices # No Moose here :(
91 0 ▶{ my $self = shift;
Subroutine devices: not called CC=4 SCAR=30.0
Pod documented
92 0 $ERROR = "";
93 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
94 0 { my %args = @_;
95 0 $self->{"Devices"} = $args{"devices"};
96 0 ▶ if ($args{"name"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 0 0 0
97 0 { $self->{"Devices"} = $self->query("Device","name",$args{"name"}); }
98 0 ▶ if ($args{"id"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"id"}) 0 0 0
99 0 { $self->{"Devices"} = $self->query("Device","id",$args{"id"}); }
100 } else
101 0 { $self->{"Devices"} = $self->query("Device");
102 }
103 0 return $self->{"Devices"};
104 }
105  
106 sub devicegroups # No Moose here :(
107 0 ▶{ my $self = shift;
Subroutine devicegroups: not called CC=4 SCAR=30.0
Pod documented
108 0 $ERROR = "";
109 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
110 0 { my %args = @_;
111 0 $self->{"DeviceGroups"} = $args{"devicegroups"};
112 0 ▶ if ($args{"name"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 0 0 0
113 0 { $self->{"DeviceGroups"} = $self->query("DeviceGroup","name",$args{"name"}); }
114 0 ▶ if ($args{"id"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"id"}) 0 0 0
115 0 { $self->{"DeviceGroups"} = $self->query("DeviceGroup","id",$args{"id"}); }
116 } else
117 0 { $self->{"DeviceGroups"} = $self->query("DeviceGroup");
118 }
119 0 return $self->{"DeviceGroups"};
120 }
121  
122 sub hosts # No Moose here :(
123 0 ▶{ my $self = shift;
Subroutine hosts: not called CC=4 SCAR=30.0
Pod documented
124 0 $ERROR = "";
125 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
126 0 { my %args = @_;
127 0 $self->{"Hosts"} = $args{"hosts"};
128 0 ▶ if ($args{"name"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"}) 0 0 0
129 0 { $self->{"Hosts"} = $self->query("Host","name",$args{"name"}); }
130 0 ▶ if ($args{"id"})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"id"}) 0 0 0
131 0 { $self->{"Hosts"} = $self->query("Host","id",$args{"id"}); }
132 } else
133 0 { $self->{"Hosts"} = $self->query("Host");
134 }
135 0 return $self->{"Hosts"};
136 }
137
138 1 has 'username' => (
139 is => 'rw',
140 isa => 'Str',
141 required => '1',
142 );
143  
144 1 has 'password' => (
145 is => 'rw',
146 isa => 'Str',
147 required => '1',
148 );
149  
150 sub version # No Moose here :(
151 0 ▶{ my $self = shift;
Subroutine version: not called CC=2 SCAR=17.9
Pod documented
152 0 $ERROR = "";
153 0 ▶ unless ($self->{"Version"}) # Version is not going to magically change in one session
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"Version"}) 0 0 0
154 0 { $self->{"Version"} = $self->query("Version"); }
155 0 return $self->{"Version"};
156 }
157
158 sub servicelocation # No Moose here :(
159 0 ▶{ my $self = shift;
Subroutine servicelocation: not called CC=2 SCAR=17.9
Pod documented
160 0 $ERROR = "";
161 0 ▶ unless ($self->{"ServiceLocation"}) # serviceLocation is not going to magically change in one session
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ServiceLocation"}) 0 0 0
162 0 { $self->{"ServiceLocation"} = $self->query("ServiceLocation"); }
163 0 return $self->{"ServiceLocation"};
164 }
165  
166 sub errormessage # No Moose here :(
167 0 ▶{ my $self = shift;
Subroutine errormessage: not called CC=1 SCAR=6.9
Pod documented
168 0 $ERROR = "";
169 0 $self->{"ErrorMessage"} = $self->query("ErrorMessage");
170 0 return $self->{"ErrorMessage"};
171 }
172
173 # Non-Moose
174  
175 sub query
176 0 ▶{ my ($self, $type, $key, $value) = @_;
Subroutine query: not called CC=23 SCAR=63.1
Pod undocumented
177 0 my $hostname = $self->hostname;
178 0 my $credentials = encode_base64($self->username.":".$self->password);
179 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
180 0 { $hostname = "https://$hostname"; } else
181 0 { $hostname = "http://$hostname"; }
182 0 my $action = "";
183 0 my $mode = "";
184 0 ▶ $key ||= "";
Condition0%0/2
$key ||= ""
l!l
00
MC/DC0%0/1
$key ||= ""
$key
Truth table0%0/2
A
A= $key
Aresult
11
00
185 0 ▶ if ($type eq "User")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "User") 0 0 0
186 0 { $action = $Net::Cisco::ACS::User::actions{"query"};
187 0 $mode = "Users";
188 0 ▶ if ($key eq "name")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "name") 0 0 0
189 0 { $action = $Net::Cisco::ACS::User::actions{"getByName"}.$value;
190 0 $mode = "User";
191 }
192 0 ▶ if ($key eq "id")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id") 0 0 0
193 0 { $action = $Net::Cisco::ACS::User::actions{"getById"}.$value;
194 0 $mode = "User";
195 }
196 }
197 0 ▶ if ($type eq "IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IdentityGroup") 0 0 0
198 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"query"};
199 0 $mode = "IdentityGroups";
200 0 ▶ if ($key eq "name")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "name") 0 0 0
201 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"getByName"}.$value;
202 0 $mode = "IdentityGroup";
203 }
204 0 ▶ if ($key eq "id")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id") 0 0 0
205 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"getById"}.$value;
206 0 $mode = "IdentityGroup";
207 }
208 }
209 0 ▶ if ($type eq "Device")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Device") 0 0 0
210 0 { $action = $Net::Cisco::ACS::Device::actions{"query"};
211 0 $mode = "Devices";
212 0 ▶ if ($key eq "name")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "name") 0 0 0
213 0 { $action = $Net::Cisco::ACS::Device::actions{"getByName"}.$value;
214 0 $mode = "Device";
215 }
216 0 ▶ if ($key eq "id")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id") 0 0 0
217 0 { $action = $Net::Cisco::ACS::Device::actions{"getById"}.$value;
218 0 $mode = "Device";
219 }
220 }
221 0 ▶ if ($type eq "DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "DeviceGroup") 0 0 0
222 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"query"};
223 0 $mode = "DeviceGroups";
224 0 ▶ if ($key eq "name")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "name") 0 0 0
225 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"getByName"}.$value;
226 0 $mode = "DeviceGroup";
227 }
228 0 ▶ if ($key eq "id")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id") 0 0 0
229 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"getById"}.$value;
230 0 $mode = "DeviceGroup";
231 }
232 }
233 0 ▶ if ($type eq "Host")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Host") 0 0 0
234 0 { $action = $Net::Cisco::ACS::Host::actions{"query"};
235 0 $mode = "Hosts";
236 0 ▶ if ($key eq "macAddress")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "macAddress") 0 0 0
237 0 { $action = $Net::Cisco::ACS::Host::actions{"getByName"}.$value;
238 0 $mode = "Host";
239 }
240 0 ▶ if ($key eq "id")
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id") 0 0 0
241 0 { $action = $Net::Cisco::ACS::Host::actions{"getById"}.$value;
242 0 $mode = "Host";
243 }
244 }
245  
246 0 ▶ if ($type eq "Version")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Version") 0 0 0
247 0 { $action = $Net::Cisco::ACS::actions{"version"};
248 0 $mode = "Version";
249 }
250 0 ▶ if ($type eq "ServiceLocation")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ServiceLocation") 0 0 0
251 0 { $action = $Net::Cisco::ACS::actions{"serviceLocation"};
252 0 $mode = "ServiceLocation";
253 }
254 0 ▶ if ($type eq "ErrorMessage")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ErrorMessage") 0 0 0
255 0 { $action = $Net::Cisco::ACS::actions{"errorMessage"};
256 0 $mode = "ErrorMessage";
257 }
258
259 0 $hostname = $hostname . $action;
260 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
261 0 my $request = HTTP::Request->new(GET => $hostname );
262 0 $request->header('Authorization' => "Basic $credentials");
263 0 my $result = $useragent->request($request);
264 0 ▶ if ($result->code eq "400") { $ERROR = "Bad Request - HTTP Status: 400"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code eq 400) 0 0 0
265 0 ▶ if ($result->code eq "410") { $ERROR = "Unknown $type queried by name or ID - HTTP Status: 410"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code eq 410) 0 0 0
266 0 $self->parse_xml($mode, $result->content);
267 }
268  
269 sub create
270 0 ▶{ my $self = shift;
Subroutine create: not called CC=10 SCAR=47.0
Pod documented
271 0 my @entries = @_;
272 0 ▶ return unless @entries;
Branch: 1 branch
BranchTrueFalseTotal
unless @entries 0 0 0
273 0 my $hostname = $self->hostname;
274 0 my $credentials = encode_base64($self->username.":".$self->password);
275 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
276 0 { $hostname = "https://$hostname"; } else
277 0 { $hostname = "http://$hostname"; }
278 0 my $action = "";
279 0 my $data = "";
280 0 my $first = $entries[0];
281 0 ▶ while(@entries)
Branch: 1 branch
BranchTrueFalseTotal
if (@entries) 0 0 0
282 0 { my $record = shift @entries;
283 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
284 0 { $action = $Net::Cisco::ACS::User::actions{"create"};
285 }
286  
287 0 ▶ if (ref($record) eq "Net::Cisco::ACS::IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::IdentityGroup") 0 0 0
288 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"create"};
289 }
290  
291 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
292 0 { $action = $Net::Cisco::ACS::Device::actions{"create"};
293 }
294
295 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
296 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"create"};
297 }
298  
299 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
300 0 { $action = $Net::Cisco::ACS::Host::actions{"create"};
301 }
302 0 $data .= $record->toXML;
303 }
304
305 0 $data = $first->header($data);
306 0 $hostname = $hostname . $action;
307 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
308 0 my $request = HTTP::Request->new(POST => $hostname );
309 0 $request->content_type("application/xml");
310 0 $request->header("Authorization" => "Basic $credentials");
311 0 $request->content($data);
312 0 my $result = $useragent->request($request);
313 0 my $result_ref = $self->parse_xml("result", $result->content);
314 0 my $id = "";
315 0 ▶ if ($result->code ne "200")
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code ne '200') { } 0 0 0
316 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
317 } else
318 0 { $id = $result_ref->{"newBornId"}; }
319 0 return $id;
320 }
321  
322 sub update
323 0 ▶{ my $self = shift;
Subroutine update: not called CC=12 SCAR=50.5
Pod documented
324 0 my @entries = @_;
325 0 my $hostname = $self->hostname;
326 0 my $credentials = encode_base64($self->username.":".$self->password);
327 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
328 0 { $hostname = "https://$hostname"; } else
329 0 { $hostname = "http://$hostname"; }
330 0 my $action = "";
331 0 my $data = "";
332 0 my $first = $entries[0];
333 0 ▶ while(@entries)
Branch: 1 branch
BranchTrueFalseTotal
if (@entries) 0 0 0
334 0 { my $record = shift @entries;
335 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
336 0 { $action = $Net::Cisco::ACS::User::actions{"update"};
337 }
338  
339 0 ▶ if (ref($record) eq "Net::Cisco::ACS::IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::IdentityGroup") 0 0 0
340 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"update"};
341 }
342  
343 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
344 0 { $action = $Net::Cisco::ACS::Device::actions{"update"};
345 }
346
347 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
348 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"update"};
349 }
350  
351 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
352 0 { $action = $Net::Cisco::ACS::Host::actions{"update"};
353 }
354 0 $data .= $record->toXML;
355 }
356  
357 0 $data = $first->header($data);
358 0 $hostname = $hostname . $action;
359 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
360 0 my $request = HTTP::Request->new(PUT => $hostname );
361 0 $request->content_type("application/xml");
362 0 $request->header("Authorization" => "Basic $credentials");
363 0 $request->content($data);
364 0 my $result = $useragent->request($request);
365 0 my $result_ref = undef;
366 0 ▶ $result_ref = $self->parse_xml("result", $result->content) if $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $result_ref 0 0 0
367 0 ▶ $result_ref = {} unless $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $result_ref 0 0 0
368 0 my $id = "";
369 0 ▶ if ($result->code ne "200" && $result_ref->{"errorCode"})
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code ne '200' and $result_ref->{'errorCode'}) { } 0 0 0
Condition0%0/3
$result->code ne 200 and $result_ref->{"errorCode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$result->code ne 200 and $result_ref->{"errorCode"}
$result->code ne 200 $result_ref->{"errorCode"}
Truth table0%0/3
A and B
A= $result->code ne 200B= $result_ref->{"errorCode"}
ABresult
0X0
100
111
370 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
371 } else
372 0 { $id = $result_ref->{"newBornId"}; }
373 0 return $id;
374 }
375  
376 sub delete
377 0 ▶{ my $self = shift;
Subroutine delete: not called CC=12 SCAR=50.5
Pod documented
378 0 my $record = shift;
379 0 my $hostname = $self->hostname;
380 0 my $credentials = encode_base64($self->username.":".$self->password);
381 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
382 0 { $hostname = "https://$hostname"; } else
383 0 { $hostname = "http://$hostname"; }
384 0 my $action = "";
385 0 my $type = "";
386
387 0 ▶ if (ref($record) eq "ARRAY") { $record = $record->[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "ARRAY") 0 0 0
388 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
389 0 { $action = $Net::Cisco::ACS::User::actions{"getById"};
390 0 $type = "User";
391 }
392  
393 0 ▶ if (ref($record) eq "Net::Cisco::ACS::IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::IdentityGroup") 0 0 0
394 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"getById"};
395 0 $type = "IdentityGroup";
396 }
397
398 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
399 0 { $action = $Net::Cisco::ACS::Device::actions{"getById"};
400 0 $type = "Device";
401 }
402
403 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
404 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"getById"};
405 0 $type = "DeviceGroup";
406 }
407  
408 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
409 0 { $action = $Net::Cisco::ACS::Host::actions{"getById"};
410 0 $type = "Host";
411 }
412
413 0 my $data = $record->header($record->toXML);
414 0 $hostname = $hostname . $action.$record->id;
415 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
416 0 my $request = HTTP::Request->new(DELETE => $hostname );
417 0 $request->content_type("application/xml");
418 0 $request->header("Authorization" => "Basic $credentials");
419 0 $request->content($data);
420 0 my $result = $useragent->request($request);
421 0 my $result_ref = undef;
422 0 ▶ $result_ref = $self->parse_xml("result", $result->content) if $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $result_ref 0 0 0
423 0 ▶ $result_ref = {} unless $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $result_ref 0 0 0
424 0 my $id = "";
425 0 ▶ if ($result->code ne "200" && $result_ref->{"errorCode"})
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code ne 200 and $result_ref->{"errorCode"}) 0 0 0
Condition0%0/3
$result->code ne 200 and $result_ref->{"errorCode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$result->code ne 200 and $result_ref->{"errorCode"}
$result->code ne 200 $result_ref->{"errorCode"}
Truth table0%0/3
A and B
A= $result->code ne 200B= $result_ref->{"errorCode"}
ABresult
0X0
100
111
426 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
427 }
428 }
429  
430 sub parse_xml
431 0 ▶{ my $self = shift;
Subroutine parse_xml: not called CC=20 SCAR=60.4
Pod undocumented
432 0 my $type = shift;
433 0 my $xml_ref = shift;
434 0 my $xmlsimple = XML::Simple->new();
435 0 my $xmlout = $xmlsimple->XMLin($xml_ref);
436 0 ▶ if ($type eq "Users")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Users") 0 0 0
437 0 { my $users_ref = $xmlout->{"User"};
438 0 my %users = ();
439 0 for my $key (keys % {$users_ref})
440 0 { my $user = Net::Cisco::ACS::User->new( name => $key, %{ $users_ref->{$key} } );
441 0 $users{$key} = $user;
442 }
443 0 $self->{"Users"} = \%users;
444 0 return $self->{"Users"};
445 }
446 0 ▶ if ($type eq "User") # userByName and userById DO NOT return hash but a single instance of Net::Cisco::ACS::User
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "User") 0 0 0
447 0 { my %user_hash = %{ $xmlout };
448 0 my $user = Net::Cisco::ACS::User->new( %user_hash );
449 0 $self->{"Users"} = $user ;
450 0 return $self->{"Users"};
451 }
452  
453 0 ▶ if ($type eq "IdentityGroups")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IdentityGroups") 0 0 0
454 0 { my $identitygroups_ref = $xmlout->{"IdentityGroup"};
455 0 my %identitygroups = ();
456 0 for my $key (keys % {$identitygroups_ref})
457 0 { my $identitygroup = Net::Cisco::ACS::IdentityGroup->new( name => $key, %{ $identitygroups_ref->{$key} } );
458 0 $identitygroups{$key} = $identitygroup;
459 }
460 0 $self->{"IdentityGroups"} = \%identitygroups;
461 0 return $self->{"IdentityGroups"};
462 }
463 0 ▶ if ($type eq "IdentityGroup") # ByName and ById DO NOT return hash but a single instance of Net::Cisco::ACS::IdentityGroup
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IdentityGroup") 0 0 0
464 0 { my %identitygroup_hash = %{ $xmlout };
465 0 my $identitygroup = Net::Cisco::ACS::IdentityGroup->new( %identitygroup_hash );
466 0 $self->{"IdentityGroups"} = $identitygroup;
467 0 return $self->{"IdentityGroups"};
468 }
469
470 0 ▶ if ($type eq "Devices")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Devices") 0 0 0
471 0 { my $device_ref = $xmlout->{"Device"};
472 0 my %devices = ();
473 0 for my $key (keys % {$device_ref})
474 0 { my $device = Net::Cisco::ACS::Device->new( name => $key, %{ $device_ref->{$key} } );
475 0 $devices{$key} = $device;
476 }
477 0 $self->{"Devices"} = \%devices;
478 0 return $self->{"Devices"};
479 }
480 0 ▶ if ($type eq "Device") # deviceByName and deviceById DO NOT return hash but a single instance of Net::Cisco::ACS::Device
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Device") 0 0 0
481 0 { my %device_hash = %{ $xmlout };
482 0 my $device = Net::Cisco::ACS::Device->new( %device_hash );
483 0 $self->{"Devices"} = $device;
484 0 return $self->{"Devices"};
485 }
486  
487 0 ▶ if ($type eq "DeviceGroups")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "DeviceGroups") 0 0 0
488 0 { my $devicegroup_ref = $xmlout->{"DeviceGroup"};
489 0 my %devicegroups = ();
490 0 for my $key (keys % {$devicegroup_ref})
491 0 { my $devicegroup = Net::Cisco::ACS::DeviceGroup->new( name => $key, %{ $devicegroup_ref->{$key} } );
492 0 $devicegroups{$key} = $devicegroup;
493 }
494 0 $self->{"DeviceGroups"} = \%devicegroups;
495 0 return $self->{"DeviceGroups"};
496 }
497 0 ▶ if ($type eq "DeviceGroup") # deviceGroupByName and deviceGroupById DO NOT return hash but a single instance of Net::Cisco::ACS::DeviceGroup
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "DeviceGroup") 0 0 0
498 0 { my %devicegroup_hash = %{ $xmlout };
499 0 my $devicegroup = Net::Cisco::ACS::DeviceGroup->new( %devicegroup_hash );
500 0 $self->{"DeviceGroups"} = $devicegroup;
501 0 return $self->{"DeviceGroups"};
502 }
503
504 0 ▶ if ($type eq "Hosts")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Hosts") 0 0 0
505 0 { my $host_ref = $xmlout->{"Host"};
506 0 my %hosts = ();
507 0 for my $key (keys % {$host_ref})
508 0 { my $host = Net::Cisco::ACS::Host->new( macAddress => $key, %{ $host_ref->{$key} } );
509 0 $hosts{$key} = $host;
510 }
511 0 $self->{"Hosts"} = \%hosts;
512 0 return $self->{"Hosts"};
513 }
514 0 ▶ if ($type eq "Host") # ByName and ById DO NOT return hash but a single instance of Net::Cisco::ACS::Host
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Host") 0 0 0
515 0 { my %host_hash = %{ $xmlout };
516 0 my $host = Net::Cisco::ACS::Host->new( %host_hash );
517 0 $self->{"Hosts"} = $host;
518 0 return $self->{"Hosts"};
519 }
520
521 0 ▶ if ($type eq "result")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "result") 0 0 0
522 0 { my %result_hash = %{ $xmlout };
523 0 return \%result_hash;
524 }
525 0 ▶ if ($type eq "Version")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Version") 0 0 0
526 0 { my %version_hash = %{ $xmlout };
527 0 return \%version_hash;
528 }
529 0 ▶ if ($type eq "ServiceLocation")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ServiceLocation") 0 0 0
530 0 { my %servicelocation_hash = %{ $xmlout };
531 0 return \%servicelocation_hash;
532 }
533 0 ▶ if ($type eq "ErrorMessage")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ErrorMessage") 0 0 0
534 0 { my %errormessage_hash = %{ $xmlout };
535 0 return \%errormessage_hash;
536 }
537  
538 }
539  
540 =head1 NAME
541  
542 Net::Cisco::ACS - Access Cisco ACS functionality through REST API
543  
544 =head1 SYNOPSIS
545  
546 use Net::Cisco::ACS;
547 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
548 # Options:
549 # hostname - IP or hostname of Cisco ACS 5.x server
550 # username - Username of Administrator user
551 # password - Password of user
552 # ssl - SSL enabled (1 - default) or disabled (0)
553
554 my %users = $acs->users;
555 # Retrieve all users from ACS
556 # Returns hash with username / Net::Cisco::ACS::User pairs
557
558 print $acs->users->{"acsadmin"}->toXML;
559 # Dump in XML format (used by ACS for API calls)
560
561 my $user = $acs->users("name","acsadmin");
562 # Faster call to request specific user information by name
563  
564 my $user = $acs->users("id","150");
565 # Faster call to request specific user information by ID (assigned by ACS, present in Net::Cisco::ACS::User)
566  
567 my %identitygroups = $acs->identitygroups;
568 # Retrieve all identitygroups from ACS
569 # Returns hash with name / Net::Cisco::ACS::IdentityGroup pairs
570
571 print $acs->identitygroups->{"All Groups"}->toXML;
572 # Dump in XML format (used by ACS for API calls)
573
574 my $identitygroup = $acs->identitygroups("name","All Groups");
575 # Faster call to request specific identity group information by name
576  
577 my $identitygroup = $acs->identitygroups("id","150");
578 # Faster call to request specific identity group information by ID (assigned by ACS, present in Net::Cisco::ACS::IdentityGroup)
579
580 my %devices = $acs->devices;
581 # Retrieve all devices from ACS
582 # Returns hash with device name / Net::Cisco::ACS::Device pairs
583  
584 print $acs->devices->{"MAIN_Router"}->toXML;
585 # Dump in XML format (used by ACS for API calls)
586
587 my $device = $acs->devices("name","MAIN_Router");
588 # Faster call to request specific device information by name
589  
590 my $device = $acs->devices("id","250");
591 # Faster call to request specific device information by ID (assigned by ACS, present in Net::Cisco::ACS::Device)
592  
593 my %devicegroups = $acs->devicegroups;
594 # Retrieve all device groups from ACS
595 # Returns hash with device name / Net::Cisco::ACS::DeviceGroup pairs
596  
597 print $acs->devicegroups->{"All Locations"}->toXML;
598 # Dump in XML format (used by ACS for API calls)
599
600 my $device = $acs->devicegroups("name","All Locations");
601 # Faster call to request specific device group information by name
602  
603 my $devicegroup = $acs->devicegroups("id","250");
604 # Faster call to request specific device group information by ID (assigned by ACS, present in Net::Cisco::ACS::DeviceGroup)
605  
606 my %hosts = $acs->hosts;
607 # Retrieve all hosts from ACS
608 # Returns hash with host name / Net::Cisco::ACS::Host pairs
609  
610 print $acs->hosts->{"1234"}->toXML;
611 # Dump in XML format (used by ACS for API calls)
612
613 my $host = $acs->hosts("name","1234");
614 # Faster call to request specific host information by name
615  
616 my $host = $acs->hosts("id","250");
617 # Faster call to request specific hosts information by ID (assigned by ACS, present in Net::Cisco::ACS::Host)
618
619 $user->id(0); # Required for new user!
620 my $id = $acs->create($user);
621 # Create new user based on Net::Cisco::ACS::User instance
622 # Return value is ID generated by ACS
623 print "Record ID is $id" if $id;
624 print $Net::Cisco::ACS::ERROR unless $id;
625 # $Net::Cisco::ACS::ERROR contains details about failure
626  
627 my $id = $acs->create(@users); # Still requires nullified ID!
628 # Create new users based on Net::Cisco::ACS::User instances in arguments
629 # Return value is not guaranteed in this case!
630 # print "Record ID is $id" if $id;
631 # print $Net::Cisco::ACS::ERROR unless $id;
632 # $Net::Cisco::ACS::ERROR contains details about failure
633
634 $identitygroup->id(0); # Required for new record!
635 my $id = $acs->create($identitygroup);
636 # Create new identity group based on Net::Cisco::ACS::IdentityGroup instance
637 # Return value is ID generated by ACS
638 print "Record ID is $id" if $id;
639 print $Net::Cisco::ACS::ERROR unless $id;
640 # $Net::Cisco::ACS::ERROR contains details about failure
641  
642 my $id = $acs->create(@identitygroups); # Still requires nullified ID!
643 # Create new identitygroups based on Net::Cisco::ACS::IdentityGroup instances in arguments
644 # Return value is not guaranteed in this case!
645 # print "Record ID is $id" if $id;
646 # print $Net::Cisco::ACS::ERROR unless $id;
647 # $Net::Cisco::ACS::ERROR contains details about failure
648
649 $device->id(0); # Required for new device!
650 my $id = $acs->create($device);
651 # Create new device based on Net::Cisco::ACS::Device instance
652 # Return value is ID generated by ACS
653 print "Record ID is $id" if $id;
654 print $Net::Cisco::ACS::ERROR unless $id;
655 # $Net::Cisco::ACS::ERROR contains details about failure
656  
657 my $id = $acs->create(@devices); # Still requires nullified ID!
658 # Create new devices based on Net::Cisco::ACS::Device instances in arguments
659 # Return value is not guaranteed in this case!
660 # print "Record ID is $id" if $id;
661 # print $Net::Cisco::ACS::ERROR unless $id;
662 # $Net::Cisco::ACS::ERROR contains details about failure
663  
664 $devicegroup->id(0); # Required for new device group!
665 my $id = $acs->create($devicegroup);
666 # Create new device group based on Net::Cisco::ACS::DeviceGroup instance
667 # Return value is ID generated by ACS
668 print "Record ID is $id" if $id;
669 print $Net::Cisco::ACS::ERROR unless $id;
670 # $Net::Cisco::ACS::ERROR contains details about failure
671  
672 my $id = $acs->create(@devicegroups); # Still requires nullified ID!
673 # Create new devicegroups based on Net::Cisco::ACS::DeviceGroup instances in arguments
674 # Return value is not guaranteed in this case!
675 # print "Record ID is $id" if $id;
676 # print $Net::Cisco::ACS::ERROR unless $id;
677 # $Net::Cisco::ACS::ERROR contains details about failure
678
679 $host->id(0); # Required for new host!
680 my $id = $acs->create($host);
681 # Create new host based on Net::Cisco::ACS::Host instance
682 # Return value is ID generated by ACS
683 print "Record ID is $id" if $id;
684 print $Net::Cisco::ACS::ERROR unless $id;
685 # $Net::Cisco::ACS::ERROR contains details about failure
686  
687 my $id = $acs->create(@hosts); # Still requires nullified ID!
688 # Create new hosts based on Net::Cisco::ACS::Host instances in arguments
689 # Return value is not guaranteed in this case!
690 # print "Record ID is $id" if $id;
691 # print $Net::Cisco::ACS::ERROR unless $id;
692 # $Net::Cisco::ACS::ERROR contains details about failure
693
694 my $id = $acs->update($user);
695 # Update existing user based on Net::Cisco::ACS::User instance
696 # Return value is ID generated by ACS
697 print "Record ID is $id" if $id;
698 print $Net::Cisco::ACS::ERROR unless $id;
699 # $Net::Cisco::ACS::ERROR contains details about failure
700  
701 my $id = $acs->update(@users);
702 # Update existing users based on Net::Cisco::ACS::User instances in arguments
703 # Return value is not guaranteed in this case!
704 # print "Record ID is $id" if $id;
705 # print $Net::Cisco::ACS::ERROR unless $id;
706 # $Net::Cisco::ACS::ERROR contains details about failure
707
708 my $id = $acs->update($identitygroup);
709 # Update existing identitygroup based on Net::Cisco::ACS::IdentityGroup instance
710 # Return value is ID generated by ACS
711 print "Record ID is $id" if $id;
712 print $Net::Cisco::ACS::ERROR unless $id;
713 # $Net::Cisco::ACS::ERROR contains details about failure
714  
715 my $id = $acs->update(@identitygroups);
716 # Update existing identitygroups based on Net::Cisco::ACS::IdentityGroups instances in arguments
717 # Return value is not guaranteed in this case!
718 # print "Record ID is $id" if $id;
719 # print $Net::Cisco::ACS::ERROR unless $id;
720 # $Net::Cisco::ACS::ERROR contains details about failure
721
722 my $id = $acs->update($device);
723 # Update existing device based on Net::Cisco::ACS::Device instance
724 # Return value is ID generated by ACS
725 print "Record ID is $id" if $id;
726 print $Net::Cisco::ACS::ERROR unless $id;
727 # $Net::Cisco::ACS::ERROR contains details about failure
728  
729 my $id = $acs->update(@devices);
730 # Update existing devices based on Net::Cisco::ACS::Device instances in arguments
731 # Return value is not guaranteed in this case!
732 # print "Record ID is $id" if $id;
733 # print $Net::Cisco::ACS::ERROR unless $id;
734 # $Net::Cisco::ACS::ERROR contains details about failure
735
736 my $id = $acs->update($devicegroup);
737 # Update existing device based on Net::Cisco::ACS::DeviceGroup instance
738 # Return value is ID generated by ACS
739 print "Record ID is $id" if $id;
740 print $Net::Cisco::ACS::ERROR unless $id;
741 # $Net::Cisco::ACS::ERROR contains details about failure
742
743 my $id = $acs->update(@devicegroups);
744 # Update existing devicegroups based on Net::Cisco::ACS::DeviceGroup instances in arguments
745 # Return value is not guaranteed in this case!
746 # print "Record ID is $id" if $id;
747 # print $Net::Cisco::ACS::ERROR unless $id;
748 # $Net::Cisco::ACS::ERROR contains details about failure
749
750 my $id = $acs->update($host);
751 # Update existing device based on Net::Cisco::ACS::Host instance
752 # Return value is ID generated by ACS
753 print "Record ID is $id" if $id;
754 print $Net::Cisco::ACS::ERROR unless $id;
755 # $Net::Cisco::ACS::ERROR contains details about failure
756  
757 my $id = $acs->update(@hosts);
758 # Update existing hosts based on Net::Cisco::ACS::Host instances in arguments
759 # Return value is not guaranteed in this case!
760 # print "Record ID is $id" if $id;
761 # print $Net::Cisco::ACS::ERROR unless $id;
762 # $Net::Cisco::ACS::ERROR contains details about failure
763
764 $acs->delete($user);
765 # Delete existing user based on Net::Cisco::ACS::User instance
766  
767 $acs->delete($identitygroup);
768 # Delete existing identity group based on Net::Cisco::ACS::IdentityGroup instance
769
770 $acs->delete($device);
771 # Delete existing device based on Net::Cisco::ACS::Device instance
772  
773 $acs->delete($devicegroup);
774 # Delete existing device based on Net::Cisco::ACS::DeviceGroup instance
775  
776 $acs->delete($host);
777 # Delete existing host based on Net::Cisco::ACS::Host instance
778
779 $acs->version
780 # Return version information for the connected server *HASHREF*
781  
782 $acs->serviceLocation
783 # Return ACS instance that serves as primary and the ACS instance that provide Monitoring and Troubleshooting Viewer. *HASHREF*
784
785 $acs->errorMessage
786 # Return all ACS message codes and message texts that are used on the REST Interface. *HASHREF*
787  
788
789 =head1 DESCRIPTION
790  
791 Net::Cisco::ACS is an implementation of the Cisco Secure Access Control System (ACS) REST API. Cisco ACS is a application / appliance that can be used for network access policy control. In short, it allows configuration of access policies for specific users onto specific devices and applications (either using RADIUS or TACACS+ authentication). Net::Cisco::ACS currently supports Device, Device Group, Host, User, Identity Group and generic information.
792  
793 =head1 USAGE
794  
795 All calls are handled through an instance of the L<Net::Cisco::ACS> class.
796  
797 use Net::Cisco::ACS;
798 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
799  
800 =over 3
801  
802 =item new
803  
804 Class constructor. Returns object of Net::Cisco::ACS on succes. Required fields are:
805  
806 =over 5
807  
808 =item hostname
809  
810 =item username
811  
812 =item password
813  
814 =back
815  
816 Optional fields are
817  
818 =over 5
819  
820 =item ssl
821  
822 =item ssl_options
823  
824 =back
825  
826 =item hostname
827  
828 IP or hostname of Cisco ACS 5.x server. This is a required value in the constructor but can be redefined afterwards.
829  
830 =item username
831  
832 Username of Administrator user. This is a required value in the constructor but can be redefined afterwards.
833  
834 =item password
835  
836 Password of user. This is a required value in the constructor but can be redefined afterwards.
837  
838 =item ssl
839  
840 SSL enabled (1 - default) or disabled (0).
841  
842 =item ssl_options
843  
844 Value is passed directly to LWP::UserAGent as ssl_opt. Default value (hash-ref) is
845  
846 { 'SSL_verify_mode' => SSL_VERIFY_NONE, 'verify_hostname' => '0' }
847  
848 =back
849  
850 From the class instance, call the different methods for retrieving values.
851  
852 =over 3
853  
854 =item users
855  
856 Returns hash or single instance, depending on context.
857  
858 my %users = $acs->users(); # Slow
859 my $user = $acs->users()->{"acsadmin"};
860 print $user->name;
861
862 The returned hash contains instances of L<Net::Cisco::ACS::User>, using name (typically the username) as the hash key. Using a call to C<users> with no arguments will retrieve all users and can take quite a few seconds (depending on the size of your database). When you know the username or ID, use the L<users> call with arguments as listed below.
863
864 my $user = $acs->users("name","acsadmin"); # Faster
865 # or
866 my $user = $acs->users("id","123"); # Faster
867 print $user->name;
868  
869 The ID is typically generated by Cisco ACS when the entry is created. It can be retrieved by calling the C<id> method on the object.
870  
871 print $user->id;
872  
873 =item identitygroups
874  
875 Returns hash or single instance, depending on context.
876  
877 my %identitygroups = $acs->identitygroups(); # Slow
878 my $identitygroup = $acs->identitygroups()->{"All Groups"};
879 print $identitgroup->name;
880
881 The returned hash contains instances of L<Net::Cisco::ACS::IdentityGroup>, using name (typically the username) as the hash key. Using a call to C<identitygroup> with no arguments will retrieve all identitygroups and can take quite a few seconds (depending on the size of your database). When you know the group name or ID, use the L<identitygroups> call with arguments as listed below.
882
883 my $identitygroup = $acs->identitygroups("name","All Groups"); # Faster
884 # or
885 my $identitygroup = $acs->identitygroups("id","123"); # Faster
886 print $identitygroup->name;
887  
888 The ID is typically generated by Cisco ACS when the entry is created. It can be retrieved by calling the C<id> method on the object.
889  
890 print $identitygroup->id;
891
892 =item devices
893  
894 Returns hash or single instance, depending on context.
895  
896 my %devices = $acs->devices(); # Slow
897 my $device = $acs->devices()->{"Main_Router"};
898 print $device->name;
899
900 The returned hash contains instances of L<Net::Cisco::ACS::Device>, using name (typically the sysname) as the hash key. Using a call to C<device> with no arguments will retrieve all devices and can take quite a few seconds (depending on the size of your database). When you know the hostname or ID, use the L<devices> call with arguments as listed below.
901
902 my $device = $acs->device("name","Main_Router"); # Faster
903 # or
904 my $device = $acs->device("id","123"); # Faster
905 print $device->name;
906  
907 The ID is typically generated by Cisco ACS when the entry is created. It can be retrieved by calling the C<id> method on the object.
908  
909 print $device->id;
910  
911 =item devicegroups
912  
913 Returns hash or single instance, depending on context.
914  
915 my %devicegroups = $acs->devicegroups(); # Slow
916 my $devicegroup = $acs->devicegroups()->{"All Locations:Main Site"};
917 print $devicegroup->name;
918  
919 The returned hash contains instances of L<Net::Cisco::ACS::DeviceGroup>, using name (typically the device group name) as the hash key. Using a call to C<devicegroups> with no arguments will retrieve all device groups and can take quite a few seconds (depending on the size of your database). When you know the device group or ID, use the L<devicegroups> call with arguments as listed below.
920
921 my $devicegroup = $acs->devicegroups("name","All Locations::Main Site"); # Faster
922 # or
923 my $devicegroup = $acs->devicegroups("id","123"); # Faster
924 print $devicegroup->name;
925  
926 The ID is typically generated by Cisco ACS when the entry is created. It can be retrieved by calling the C<id> method on the object.
927  
928 print $devicegroup->id;
929  
930 =item hosts
931  
932 Returns hash or single instance, depending on context.
933  
934 my %hosts = $acs->hosts(); # Slow
935 my $host = $acs->hosts()->{"12345"};
936 print $host->name;
937
938 The returned hash contains instances of L<Net::Cisco::ACS::Host>, using name as the hash key. Using a call to C<hosts> with no arguments will retrieve all hosts and can take quite a few seconds (depending on the size of your database). When you know the name or ID, use the L<hosts> call with arguments as listed below.
939
940 my $host = $acs->host("name","12345"); # Faster
941 # or
942 my $host = $acs->device("id","123"); # Faster
943 print $host->name;
944  
945 The ID is typically generated by Cisco ACS when the entry is created. It can be retrieved by calling the C<id> method on the object.
946  
947 print $host->id;
948
949 =item version
950  
951 This method returns version specific information about the Cisco ACS instance you're connected to. Values are returned in a hash reference.
952  
953 use Data::Dumper;
954 # ...
955 print Dumper $acs->version;
956  
957 =item servicelocation
958  
959 This method returns information about the ACS instance that serves as primary and the ACS instance that provide Monitoring and Troubleshooting Viewer. Values are returned in a hash reference.
960  
961 use Data::Dumper;
962 # ...
963 print Dumper $acs->servicelocation;
964  
965 =item errormessage
966  
967 This method returns all ACS message codes and message texts that are used on the REST Interface. Values are returned in a hash reference. See also C<$Net::Cisco::ACS::ERROR>.
968  
969 use Data::Dumper;
970 # ...
971 print Dumper $acs->errormessage;
972  
973 =item create
974  
975 This method created a new entry in Cisco ACS, depending on the argument passed. Record type is detected automatically. For all record types, the ID value must be set to 0.
976  
977 my $user = $acs->users("name","acsadmin");
978 $user->id(0); # Required for new user!
979 $user->name("altadmin"); # Required field
980 $user->password("TopSecret"); # Password policies will be enforced!
981 $user->description("Alternate Admin");
982 my $id = $acs->create($user);
983 # Create new user based on Net::Cisco::ACS::User instance
984 # Return value is ID generated by ACS
985 print "Record ID is $id" if $id;
986 print $Net::Cisco::ACS::ERROR unless $id;
987 # $Net::Cisco::ACS::ERROR contains details about failure
988  
989 my $device = $acs->devices("name","Main_Router");
990 $device->name("AltRouter"); # Required field
991 $device->description("Standby Router");
992 $device->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # Change IP address! Overlap check is enforced!
993 $device->id(0); # Required for new device!
994 my $id = $acs->create($device);
995 # Create new device based on Net::Cisco::ACS::Device instance
996 # Return value is ID generated by ACS
997 print "Record ID is $id" if $id;
998 print $Net::Cisco::ACS::ERROR unless $id;
999 # $Net::Cisco::ACS::ERROR contains details about failure
1000  
1001 Multiple instances can be passed as an argument. Objects will be created in bulk (one transaction). The returned ID is not guaranteed to be the IDs of the created objects.
1002  
1003 my $user = $acs->users("name","acsadmin");
1004 $user->id(0); # Required for new user!
1005 $user->name("altadmin"); # Required field
1006 $user->password("TopSecret"); # Password policies will be enforced!
1007 $user->description("Alternate Admin");
1008  
1009 my $user2 = $acs->users("name","acsadmin");
1010 $user2->id(0); # Required for new user!
1011 $user2->name("altadmin"); # Required field
1012 $user2->password("TopSecret"); # Password policies will be enforced!
1013 $user2->description("Alternate Admin");
1014  
1015 my $id = $acs->create($user,$user2);
1016 # Create new users based on Net::Cisco::ACS::User instances in argument.
1017 # Return value is ID generated by ACS but not guaranteed.
1018 # print "Record ID is $id" if $id;
1019 # print $Net::Cisco::ACS::ERROR unless $id;
1020 # $Net::Cisco::ACS::ERROR contains details about failure
1021  
1022 my $device = $acs->devices("name","Main_Router");
1023 $device->name("MainRouter"); # Required field
1024 $device->description("Main Router");
1025 $device->ips([{netMask => "32", ipAddress=>"10.0.0.1"}]); # Change IP address! Overlap check is enforced!
1026 $device->id(0); # Required for new device!
1027  
1028 my $device2 = $acs->devices("name","Alt_Router");
1029 $device2->name("AltRouter"); # Required field
1030 $device2->description("Standby Router");
1031 $device2->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # Change IP address! Overlap check is enforced!
1032 $device2->id(0); # Required for new device!
1033
1034 my $id = $acs->create($device,$device2);
1035 # Create new device based on Net::Cisco::ACS::Device instance
1036 # Return value is ID generated by ACS but not guaranteed.
1037 # print "Record ID is $id" if $id;
1038 # print $Net::Cisco::ACS::ERROR unless $id;
1039 # $Net::Cisco::ACS::ERROR contains details about failure
1040
1041 =item update
1042  
1043 This method updates an existing entry in Cisco ACS, depending on the argument passed. Record type is detected automatically.
1044  
1045 my $user = $acs->users("name","acsadmin");
1046 $user->password("TopSecret"); # Change password. Password policies will be enforced!
1047 my $id = $acs->update($user);
1048 # Update user based on Net::Cisco::ACS::User instance
1049 # Return value is ID generated by ACS
1050 print "Record ID is $id" if $id;
1051 print $Net::Cisco::ACS::ERROR unless $id;
1052 # $Net::Cisco::ACS::ERROR contains details about failure
1053  
1054 my $device = $acs->devices("name","Main_Router");
1055 $user->description("To be ceased"); # Change description
1056 $device->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # or Change IP address. Overlap check is enforced!
1057 my $id = $acs->update($device);
1058 # Create new device based on Net::Cisco::ACS::Device instance
1059 # Return value is ID generated by ACS
1060 print "Record ID is $id" if $id;
1061 print $Net::Cisco::ACS::ERROR unless $id;
1062 # $Net::Cisco::ACS::ERROR contains details about failure
1063  
1064 Multiple instances can be passed as an argument. Objects will be updated in bulk (one transaction). The returned ID is not guaranteed to be the IDs of the created objects.
1065  
1066 my $user = $acs->users("name","acsadmin");
1067 $user->id(0); # Required for new user!
1068 $user->password("TopSecret"); # Password policies will be enforced!
1069  
1070 my $user2 = $acs->users("name","acsadmin2");
1071 $user2->password("TopSecret"); # Password policies will be enforced!
1072  
1073 my $id = $acs->update($user,$user2);
1074 # Update users based on Net::Cisco::ACS::User instances in arguments
1075 # Return value is ID generated by ACS but not guaranteed.
1076 # print "Record ID is $id" if $id;
1077 # print $Net::Cisco::ACS::ERROR unless $id;
1078 # $Net::Cisco::ACS::ERROR contains details about failure
1079  
1080 my $device = $acs->devices("name","Main_Router");
1081 $device->description("Main Router");
1082 $device->ips([{netMask => "32", ipAddress=>"10.0.0.1"}]); # Change IP address! Overlap check is enforced!
1083  
1084 my $device2 = $acs->devices("name","Alt_Router");
1085 $device2->description("Standby Router");
1086 $device2->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # Change IP address! Overlap check is enforced!
1087
1088 my $id = $acs->create($device,$device2);
1089 # Update devices based on Net::Cisco::ACS::Device instances in arguments
1090 # Return value is ID generated by ACS but not guaranteed.
1091 # print "Record ID is $id" if $id;
1092 # print $Net::Cisco::ACS::ERROR unless $id;
1093 # $Net::Cisco::ACS::ERROR contains details about failure
1094
1095 =item delete
1096  
1097 This method deletes an existing entry in Cisco ACS, depending on the argument passed. Record type is detected automatically.
1098  
1099 my $user = $acs->users("name","acsadmin");
1100 $acs->delete($user);
1101  
1102 my $device = $acs->users("name","Main_Router");
1103 $acs->delete($device);
1104  
1105 =item $ERROR
1106  
1107 This variable will contain detailed error information, based on the REST API answer. This value is reset during every call to C<users>, C<devices> and C<devicegroups>.
1108
1109 =back
1110  
1111 =head1 REQUIREMENTS
1112  
1113 For this library to work, you need an instance with Cisco ACS (obviously) or a simulator like L<Net::Cisco::ACS::Mock>.
1114  
1115 To enable the Cisco ACS REST API, you will need to run the command below from the Cisco ACS console:
1116  
1117 acs config-web-interface rest enable
1118  
1119 You will also need an administrator-role account, typically NOT associated with a device-access account. Configure the account through the GUI.
1120  
1121 System Administration > Administrators > Accounts
1122  
1123 You will need more than generic privileges (SuperAdmin is ideal, suspected that UserAdmin and NetworkDeviceAdmin are sufficient).
1124  
1125 You will also need
1126  
1127 =over 3
1128  
1129 =item L<Moose>
1130  
1131 =item L<IO::Socket::SSL>
1132  
1133 =item L<LWP::UserAgent>
1134  
1135 =item L<XML::Simple>
1136  
1137 =item L<MIME::Base64>
1138  
1139 =item L<URI::Escape>
1140  
1141 =back
1142
1143 =head1 BUGS
1144  
1145 None so far
1146  
1147 =head1 SUPPORT
1148  
1149 None so far :)
1150  
1151 =head1 AUTHOR
1152  
1153 Hendrik Van Belleghem
1154 CPAN ID: BEATNIK
1155 hendrik.vanbelleghem@gmail.com
1156  
1157 =head1 COPYRIGHT
1158  
1159 This program is free software licensed under the...
1160  
1161 The General Public License (GPL)
1162 Version 2, June 1991
1163  
1164 The full text of the license can be found in the
1165 LICENSE file included with this module.
1166  
1167 =head1 COMPATIBILITY
1168  
1169 Certain API calls are not support from Cisco ACS 5.0 onwards. The current supported versions of Cisco ACS (by Cisco) are 5.6, 5.7 and 5.8 (Active).
1170  
1171 =head1 SEE ALSO
1172  
1173 =over 3
1174  
1175 See L<Net::Cisco::ACS::User> for more information on User management.
1176  
1177 See L<Net::Cisco::ACS::IdentityGroup> for more information on User Group management.
1178  
1179 See L<Net::Cisco::ACS::Device> for more information on Device management.
1180  
1181 See L<Net::Cisco::ACS::DeviceGroup> for more information on Device Group management.
1182  
1183 See L<Net::Cisco::ACS::Host> for more information on Host management.
1184  
1185 See the L<Cisco ACS product page|http://www.cisco.com/c/en/us/products/security/secure-access-control-system/index.html> for more information.
1186  
1187 L<Net::Cisco::ACS> relies on L<Moose>.
1188  
1189 =back
1190  
1191 =cut
1192  
1193 #################### main pod documentation end ###################
1194  
1195 1 __PACKAGE__->meta->make_immutable();
1196  
1197 1 1;
1198 # The preceding line will help the module return a true value
1199  
↑ Summary blib/lib/Net/Cisco/ACS/Device.pm »