Skip to content

Commit

Permalink
add junos_chassis_inventory data-source
Browse files Browse the repository at this point in the history
Fix #587
  • Loading branch information
jeremmfr committed Jan 2, 2024
1 parent ef10db3 commit 4038ad2
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changes/issue-587.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- markdownlint-disable-file MD013 MD041 -->
FEATURES:

* add **junos_chassis_inventory** data-source (Fix [#587](https://github.com/jeremmfr/terraform-provider-junos/issues/587))
59 changes: 59 additions & 0 deletions docs/data-sources/chassis_inventory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
page_title: "Junos: junos_chassis_inventory"
---

# junos_chassis_inventory

Get chassis inventory (like the `show chassis hardware` command).

## Example Usage

```hcl
# Read chassis inventory and display serial-number
data "junos_chassis_inventory" "demo" {}
output "SN" {
value = data.junos_chassis_inventory.demo.chassis.0.serial_number
}
```

## Attributes Reference

The following attributes are exported:

- **id** (String)
An identifier for the data source with value `chassis_inventory`.
- **chassis** (Block List)
Chassis inventory for each routing engine.
- Attributes defined by [component information schema](#component-information-schema)
- **re_name** (String)
Name of the routing engine (only if there are multiple routing engines).
- **module** (Block List)
For each module, component information.
See [below for nested schema](#module-attributes).

### module attributes

- Attributes defined by [component information schema](#component-information-schema)
- **sub_module** (Block List)
For each sub-module, component information.
- Attributes defined by [component information schema](#component-information-schema)
- **sub_sub_module** (Block List)
For each sub-sub-module, component information.
Attributes defined by [component information schema](#component-information-schema)

### component information schema

- **clei_code** (String)
Common Language Equipment Identifier code of the component.
- **description** (String)
Description of the component.
- **model_number** (String)
Model number of the component.
- **name** (String)
Name of the component.
- **part_number** (String)
Part number of the component.
- **serial_number** (String)
Serial number of the component.
- **version** (String)
Version of the component.
25 changes: 25 additions & 0 deletions internal/junos/netconf_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
rpcCloseSession = "<close-session/>"

rpcGetSystemInformation = "<get-system-information/>"
RPCGetChassisInventory = `<get-chassis-inventory></get-chassis-inventory>`
RPCGetInterfaceInformationInterfaceName = "<get-interface-information><interface-name>%s</interface-name></get-interface-information>" //nolint:lll
RPCGetInterfacesInformationTerse = `<get-interface-information><terse/></get-interface-information>`
RPCGetInterfaceInformationTerse = `<get-interface-information>%s<terse/></get-interface-information>`
Expand Down Expand Up @@ -114,3 +115,27 @@ type RPCGetRouteInformationReply struct {
} `xml:"rt"`
} `xml:"route-table"`
}

type RPCGetChassisInventoryReply struct {
XMLName xml.Name `xml:"chassis-inventory"`
Chassis struct {
RPCGetChassisInventoryReplyComponent
Module []struct {
RPCGetChassisInventoryReplyComponent
SubModule []struct {
RPCGetChassisInventoryReplyComponent
SubSubModule []RPCGetChassisInventoryReplyComponent `xml:"chassis-sub-sub-module"`
} `xml:"chassis-sub-module"`
} `xml:"chassis-module"`
} `xml:"chassis"`
}

type RPCGetChassisInventoryReplyComponent struct {
Name *string `xml:"name"`
Version *string `xml:"version"`
PartNumber *string `xml:"part-number"`
SerialNumber *string `xml:"serial-number"`
ModelNumber *string `xml:"model-number"`
CleiCode *string `xml:"clei-code"`
Description *string `xml:"description"`
}
Loading

0 comments on commit 4038ad2

Please sign in to comment.