Perl Example using RESTConf Data

Use Case

Exporting EPNM's Hardware Inventory has always been a popular ask. There are 3 Basic REST Calls available that get this RAW data.

  • Equipments Inventory ( /restconf/data/v1/cisco-resource-physical:equipment )
  • Modules Inventory ( /restconf/data/v1/cisco-resource-physical:module )
  • Nodes Inventory ( /restconf/data/v1/cisco-resource-physical:node )

The use case here is to collate information available via the 3 basic calls above, and draw an outline of the physical structure of the said device to provide a comprehensive network device inventory report.

JSON Snippet

{
        -"com.response-message": {
                -"com.header": {
                        "com.firstIndex": 0,
                                "com.lastIndex": 0
                },
                        -"com.data": {
                                -"eq.module": [
                                        -{
                                                "fdtn.description": "1000BASE-SX SFP (DOM), MMF, 550/220m",
                                                "fdtn.name": "module mau GigabitEthernet0/1/CPU0/15",
                                                "eq.connectors": "",
                                                "eq.contained-equipment-recurse": "",
                                                "eq.containing-equipment": "MD=CISCO_EPNM!ND=isc-cl-test-l2-asr9006-2.cisco.com!EQ=name=slot mau GigabitEthernet0/1/CPU0/15;partnumber=cevContainerSFP",
                                                "eq.ent-physical-index": 37424733,
                                                "eq.equipment-type": "MODULE",
                                                "eq.fdn": "MD=CISCO_EPNM!ND=isc-cl-test-l2-asr9006-2.cisco.com!EQ=name=module mau GigabitEthernet0/1/CPU0/15;partnumber=SFP-GE-S",
                                                "eq.hardware-version": "V01 ",
                                                "eq.is-field-replaceable-unit": "TRUE",
                                                "eq.is-physically-present": true,
                                                "eq.is-reporting-alarms-allowed": "UNKNOWN",
                                                "eq.operational-state-code": "enabled",
                                                "eq.part-number": "SFP-GE-S           ",
                                                "eq.product-id": "SFP-GE-S           ",
                                                "eq.serial-number": "FNS12250BQN   ",
                                                "eq.service-state": "UNKNOWN",
                                                "eq.vendor-equipment-type": "cevSFP1000BaseSx"
                                        }
                                ]
                        }
        }
}

Perl Snippet

sub getNode_ {
        my ($eq, %glbl_eq);
        $client->GET(
                        'restconf/data/v1/cisco-resource-physical:node',
                        $headers
                    );

        my $response = from_json($client->responseContent());
        my $node = toList($response->{'com.response-message'},'com.data');
        my $fdn_ = $node->[0]->{'nd.node'};

        foreach my $nd_ (@$fdn_) {

                # this is one node. here's the node name
                my $ndname_ = $nd_->{'nd.fdn'};
                $ndname_ =~ s/MD\=CISCO_EPNM\!ND\=//;
                my @nd_equips = ();
                foreach my $eq_ ($nd_->{'nd.equipment-list'}->{'eq.equipment'}) {
                        foreach (@$eq_) {
                                my %tmp;
                                $tmp{'eqname'}=$_->{'fdtn.name'};
                                $tmp{'eqdescr'}=$_->{'fdtn.description'};
                                $tmp{'eqpartno'}=$_->{'eq.part-number'};
                                $tmp{'eqserno'}=$_->{'eq.serial-number'};
                                $tmp{'eqmanufacturer'}=$_->{'eq.manufacturer'};
                                $tmp{'eqhwver'}=$_->{'eq.hardware-version'};

                                my $yatmp = $_->{'eq.fdn'};
                                $glbl_eq{$yatmp}= \%tmp;

                                push( @nd_equips, \%tmp );
                        }
                }
        }
        return \%glbl_eq;
}