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
« ACS/User.pm ↑ Summary 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 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %actions);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $VERSION = '0.03';
10 1 @ISA = qw(Exporter);
11 1 @EXPORT = qw();
12 1 @EXPORT_OK = qw();
13 1 %EXPORT_TAGS = ();
14 };
15  
16 1 %actions = ( "query" => "/Rest/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  
159 =item enabled
160  
161 =item identityGroupName
162  
163 =item macAddress
164  
165 =item id
166  
167 Formatting rules may be in place & enforced by Cisco ACS.
168  
169 =back
170  
171 Read-only values:
172  
173 =over 5
174  
175 =item created
176  
177 =item lastModified
178  
179 =item lastEnabled
180  
181 =back
182  
183 =over 3
184  
185 =item description
186  
187 The host description, typically used for host name. This is the only text-field for this record type.
188  
189 =item enabled
190  
191 Boolean flag to indicate record status.
192  
193 =item macAddress
194  
195 MAC Address for host. Used for actual identification.
196  
197 =item id
198  
199 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.
200  
201 =item toXML
202  
203 Dump the record in ACS accept XML formatting (without header).
204  
205 =item header
206  
207 Generate the correct XML header. Takes output of C<toXML> as argument.
208  
209 =back
210  
211 =back
212  
213 =head1 BUGS
214  
215 None yet
216  
217 =head1 SUPPORT
218  
219 None yet :)
220  
221 =head1 AUTHOR
222  
223 Hendrik Van Belleghem
224 CPAN ID: BEATNIK
225 hendrik.vanbelleghem@gmail.com
226  
227 =head1 COPYRIGHT
228  
229 This program is free software licensed under the...
230  
231 The General Public License (GPL)
232 Version 2, June 1991
233  
234 The full text of the license can be found in the
235 LICENSE file included with this module.
236  
237  
238 =head1 SEE ALSO
239  
240 perl(1).
241  
242 =cut
243  
244 #################### main pod documentation end ###################
245 1 __PACKAGE__->meta->make_immutable();
246  
247 1 1;
248 # The preceding line will help the module return a true value
249  
« ACS/User.pm ↑ Summary ACS/DeviceGroup.pm »