File Coverage

blib/lib/Net/Cisco/ISE/NetworkDeviceGroup.pm
Criterion Covered Total %
statement 20 37 54.0
branch 0 2 0.0
condition 0 12 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 28 61 45.9


line stmt bran cond sub pod time code
1             package Net::Cisco::ISE::NetworkDeviceGroup;
2 1     1   9 use strict;
  1         3  
  1         45  
3 1     1   10 use Moose;
  1         2  
  1         10  
4 1     1   7570 use Data::Dumper;
  1         2  
  1         69  
5              
6             BEGIN {
7 1     1   6 use Exporter ();
  1         2  
  1         30  
8 1     1   4 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %actions);
  1         2  
  1         112  
9 1     1   5 $VERSION = '0.05';
10 1         21 @ISA = qw(Exporter);
11 1         3 @EXPORT = qw();
12 1         2 @EXPORT_OK = qw();
13 1         243 %EXPORT_TAGS = ();
14             };
15              
16             %actions = ( "query" => "/ers/config/networkdevicegroup/",
17             "create" => "/ers/config/networkdevicegroup/",
18             "update" => "/ers/config/networkdevicegroup/",
19             "getById" => "/ers/config/networkdevicegroup/",
20             );
21              
22             # MOOSE!
23            
24             has 'description' => (
25             is => 'rw',
26             isa => 'Any',
27             );
28              
29             has 'id' => (
30             is => 'rw',
31             isa => 'Str',
32             );
33              
34             has 'name' => (
35             is => 'rw',
36             isa => 'Str',
37             );
38              
39             has 'type' => (
40             is => 'rw',
41             isa => 'Str',
42             );
43              
44             # No Moose
45              
46             sub toXML
47 0     0 1   { my $self = shift;
48 0           my $result = "";
49 0           my $id = $self->id;
50 0   0       my $description = $self->description || "";
51 0   0       my $name = $self->name || "";
52 0   0       my $type = $self->type || "Location";
53 0 0         if ($id) { $result = " <id>$id</id>\n"; }
  0            
54            
55 0           $result = <<XML;
56             <type>$type</type>
57             XML
58              
59 0           return $result;
60             }
61              
62             sub header
63 0     0 1   { my $self = shift;
64 0           my $data = shift;
65 0           my $record = shift;
66 0   0       my $name = $record->name || "Device Group Name";
67 0   0       my $id = $record->id || "";
68 0   0       my $description = $record->description || "Random Description";
69              
70 0           return qq{<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns4:networkdevicegroup description="$description" name="$name" id="$id" xmlns:ers="ers.ise.cisco.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns4="network.ers.ise.cisco.com">$data</ns4:networkdevicegroup>};
71              
72             }
73              
74              
75             =head1 NAME
76              
77             Net::Cisco::ISE::NetworkDeviceGroup - Access Cisco ISE functionality through REST API - DeviceGroup fields
78              
79             =head1 SYNOPSIS
80              
81             use Net::Cisco::ISE;
82             use Net::Cisco::ISE::NetworkDeviceGroup;
83            
84             my $acs = Net::Cisco::ISE->new(hostname => '10.0.0.1', username => 'acsadmin', password => 'testPassword');
85            
86             my %devicegroups = $acs->networkdevicegroups;
87             # Retrieve all device groups from ISE
88             # Returns hash with device name / Net::Cisco::ISE::NetworkDeviceGroup pairs
89              
90             print $acs->networkdevicegroups->{"All Locations"}->toXML;
91             # Dump in XML format (used by ISE for API calls)
92            
93             my $device = $acs->networkdevicegroups("name","All Locations");
94             # Faster call to request specific device group information by name
95              
96             my $networkdevicegroup = $acs->networkdevicegroups("id","250");
97             # Faster call to request specific device group information by ID (assigned by ISE, present in Net::Cisco::ISE::NetworkDeviceGroup)
98              
99             $networkdevicegroup->id(0); # Required for new device group!
100             my $id = $acs->create($networkdevicegroup);
101             # Create new device group based on Net::Cisco::ISE::NetworkDeviceGroup instance
102             # Return value is ID generated by ISE
103             print "Record ID is $id" if $id;
104             print $Net::Cisco::ISE::ERROR unless $id;
105             # $Net::Cisco::ISE::ERROR contains details about failure
106              
107             my $id = $acs->update($networkdevicegroup);
108             # Update existing device based on Net::Cisco::ISE::NetworkDeviceGroup instance
109             # Return value is ID generated by ISE
110             print "Record ID is $id" if $id;
111             print $Net::Cisco::ISE::ERROR unless $id;
112             # $Net::Cisco::ISE::ERROR contains details about failure
113              
114             $acs->delete($networkdevicegroup);
115             # Delete existing device based on Net::Cisco::ISE::NetworkDeviceGroup instance
116            
117             =head1 DESCRIPTION
118              
119             The Net::Cisco::ISE::NetworkDeviceGroup class holds all the device group relevant information from Cisco ISE 5.x
120              
121             =head1 USAGE
122              
123             All calls are typically handled through an instance of the L<Net::Cisco::ISE> class. L<Net::Cisco::ISE::NetworkDeviceGroup> acts as a container for device group related information.
124              
125             =over 3
126              
127             =item new
128              
129             Class constructor. Returns object of Net::Cisco::ISE::NetworkDeviceGroup on succes. The following fields can be set / retrieved:
130              
131             =over 5
132              
133             =item description
134              
135             =item name
136              
137             =item id
138              
139             =item groupType
140              
141             Formatting rules may be in place & enforced by Cisco ISE.
142              
143             =back
144              
145             =over 3
146              
147             =item description
148              
149             The device group account description, typically used for full device group name.
150              
151             =item name
152              
153             The device group name. This is a required value in the constructor but can be redefined afterwards.
154              
155             =item groupType
156              
157             This points to the type of Device Group, typically Location or Device Type but can be customized. See also L<Net::Cisco::ISE::NetworkDevice> C<deviceType>.
158              
159             =item id
160              
161             Cisco ISE generates a unique ID for each Device Group record. This field cannot be updated within ISE but is used for reference. Set to 0 when creating a new record or when duplicating an existing device group.
162              
163             =item toXML
164              
165             Dump the record in ISE accept XML formatting (without header).
166              
167             =item header
168              
169             Generate the correct XML header. Takes output of C<toXML> as argument.
170              
171             =back
172              
173             =back
174              
175             =head1 BUGS
176              
177             None yet
178              
179             =head1 SUPPORT
180              
181             None yet :)
182              
183             =head1 AUTHOR
184              
185             Hendrik Van Belleghem
186             CPAN ID: BEATNIK
187             hendrik.vanbelleghem@gmail.com
188              
189             =head1 COPYRIGHT
190              
191             This program is free software licensed under the...
192              
193             The General Public License (GPL)
194             Version 2, June 1991
195              
196             The full text of the license can be found in the
197             LICENSE file included with this module.
198              
199              
200             =head1 SEE ALSO
201              
202             perl(1).
203              
204             =cut
205              
206             #################### main pod documentation end ###################
207             __PACKAGE__->meta->make_immutable();
208              
209             1;
210             # The preceding line will help the module return a true value
211