blib/lib/Net/Cisco/ACS.pm

filter: Statementstmt 14.0% 60 / 426 Branchbran 0.0% 0 / 160 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 / 642 CC 89 SCAR 54.0
CC
89
Cov
10%
query
552.0
parse_xml
420.0
update
156.0
CRAP 221.1
↑ 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.02';
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 warn Dumper $result->content;
265 0 ▶ if ($result->code eq "400") { $ERROR = "Bad Request - HTTP Status: 400"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code eq 400) 0 0 0
266 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
267 0 $self->parse_xml($mode, $result->content);
268 }
269  
270 sub create
271 0 ▶{ my $self = shift;
Subroutine create: not called CC=9 SCAR=45.0
Pod documented
272 0 my $record = shift;
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 $type = "";
280
281 0 ▶ if (ref($record) eq "ARRAY") { $record = $record->[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "ARRAY") 0 0 0
282 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
283 0 { $action = $Net::Cisco::ACS::User::actions{"create"};
284 0 $type = "User";
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 0 $type = "IdentityGroup";
290 }
291
292 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
293 0 { $action = $Net::Cisco::ACS::Device::actions{"create"};
294 0 $type = "DeviceGroup";
295 }
296
297 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
298 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"create"};
299 0 $type = "DeviceGroup";
300 }
301  
302 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
303 0 { $action = $Net::Cisco::ACS::Host::actions{"create"};
304 0 $type = "Host";
305 }
306
307 0 my $data = $record->header($record->toXML);
308 0 $hostname = $hostname . $action;
309 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
310 0 my $request = HTTP::Request->new(POST => $hostname );
311 0 $request->content_type("application/xml");
312 0 $request->header("Authorization" => "Basic $credentials");
313 0 $request->content($data);
314 0 my $result = $useragent->request($request);
315 0 my $result_ref = $self->parse_xml("result", $result->content);
316 0 my $id = "";
317 0 ▶ if ($result->code ne "200")
Branch: 1 branch
BranchTrueFalseTotal
if ($result->code ne '200') { } 0 0 0
318 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
319 } else
320 0 { $id = $result_ref->{"newBornId"}; }
321 0 return $id;
322 }
323  
324 sub update
325 0 ▶{ my $self = shift;
Subroutine update: not called CC=12 SCAR=50.5
Pod documented
326 0 my $record = shift;
327 0 my $hostname = $self->hostname;
328 0 my $credentials = encode_base64($self->username.":".$self->password);
329 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
330 0 { $hostname = "https://$hostname"; } else
331 0 { $hostname = "http://$hostname"; }
332 0 my $action = "";
333 0 my $type = "";
334
335 0 ▶ if (ref($record) eq "ARRAY") { $record = $record->[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "ARRAY") 0 0 0
336 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
337 0 { $action = $Net::Cisco::ACS::User::actions{"update"};
338 0 $type = "User";
339 }
340 0 ▶ if (ref($record) eq "Net::Cisco::ACS::IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::IdentityGroup") 0 0 0
341 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"update"};
342 0 $type = "IdentityGroup";
343 }
344 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
345 0 { $action = $Net::Cisco::ACS::Device::actions{"update"};
346 0 $type = "Device";
347 }
348 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
349 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"update"};
350 0 $type = "DeviceGroup";
351 }
352  
353 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
354 0 { $action = $Net::Cisco::ACS::Host::actions{"update"};
355 0 $type = "Host";
356 }
357  
358 0 my $data = $record->header($record->toXML);
359 0 $hostname = $hostname . $action;
360 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
361 0 my $request = HTTP::Request->new(PUT => $hostname );
362 0 $request->content_type("application/xml");
363 0 $request->header("Authorization" => "Basic $credentials");
364 0 $request->content($data);
365 0 my $result = $useragent->request($request);
366 0 my $result_ref = undef;
367 0 ▶ $result_ref = $self->parse_xml("result", $result->content) if $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $result_ref 0 0 0
368 0 ▶ $result_ref = {} unless $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $result_ref 0 0 0
369 0 my $id = "";
370 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
371 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
372 } else
373 0 { $id = $result_ref->{"newBornId"}; }
374 0 return $id;
375 }
376  
377 sub delete
378 0 ▶{ my $self = shift;
Subroutine delete: not called CC=12 SCAR=50.5
Pod documented
379 0 my $record = shift;
380 0 my $hostname = $self->hostname;
381 0 my $credentials = encode_base64($self->username.":".$self->password);
382 0 ▶ if ($self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ssl) { } 0 0 0
383 0 { $hostname = "https://$hostname"; } else
384 0 { $hostname = "http://$hostname"; }
385 0 my $action = "";
386 0 my $type = "";
387
388 0 ▶ if (ref($record) eq "ARRAY") { $record = $record->[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "ARRAY") 0 0 0
389 0 ▶ if (ref($record) eq "Net::Cisco::ACS::User")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::User") 0 0 0
390 0 { $action = $Net::Cisco::ACS::User::actions{"getById"};
391 0 $type = "User";
392 }
393  
394 0 ▶ if (ref($record) eq "Net::Cisco::ACS::IdentityGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::IdentityGroup") 0 0 0
395 0 { $action = $Net::Cisco::ACS::IdentityGroup::actions{"getById"};
396 0 $type = "IdentityGroup";
397 }
398
399 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Device")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Device") 0 0 0
400 0 { $action = $Net::Cisco::ACS::Device::actions{"getById"};
401 0 $type = "Device";
402 }
403
404 0 ▶ if (ref($record) eq "Net::Cisco::ACS::DeviceGroup")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::DeviceGroup") 0 0 0
405 0 { $action = $Net::Cisco::ACS::DeviceGroup::actions{"getById"};
406 0 $type = "DeviceGroup";
407 }
408  
409 0 ▶ if (ref($record) eq "Net::Cisco::ACS::Host")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $record eq "Net::Cisco::ACS::Host") 0 0 0
410 0 { $action = $Net::Cisco::ACS::Host::actions{"getById"};
411 0 $type = "Host";
412 }
413
414 0 my $data = $record->header($record->toXML);
415 0 $hostname = $hostname . $action.$record->id;
416 0 my $useragent = LWP::UserAgent->new (ssl_opts => $self->ssl_options);
417 0 my $request = HTTP::Request->new(DELETE => $hostname );
418 0 $request->content_type("application/xml");
419 0 $request->header("Authorization" => "Basic $credentials");
420 0 $request->content($data);
421 0 my $result = $useragent->request($request);
422 0 my $result_ref = undef;
423 0 ▶ $result_ref = $self->parse_xml("result", $result->content) if $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $result_ref 0 0 0
424 0 ▶ $result_ref = {} unless $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $result_ref 0 0 0
425 0 my $id = "";
426 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
427 0 { $ERROR = $result_ref->{"errorCode"}." ".$result_ref->{"moreErrInfo"}." - HTTP Status: ".$result_ref->{"httpCode"};
428 }
429 }
430  
431 sub parse_xml
432 0 ▶{ my $self = shift;
Subroutine parse_xml: not called CC=20 SCAR=60.4
Pod undocumented
433 0 my $type = shift;
434 0 my $xml_ref = shift;
435 0 my $xmlsimple = XML::Simple->new();
436 0 my $xmlout = $xmlsimple->XMLin($xml_ref);
437 0 ▶ if ($type eq "Users")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Users") 0 0 0
438 0 { my $users_ref = $xmlout->{"User"};
439 0 my %users = ();
440 0 for my $key (keys % {$users_ref})
441 0 { my $user = Net::Cisco::ACS::User->new( name => $key, %{ $users_ref->{$key} } );
442 0 $users{$key} = $user;
443 }
444 0 $self->{"Users"} = \%users;
445 0 return $self->{"Users"};
446 }
447 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
448 0 { my %user_hash = %{ $xmlout };
449 0 my $user = Net::Cisco::ACS::User->new( %user_hash );
450 0 $self->{"Users"} = $user ;
451 0 return $self->{"Users"};
452 }
453  
454 0 ▶ if ($type eq "IdentityGroups")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "IdentityGroups") 0 0 0
455 0 { my $identitygroups_ref = $xmlout->{"IdentityGroup"};
456 0 my %identitygroups = ();
457 0 for my $key (keys % {$identitygroups_ref})
458 0 { my $identitygroup = Net::Cisco::ACS::IdentityGroup->new( name => $key, %{ $identitygroups_ref->{$key} } );
459 0 $identitygroups{$key} = $identitygroup;
460 }
461 0 $self->{"IdentityGroups"} = \%identitygroups;
462 0 return $self->{"IdentityGroups"};
463 }
464 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
465 0 { my %identitygroup_hash = %{ $xmlout };
466 0 my $identitygroup = Net::Cisco::ACS::IdentityGroup->new( %identitygroup_hash );
467 0 $self->{"IdentityGroups"} = $identitygroup;
468 0 return $self->{"IdentityGroups"};
469 }
470
471 0 ▶ if ($type eq "Devices")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Devices") 0 0 0
472 0 { my $device_ref = $xmlout->{"Device"};
473 0 my %devices = ();
474 0 for my $key (keys % {$device_ref})
475 0 { my $device = Net::Cisco::ACS::Device->new( name => $key, %{ $device_ref->{$key} } );
476 0 $devices{$key} = $device;
477 }
478 0 $self->{"Devices"} = \%devices;
479 0 return $self->{"Devices"};
480 }
481 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
482 0 { my %device_hash = %{ $xmlout };
483 0 my $device = Net::Cisco::ACS::Device->new( %device_hash );
484 0 $self->{"Devices"} = $device;
485 0 return $self->{"Devices"};
486 }
487  
488 0 ▶ if ($type eq "DeviceGroups")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "DeviceGroups") 0 0 0
489 0 { my $devicegroup_ref = $xmlout->{"DeviceGroup"};
490 0 my %devicegroups = ();
491 0 for my $key (keys % {$devicegroup_ref})
492 0 { my $devicegroup = Net::Cisco::ACS::DeviceGroup->new( name => $key, %{ $devicegroup_ref->{$key} } );
493 0 $devicegroups{$key} = $devicegroup;
494 }
495 0 $self->{"DeviceGroups"} = \%devicegroups;
496 0 return $self->{"DeviceGroups"};
497 }
498 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
499 0 { my %devicegroup_hash = %{ $xmlout };
500 0 my $devicegroup = Net::Cisco::ACS::DeviceGroup->new( %devicegroup_hash );
501 0 $self->{"DeviceGroups"} = $devicegroup;
502 0 return $self->{"DeviceGroups"};
503 }
504
505 0 ▶ if ($type eq "Hosts")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Hosts") 0 0 0
506 0 { my $host_ref = $xmlout->{"Host"};
507 0 my %hosts = ();
508 0 for my $key (keys % {$host_ref})
509 0 { my $host = Net::Cisco::ACS::Host->new( macAddress => $key, %{ $host_ref->{$key} } );
510 0 $hosts{$key} = $host;
511 }
512 0 $self->{"Hosts"} = \%hosts;
513 0 return $self->{"Hosts"};
514 }
515 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
516 0 { my %host_hash = %{ $xmlout };
517 0 my $host = Net::Cisco::ACS::Host->new( %host_hash );
518 0 $self->{"Hosts"} = $host;
519 0 return $self->{"Hosts"};
520 }
521
522 0 ▶ if ($type eq "result")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "result") 0 0 0
523 0 { my %result_hash = %{ $xmlout };
524 0 return \%result_hash;
525 }
526 0 ▶ if ($type eq "Version")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Version") 0 0 0
527 0 { my %version_hash = %{ $xmlout };
528 0 return \%version_hash;
529 }
530 0 ▶ if ($type eq "ServiceLocation")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ServiceLocation") 0 0 0
531 0 { my %servicelocation_hash = %{ $xmlout };
532 0 return \%servicelocation_hash;
533 }
534 0 ▶ if ($type eq "ErrorMessage")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "ErrorMessage") 0 0 0
535 0 { my %errormessage_hash = %{ $xmlout };
536 0 return \%errormessage_hash;
537 }
538  
539 }
540  
541 =head1 NAME
542  
543 Net::Cisco::ACS - Access Cisco ACS functionality through REST API
544  
545 =head1 SYNOPSIS
546  
547 use Net::Cisco::ACS;
548 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
549 # Options:
550 # hostname - IP or hostname of Cisco ACS 5.x server
551 # username - Username of Administrator user
552 # password - Password of user
553 # ssl - SSL enabled (1 - default) or disabled (0)
554
555 my %users = $acs->users;
556 # Retrieve all users from ACS
557 # Returns hash with username / Net::Cisco::ACS::User pairs
558
559 print $acs->users->{"acsadmin"}->toXML;
560 # Dump in XML format (used by ACS for API calls)
561
562 my $user = $acs->users("name","acsadmin");
563 # Faster call to request specific user information by name
564  
565 my $user = $acs->users("id","150");
566 # Faster call to request specific user information by ID (assigned by ACS, present in Net::Cisco::ACS::User)
567  
568 my %identitygroups = $acs->identitygroups;
569 # Retrieve all identitygroups from ACS
570 # Returns hash with name / Net::Cisco::ACS::IdentityGroup pairs
571
572 print $acs->identitygroups->{"All Groups"}->toXML;
573 # Dump in XML format (used by ACS for API calls)
574
575 my $identitygroup = $acs->identitygroups("name","All Groups");
576 # Faster call to request specific identity group information by name
577  
578 my $identitygroup = $acs->identitygroups("id","150");
579 # Faster call to request specific identity group information by ID (assigned by ACS, present in Net::Cisco::ACS::IdentityGroup)
580
581 my %devices = $acs->devices;
582 # Retrieve all devices from ACS
583 # Returns hash with device name / Net::Cisco::ACS::Device pairs
584  
585 print $acs->devices->{"MAIN_Router"}->toXML;
586 # Dump in XML format (used by ACS for API calls)
587
588 my $device = $acs->devices("name","MAIN_Router");
589 # Faster call to request specific device information by name
590  
591 my $device = $acs->devices("id","250");
592 # Faster call to request specific device information by ID (assigned by ACS, present in Net::Cisco::ACS::Device)
593  
594 my %devicegroups = $acs->devicegroups;
595 # Retrieve all device groups from ACS
596 # Returns hash with device name / Net::Cisco::ACS::DeviceGroup pairs
597  
598 print $acs->devicegroups->{"All Locations"}->toXML;
599 # Dump in XML format (used by ACS for API calls)
600
601 my $device = $acs->devicegroups("name","All Locations");
602 # Faster call to request specific device group information by name
603  
604 my $devicegroup = $acs->devicegroups("id","250");
605 # Faster call to request specific device group information by ID (assigned by ACS, present in Net::Cisco::ACS::DeviceGroup)
606  
607 my %hosts = $acs->hosts;
608 # Retrieve all hosts from ACS
609 # Returns hash with host name / Net::Cisco::ACS::Host pairs
610  
611 print $acs->hosts->{"1234"}->toXML;
612 # Dump in XML format (used by ACS for API calls)
613
614 my $host = $acs->hosts("name","1234");
615 # Faster call to request specific host information by name
616  
617 my $host = $acs->hosts("id","250");
618 # Faster call to request specific hosts information by ID (assigned by ACS, present in Net::Cisco::ACS::Host)
619
620 $user->id(0); # Required for new user!
621 my $id = $acs->create($user);
622 # Create new user based on Net::Cisco::ACS::User instance
623 # Return value is ID generated by ACS
624 print "Record ID is $id" if $id;
625 print $Net::Cisco::ACS::ERROR unless $id;
626 # $Net::Cisco::ACS::ERROR contains details about failure
627  
628 $identitygroup->id(0); # Required for new record!
629 my $id = $acs->create($identitygroup);
630 # Create new identity group based on Net::Cisco::ACS::IdentityGroup instance
631 # Return value is ID generated by ACS
632 print "Record ID is $id" if $id;
633 print $Net::Cisco::ACS::ERROR unless $id;
634 # $Net::Cisco::ACS::ERROR contains details about failure
635
636 $device->id(0); # Required for new device!
637 my $id = $acs->create($device);
638 # Create new device based on Net::Cisco::ACS::Device instance
639 # Return value is ID generated by ACS
640 print "Record ID is $id" if $id;
641 print $Net::Cisco::ACS::ERROR unless $id;
642 # $Net::Cisco::ACS::ERROR contains details about failure
643  
644 $devicegroup->id(0); # Required for new device group!
645 my $id = $acs->create($devicegroup);
646 # Create new device group based on Net::Cisco::ACS::DeviceGroup instance
647 # Return value is ID generated by ACS
648 print "Record ID is $id" if $id;
649 print $Net::Cisco::ACS::ERROR unless $id;
650 # $Net::Cisco::ACS::ERROR contains details about failure
651  
652 $host->id(0); # Required for new host!
653 my $id = $acs->create($host);
654 # Create new host based on Net::Cisco::ACS::Host instance
655 # Return value is ID generated by ACS
656 print "Record ID is $id" if $id;
657 print $Net::Cisco::ACS::ERROR unless $id;
658 # $Net::Cisco::ACS::ERROR contains details about failure
659
660 my $id = $acs->update($user);
661 # Update existing user based on Net::Cisco::ACS::User instance
662 # Return value is ID generated by ACS
663 print "Record ID is $id" if $id;
664 print $Net::Cisco::ACS::ERROR unless $id;
665 # $Net::Cisco::ACS::ERROR contains details about failure
666  
667 my $id = $acs->update($identitygroup);
668 # Update existing identitygroup based on Net::Cisco::ACS::IdentityGroup instance
669 # Return value is ID generated by ACS
670 print "Record ID is $id" if $id;
671 print $Net::Cisco::ACS::ERROR unless $id;
672 # $Net::Cisco::ACS::ERROR contains details about failure
673
674 my $id = $acs->update($device);
675 # Update existing device based on Net::Cisco::ACS::Device instance
676 # Return value is ID generated by ACS
677 print "Record ID is $id" if $id;
678 print $Net::Cisco::ACS::ERROR unless $id;
679 # $Net::Cisco::ACS::ERROR contains details about failure
680  
681 my $id = $acs->update($devicegroup);
682 # Update existing device based on Net::Cisco::ACS::DeviceGroup instance
683 # Return value is ID generated by ACS
684 print "Record ID is $id" if $id;
685 print $Net::Cisco::ACS::ERROR unless $id;
686 # $Net::Cisco::ACS::ERROR contains details about failure
687  
688 my $id = $acs->update($host);
689 # Update existing device based on Net::Cisco::ACS::Host instance
690 # Return value is ID generated by ACS
691 print "Record ID is $id" if $id;
692 print $Net::Cisco::ACS::ERROR unless $id;
693 # $Net::Cisco::ACS::ERROR contains details about failure
694  
695 $acs->delete($user);
696 # Delete existing user based on Net::Cisco::ACS::User instance
697  
698 $acs->delete($identitygroup);
699 # Delete existing identity group based on Net::Cisco::ACS::IdentityGroup instance
700
701 $acs->delete($device);
702 # Delete existing device based on Net::Cisco::ACS::Device instance
703  
704 $acs->delete($devicegroup);
705 # Delete existing device based on Net::Cisco::ACS::DeviceGroup instance
706  
707 $acs->delete($host);
708 # Delete existing host based on Net::Cisco::ACS::Host instance
709
710 $acs->version
711 # Return version information for the connected server *HASHREF*
712  
713 $acs->serviceLocation
714 # Return ACS instance that serves as primary and the ACS instance that provide Monitoring and Troubleshooting Viewer. *HASHREF*
715
716 $acs->errorMessage
717 # Return all ACS message codes and message texts that are used on the REST Interface. *HASHREF*
718  
719
720 =head1 DESCRIPTION
721  
722 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.
723  
724 =head1 USAGE
725  
726 All calls are handled through an instance of the L<Net::Cisco::ACS> class.
727  
728 use Net::Cisco::ACS;
729 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
730  
731 =over 3
732  
733 =item new
734  
735 Class constructor. Returns object of Net::Cisco::ACS on succes. Required fields are:
736  
737 =over 5
738  
739 =item hostname
740  
741 =item username
742  
743 =password
744  
745 =back
746  
747 Optional fields are
748  
749 =over 5
750  
751 =item ssl
752  
753 =item ssl_options
754  
755 =back
756  
757 =item hostname
758  
759 IP or hostname of Cisco ACS 5.x server. This is a required value in the constructor but can be redefined afterwards.
760  
761 =item username
762  
763 Username of Administrator user. This is a required value in the constructor but can be redefined afterwards.
764  
765 =item password
766  
767 Password of user. This is a required value in the constructor but can be redefined afterwards.
768  
769 =item ssl
770  
771 SSL enabled (1 - default) or disabled (0).
772  
773 =item ssl_options
774  
775 Value is passed directly to LWP::UserAGent as ssl_opt. Default value (hash-ref) is
776  
777 { 'SSL_verify_mode' => SSL_VERIFY_NONE, 'verify_hostname' => '0' }
778  
779 =back
780  
781 From the class instance, call the different methods for retrieving values.
782  
783 =over 3
784  
785 =item users
786  
787 Returns hash or single instance, depending on context.
788  
789 my %users = $acs->users(); # Slow
790 my $user = $acs->users()->{"acsadmin"};
791 print $user->name;
792
793 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.
794
795 my $user = $acs->users("name","acsadmin"); # Faster
796 # or
797 my $user = $acs->users("id","123"); # Faster
798 print $user->name;
799  
800 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.
801  
802 print $user->id;
803  
804 =item identitygroups
805  
806 Returns hash or single instance, depending on context.
807  
808 my %identitygroups = $acs->identitygroups(); # Slow
809 my $identitygroup = $acs->identitygroups()->{"All Groups"};
810 print $identitgroup->name;
811
812 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.
813
814 my $identitygroup = $acs->identitygroups("name","All Groups"); # Faster
815 # or
816 my $identitygroup = $acs->identitygroups("id","123"); # Faster
817 print $identitygroup->name;
818  
819 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.
820  
821 print $identitygroup->id;
822
823 =item devices
824  
825 Returns hash or single instance, depending on context.
826  
827 my %devices = $acs->devices(); # Slow
828 my $device = $acs->devices()->{"Main_Router"};
829 print $device->name;
830
831 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.
832
833 my $device = $acs->device("name","Main_Router"); # Faster
834 # or
835 my $device = $acs->device("id","123"); # Faster
836 print $device->name;
837  
838 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.
839  
840 print $device->id;
841  
842 =item devicegroups
843  
844 Returns hash or single instance, depending on context.
845  
846 my %devicegroups = $acs->devicegroups(); # Slow
847 my $devicegroup = $acs->devicegroups()->{"All Locations:Main Site"};
848 print $devicegroup->name;
849  
850 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.
851
852 my $devicegroup = $acs->devicegroups("name","All Locations::Main Site"); # Faster
853 # or
854 my $devicegroup = $acs->devicegroups("id","123"); # Faster
855 print $devicegroup->name;
856  
857 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.
858  
859 print $devicegroup->id;
860  
861 =item hosts
862  
863 Returns hash or single instance, depending on context.
864  
865 my %hosts = $acs->hosts(); # Slow
866 my $host = $acs->hosts()->{"12345"};
867 print $host->name;
868
869 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.
870
871 my $host = $acs->host("name","12345"); # Faster
872 # or
873 my $host = $acs->device("id","123"); # Faster
874 print $host->name;
875  
876 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.
877  
878 print $host->id;
879
880 =item version
881  
882 This method returns version specific information about the Cisco ACS instance you're connected to. Values are returned in a hash reference.
883  
884 use Data::Dumper;
885 # ...
886 print Dumper $acs->version;
887  
888 =item servicelocation
889  
890 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.
891  
892 use Data::Dumper;
893 # ...
894 print Dumper $acs->servicelocation;
895  
896 =item errormessage
897  
898 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>.
899  
900 use Data::Dumper;
901 # ...
902 print Dumper $acs->errormessage;
903  
904 =item create
905  
906 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.
907  
908 my $user = $acs->users("name","acsadmin");
909 $user->id(0); # Required for new user!
910 $user->name("altadmin"); # Required field
911 $user->password("TopSecret"); # Password policies will be enforced!
912 $user->description("Alternate Admin");
913 my $id = $acs->create($user);
914 # Create new user based on Net::Cisco::ACS::User instance
915 # Return value is ID generated by ACS
916 print "Record ID is $id" if $id;
917 print $Net::Cisco::ACS::ERROR unless $id;
918 # $Net::Cisco::ACS::ERROR contains details about failure
919  
920 my $device = $acs->devices("name","Main_Router");
921 $device->name("AltRouter"); # Required field
922 $device->description("Standby Router");
923 $device->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # Change IP address! Overlap check is enforced!
924 $device->id(0); # Required for new device!
925 my $id = $acs->create($device);
926 # Create new device based on Net::Cisco::ACS::Device instance
927 # Return value is ID generated by ACS
928 print "Record ID is $id" if $id;
929 print $Net::Cisco::ACS::ERROR unless $id;
930 # $Net::Cisco::ACS::ERROR contains details about failure
931  
932 =item update
933  
934 This method updates an existing entry in Cisco ACS, depending on the argument passed. Record type is detected automatically.
935  
936 my $user = $acs->users("name","acsadmin");
937 $user->password("TopSecret"); # Change password. Password policies will be enforced!
938 my $id = $acs->update($user);
939 # Update user based on Net::Cisco::ACS::User instance
940 # Return value is ID generated by ACS
941 print "Record ID is $id" if $id;
942 print $Net::Cisco::ACS::ERROR unless $id;
943 # $Net::Cisco::ACS::ERROR contains details about failure
944  
945 my $device = $acs->devices("name","Main_Router");
946 $user->description("To be ceased"); # Change description
947 $device->ips([{netMask => "32", ipAddress=>"10.0.0.2"}]); # or Change IP address. Overlap check is enforced!
948 my $id = $acs->update($device);
949 # Create new device based on Net::Cisco::ACS::Device instance
950 # Return value is ID generated by ACS
951 print "Record ID is $id" if $id;
952 print $Net::Cisco::ACS::ERROR unless $id;
953 # $Net::Cisco::ACS::ERROR contains details about failure
954  
955 =item delete
956  
957 This method deletes an existing entry in Cisco ACS, depending on the argument passed. Record type is detected automatically.
958  
959 my $user = $acs->users("name","acsadmin");
960 $acs->delete($user);
961  
962 my $device = $acs->users("name","Main_Router");
963 $acs->delete($device);
964  
965 =item $ERROR
966  
967 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>.
968
969 =back
970  
971 =head1 REQUIREMENTS
972  
973 For this library to work, you need an instance with Cisco ACS (obviously) or a simulator like L<Net::Cisco::ACS::Mock>.
974  
975 To enable the Cisco ACS REST API, you will need to run the command below from the Cisco ACS console:
976  
977 acs config-web-interface rest enable
978  
979 You will also need an administrator-role account, typically NOT associated with a device-access account. Configure the account through the GUI.
980  
981 System Administration > Administrators > Accounts
982  
983 You will need more than generic privileges (SuperAdmin is ideal, suspected that UserAdmin and NetworkDeviceAdmin are sufficient).
984  
985 You will also need
986  
987 =over 3
988  
989 =item L<Moose>
990  
991 =item L<IO::Socket::SSL>
992  
993 =item L<LWP::UserAgent>
994  
995 =item L<XML::Simple>
996  
997 =item L<MIME::Base64>
998  
999 =item L<URI::Escape>
1000  
1001 =back
1002
1003 =head1 BUGS
1004  
1005 None so far
1006  
1007 =head1 SUPPORT
1008  
1009 None so far :)
1010  
1011 =head1 AUTHOR
1012  
1013 Hendrik Van Belleghem
1014 CPAN ID: BEATNIK
1015 hendrik.vanbelleghem@gmail.com
1016  
1017 =head1 COPYRIGHT
1018  
1019 This program is free software licensed under the...
1020  
1021 The General Public License (GPL)
1022 Version 2, June 1991
1023  
1024 The full text of the license can be found in the
1025 LICENSE file included with this module.
1026  
1027 =head1 COMPATIBILITY
1028  
1029 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).
1030  
1031 =head1 SEE ALSO
1032  
1033 =over 3
1034  
1035 See L<Net::Cisco::ACS::User> for more information on User management.
1036  
1037 See L<Net::Cisco::ACS::IdentityGroup> for more information on User Group management.
1038  
1039 See L<Net::Cisco::ACS::Device> for more information on Device management.
1040  
1041 See L<Net::Cisco::ACS::DeviceGroup> for more information on Device Group management.
1042  
1043 See L<Net::Cisco::ACS::Host> for more information on Host management.
1044  
1045 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.
1046  
1047 L<Net::Cisco::ACS> relies on L<Moose>.
1048  
1049 =back
1050  
1051 =cut
1052  
1053 #################### main pod documentation end ###################
1054  
1055 1 __PACKAGE__->meta->make_immutable();
1056  
1057 1 1;
1058 # The preceding line will help the module return a true value
1059  
↑ Summary blib/lib/Net/Cisco/ACS/Device.pm »