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

filter: Statementstmt 65.9% 31 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 50.6% 39 / 77 CC 8 SCAR 36.6
CC
8
Cov
51%
toXML
72.0
header
2.0
BEGIN
1.0
CRAP 38.9
« blib/lib/Net/Cisco/ACS/User.pm ↑ Summary blib/lib/Net/Cisco/ACS/DeviceGroup.pm »
1 package Net::Cisco::ACS::Host;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 BEGIN {
7 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %actions);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ $VERSION = '0.02';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 @ISA = qw(Exporter);
11 1 @EXPORT = qw();
12 1 @EXPORT_OK = qw();
13 1 %EXPORT_TAGS = ();
14 };
15  
16 1 %actions = ( "query" => "/Rest/Identity/Host",
17 "create" => "/Rest/Identity/Host",
18 "update" => "/Rest/Identity/Host",
19 "getByName" => "/Rest/Identity/Host/name/",
20 "getById" => "/Rest/Identity/Host/id/",
21 );
22  
23 # MOOSE!
24
25 1 has 'description' => (
26 is => 'rw',
27 isa => 'Any',
28 );
29  
30 1 has 'id' => (
31 is => 'rw',
32 isa => 'Str',
33 );
34  
35 1 has 'identityGroupName' => (
36 is => 'rw',
37 isa => 'Str',
38 );
39
40 1 has 'created' => (
41 is => 'rw',
42 isa => 'Str',
43 );
44  
45 1 has 'enabled' => (
46 is => 'rw',
47 isa => 'Str',
48 );
49
50 1 has 'lastEnabled' => (
51 is => 'rw',
52 isa => 'Str',
53 );
54  
55 1 has 'lastModified' => (
56 is => 'rw',
57 isa => 'Str',
58 );
59  
60 1 has 'macAddress' => ( # Not sure if query for Host can be done on MAC Address or on 'name' getByName vs getByMacAddress??!?
61 is => 'rw',
62 isa => 'Str',
63 );
64
65 # No Moose
66  
67 sub toXML
68 0 ▶{ my $self = shift;
Subroutine toXML: not called CC=8 SCAR=42.8
Pod documented
69 0 my $result = "";
70 0 my $id = $self->id;
71 0 ▶ my $description = $self->description || "";
Condition0%0/2
$self->description || ''
l!l
00
MC/DC0%0/1
$self->description || ''
$self->description
Truth table0%0/2
A
A= $self->description
Aresult
11
00
72 0 ▶ my $identitygroupname = $self->identityGroupName || "All Groups";
Condition0%0/2
$self->identityGroupName || 'All Groups'
l!l
00
MC/DC0%0/1
$self->identityGroupName || 'All Groups'
$self->identityGroupName
Truth table0%0/2
A
A= $self->identityGroupName
Aresult
11
00
73 0 ▶ my $enabled = $self->enabled || "true";
Condition0%0/2
$self->enabled || 'true'
l!l
00
MC/DC0%0/1
$self->enabled || 'true'
$self->enabled
Truth table0%0/2
A
A= $self->enabled
Aresult
11
00
74 0 ▶ my $lastenabled = $self->lastEnabled || "";
Condition0%0/2
$self->lastEnabled || ''
l!l
00
MC/DC0%0/1
$self->lastEnabled || ''
$self->lastEnabled
Truth table0%0/2
A
A= $self->lastEnabled
Aresult
11
00
75 0 ▶ my $lastmodified = $self->lastModified || "";
Condition0%0/2
$self->lastModified || ''
l!l
00
MC/DC0%0/1
$self->lastModified || ''
$self->lastModified
Truth table0%0/2
A
A= $self->lastModified
Aresult
11
00
76 0 ▶ my $macaddress = $self->macAddress || "";
Condition0%0/2
$self->macAddress || ''
l!l
00
MC/DC0%0/1
$self->macAddress || ''
$self->macAddress
Truth table0%0/2
A
A= $self->macAddress
Aresult
11
00
77 0 ▶ if ($id) { $result = " <id>$id</id>\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
78 0 $result = <<XML;
79 <description>$description</description>
80 <identityGroupName>$identitygroupname</identityGroupName>
81 <enabled>$enabled</enabled>
82 <macAddress>$macaddress</macAddress>
83 XML
84  
85 0 return $result;
86 }
87  
88 sub header
89 0 ▶{ my $self = shift;
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
90 0 my $hosts = shift;
91 0 return qq(<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:hosts xmlns:ns2="identity.rest.mgmt.acs.nm.cisco.com">$hosts</ns1:hosts>);
92 }
93
94 =head1 NAME
95  
96 Net::Cisco::ACS::Host - Access Cisco ACS functionality through REST API - Host fields
97  
98 =head1 SYNOPSIS
99  
100 use Net::Cisco::ACS;
101 use Net::Cisco::ACS::Host;
102  
103 my $acs = Net::Cisco::ACS->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
104 my $host = Net::Cisco::ACS::Host->new(macAddress=>"00-00-00-00-00-00", "description"=>"R2D2","identityGroupName"=>"All Groups:Droids");
105
106 my %hosts = $acs->hosts;
107 # Retrieve all hosts from ACS
108 # Returns hash with host macAddress / Net::Cisco::ACS::Host pairs
109  
110 print $acs->hosts->{"00-00-00-00-00-00"}->toXML;
111 # Dump in XML format (used by ACS for API calls)
112
113 my $host = $acs->hosts("macAddress","00-00-00-00-00-00");
114 # Faster call to request specific host information by MAC Address. No name field exists.
115  
116 my $host = $acs->hosts("id","250");
117 # Faster call to request specific hosts information by ID (assigned by ACS, present in Net::Cisco::ACS::Host)
118  
119 $host->id(0); # Required for new host!
120 my $id = $acs->create($host);
121 # Create new host based on Net::Cisco::ACS::Host instance
122 # Return value is ID generated by ACS
123 print "Record ID is $id" if $id;
124 print $Net::Cisco::ACS::ERROR unless $id;
125 # $Net::Cisco::ACS::ERROR contains details about failure
126  
127 my $id = $acs->update($host);
128 # Update existing device based on Net::Cisco::ACS::Host instance
129 # Return value is ID generated by ACS
130 print "Record ID is $id" if $id;
131 print $Net::Cisco::ACS::ERROR unless $id;
132 # $Net::Cisco::ACS::ERROR contains details about failure
133  
134 $acs->delete($host);
135 # Delete existing host based on Net::Cisco::ACS::Host instance
136
137 =head1 DESCRIPTION
138  
139 The Net::Cisco::ACS::Host class holds all the Internal Host relevant information from Cisco ACS 5.x. Hosts (in this case) are not to be confused with L<Net::Cisco::ACS::Device>. Hosts are used as an identity item, in case of e.g dot1x configurations.
140  
141 =head1 USAGE
142  
143 The Net::Cisco::ACS::Host class holds all the user relevant information from Cisco ACS 5.x
144  
145 =head1 USAGE
146  
147 All calls are typically handled through an instance of the L<Net::Cisco::ACS> class. L<Net::Cisco::ACS::Host> acts as a container for host identity related information.
148  
149 =over 3
150  
151 =item new
152  
153 Class constructor. Returns object of L<Net::Cisco::ACS::Host> on succes. The following fields can be set / retrieved:
154  
155 =over 5
156  
157 =item description
158 =item enabled
159 =item identityGroupName
160 =item macAddress
161 =item id
162  
163 Formatting rules may be in place & enforced by Cisco ACS.
164  
165 =back
166  
167 Read-only values:
168  
169 =over 5
170  
171 =item created
172 =item lastModified
173 =item lastEnabled
174  
175 =back
176  
177 =over 3
178  
179 =item description
180  
181 The host description, typically used for host name. This is the only text-field for this record type.
182  
183 =item enabled
184  
185 Boolean flag to indicate record status.
186  
187 =item macAddress
188  
189 MAC Address for host. Used for actual identification.
190  
191 =item id
192  
193 Cisco ACS generates a unique ID for each Host record. This field cannot be updated within ACS but is used for reference. Set to 0 when creating a new record or when duplicating an existing host.
194  
195 =item toXML
196  
197 Dump the record in ACS accept XML formatting (without header).
198  
199 =item header
200  
201 Generate the correct XML header. Takes output of C<toXML> as argument.
202  
203 =back
204  
205  
206 =head1 BUGS
207  
208 None yet
209  
210 =head1 SUPPORT
211  
212 None yet :)
213  
214 =head1 AUTHOR
215  
216 Hendrik Van Belleghem
217 CPAN ID: BEATNIK
218 hendrik.vanbelleghem@gmail.com
219  
220 =head1 COPYRIGHT
221  
222 This program is free software licensed under the...
223  
224 The General Public License (GPL)
225 Version 2, June 1991
226  
227 The full text of the license can be found in the
228 LICENSE file included with this module.
229  
230  
231 =head1 SEE ALSO
232  
233 perl(1).
234  
235 =cut
236  
237 #################### main pod documentation end ###################
238 1 __PACKAGE__->meta->make_immutable();
239  
240 1 1;
241 # The preceding line will help the module return a true value
242  
« blib/lib/Net/Cisco/ACS/User.pm ↑ Summary blib/lib/Net/Cisco/ACS/DeviceGroup.pm »