asterust 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. {asterust-0.1.0 → asterust-0.2.0}/.github/workflows/publish-pypi.yml +1 -2
  2. asterust-0.2.0/.github/workflows/release-plz.yml +71 -0
  3. {asterust-0.1.0 → asterust-0.2.0}/AGENTS.md +8 -5
  4. asterust-0.2.0/CHANGELOG.md +31 -0
  5. {asterust-0.1.0 → asterust-0.2.0}/Cargo.lock +11 -3
  6. {asterust-0.1.0 → asterust-0.2.0}/Cargo.toml +2 -2
  7. {asterust-0.1.0 → asterust-0.2.0}/PKG-INFO +22 -1
  8. {asterust-0.1.0 → asterust-0.2.0}/README.md +1 -0
  9. asterust-0.2.0/crates/asterust-iosxe/CHANGELOG.md +14 -0
  10. asterust-0.2.0/crates/asterust-iosxe/Cargo.toml +14 -0
  11. asterust-0.2.0/crates/asterust-iosxe/README.md +28 -0
  12. asterust-0.2.0/crates/asterust-iosxe/src/bgp.rs +154 -0
  13. asterust-0.2.0/crates/asterust-iosxe/src/device.rs +85 -0
  14. asterust-0.2.0/crates/asterust-iosxe/src/interface.rs +160 -0
  15. asterust-0.2.0/crates/asterust-iosxe/src/isis.rs +75 -0
  16. asterust-0.2.0/crates/asterust-iosxe/src/lib.rs +43 -0
  17. asterust-0.2.0/crates/asterust-iosxe/src/ospf.rs +135 -0
  18. asterust-0.2.0/crates/asterust-iosxe/src/vrf.rs +170 -0
  19. asterust-0.2.0/crates/asterust-iosxe/tests/full_config.rs +53 -0
  20. asterust-0.2.0/crates/asterust-iosxr/CHANGELOG.md +20 -0
  21. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/Cargo.toml +1 -1
  22. asterust-0.2.0/crates/asterust-iosxr/LICENSE-APACHE +201 -0
  23. asterust-0.2.0/crates/asterust-iosxr/LICENSE-MIT +21 -0
  24. asterust-0.2.0/crates/asterust-iosxr/README.md +46 -0
  25. asterust-0.2.0/crates/asterust-iosxr/src/bgp.rs +598 -0
  26. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/src/device.rs +11 -1
  27. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/src/lib.rs +1 -0
  28. asterust-0.2.0/crates/asterust-iosxr/src/vrf.rs +150 -0
  29. asterust-0.2.0/crates/asterust-py/CHANGELOG.md +24 -0
  30. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-py/Cargo.toml +3 -2
  31. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-py/README.md +21 -0
  32. asterust-0.2.0/crates/asterust-py/src/iosxe.rs +250 -0
  33. asterust-0.2.0/crates/asterust-py/src/iosxr.rs +406 -0
  34. asterust-0.2.0/crates/asterust-py/src/lib.rs +45 -0
  35. asterust-0.2.0/crates/asterust-py/src/repr.rs +13 -0
  36. asterust-0.2.0/crates/asterust-py/tests/test_iosxe.py +126 -0
  37. asterust-0.2.0/crates/asterust-py/tests/test_iosxr.py +198 -0
  38. asterust-0.2.0/python/asterust/iosxe.py +23 -0
  39. asterust-0.2.0/python/asterust/iosxr.py +39 -0
  40. asterust-0.2.0/release-plz.toml +8 -0
  41. {asterust-0.1.0 → asterust-0.2.0}/src/config/mod.rs +40 -0
  42. asterust-0.2.0/src/device.rs +123 -0
  43. {asterust-0.1.0 → asterust-0.2.0}/src/lib.rs +1 -0
  44. asterust-0.1.0/.github/workflows/publish.yml +0 -26
  45. asterust-0.1.0/crates/asterust-iosxr/README.md +0 -26
  46. asterust-0.1.0/crates/asterust-iosxr/src/bgp.rs +0 -118
  47. asterust-0.1.0/crates/asterust-py/src/iosxr.rs +0 -194
  48. asterust-0.1.0/crates/asterust-py/src/lib.rs +0 -22
  49. asterust-0.1.0/crates/asterust-py/tests/test_iosxr.py +0 -88
  50. asterust-0.1.0/python/asterust/iosxr.py +0 -21
  51. {asterust-0.1.0 → asterust-0.2.0}/.github/workflows/ci.yml +0 -0
  52. {asterust-0.1.0 → asterust-0.2.0}/.gitignore +0 -0
  53. {asterust-0.1.0 → asterust-0.2.0}/LICENSE-APACHE +0 -0
  54. {asterust-0.1.0 → asterust-0.2.0}/LICENSE-MIT +0 -0
  55. {asterust-0.1.0 → asterust-0.2.0}/Makefile +0 -0
  56. {asterust-0.1.0/crates/asterust-iosxr → asterust-0.2.0/crates/asterust-iosxe}/LICENSE-APACHE +0 -0
  57. {asterust-0.1.0/crates/asterust-iosxr → asterust-0.2.0/crates/asterust-iosxe}/LICENSE-MIT +0 -0
  58. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/src/interface.rs +0 -0
  59. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/src/isis.rs +0 -0
  60. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/src/ospf.rs +0 -0
  61. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-iosxr/tests/full_config.rs +0 -0
  62. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-py/src/config.rs +0 -0
  63. {asterust-0.1.0 → asterust-0.2.0}/crates/asterust-py/tests/test_config.py +0 -0
  64. {asterust-0.1.0 → asterust-0.2.0}/pyproject.toml +0 -0
  65. {asterust-0.1.0 → asterust-0.2.0}/python/asterust/__init__.py +0 -0
  66. {asterust-0.1.0 → asterust-0.2.0}/rustfmt.toml +0 -0
  67. {asterust-0.1.0 → asterust-0.2.0}/src/config/cisco.rs +0 -0
  68. {asterust-0.1.0 → asterust-0.2.0}/src/config/juniper.rs +0 -0
  69. {asterust-0.1.0 → asterust-0.2.0}/tests/config_cisco.rs +0 -0
  70. {asterust-0.1.0 → asterust-0.2.0}/tests/config_juniper.rs +0 -0
@@ -1,8 +1,7 @@
1
1
  name: Publish to PyPI
2
2
 
3
3
  on:
4
- push:
5
- tags: ['py-v*']
4
+ workflow_dispatch:
6
5
 
7
6
  jobs:
8
7
  wheels:
@@ -0,0 +1,71 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ release-plz-release:
9
+ name: Release-plz release
10
+ runs-on: ubuntu-latest
11
+ if: ${{ github.repository_owner == 'asterust' }}
12
+ environment: release
13
+ permissions:
14
+ contents: write
15
+ id-token: write # crates.io Trusted Publishing
16
+ actions: write # dispatch publish-pypi.yml
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0
21
+ persist-credentials: false
22
+
23
+ - name: Install Rust
24
+ uses: dtolnay/rust-toolchain@stable
25
+
26
+ - name: Run release-plz
27
+ id: release-plz
28
+ uses: release-plz/action@v0.5
29
+ with:
30
+ command: release
31
+ env:
32
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33
+
34
+ # Tags pushed with GITHUB_TOKEN don't trigger other workflows, so dispatch the upload explicitly.
35
+ - name: Publish Python package
36
+ if: ${{ steps.release-plz.outputs.releases_created == 'true' }}
37
+ env:
38
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39
+ GH_REPO: ${{ github.repository }}
40
+ RELEASES: ${{ steps.release-plz.outputs.releases }}
41
+ run: |
42
+ tag=$(echo "$RELEASES" | jq -r '.[] | select(.package_name == "asterust-py") | .tag')
43
+ if [ -n "$tag" ]; then
44
+ gh workflow run publish-pypi.yml --ref "$tag"
45
+ fi
46
+
47
+ release-plz-pr:
48
+ name: Release-plz PR
49
+ runs-on: ubuntu-latest
50
+ if: ${{ github.repository_owner == 'asterust' }}
51
+ permissions:
52
+ contents: write
53
+ pull-requests: write
54
+ concurrency:
55
+ group: release-plz-${{ github.ref }}
56
+ cancel-in-progress: false
57
+ steps:
58
+ - uses: actions/checkout@v4
59
+ with:
60
+ fetch-depth: 0
61
+ persist-credentials: false
62
+
63
+ - name: Install Rust
64
+ uses: dtolnay/rust-toolchain@stable
65
+
66
+ - name: Run release-plz
67
+ uses: release-plz/action@v0.5
68
+ with:
69
+ command: release-pr
70
+ env:
71
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -96,10 +96,13 @@ micro-optimization.
96
96
  not just *what* changed — the diff already shows the *what*).
97
97
  - Never commit commented-out code, debug `println!`/`dbg!` calls, or
98
98
  credentials.
99
- - Bump `Cargo.toml`'s `version` whenever a branch adds a new feature
100
- (new module, new public API, new vendor/syntax support) — minor bump
101
- for features, patch for pure bugfixes. Don't bump for docs/tooling/
102
- test-only changes.
99
+ - Use conventional commit prefixes (`feat:`, `fix:`, `feat!:` or a
100
+ `BREAKING CHANGE:` footer, plus `docs:`/`ci:`/`test:`/`chore:`).
101
+ release-plz reads them to pick each crate's next version and write
102
+ its changelog, so the prefix must match the change.
103
+ - Don't bump `version` in `Cargo.toml` by hand. release-plz opens a
104
+ release PR on `main`; merging it tags, publishes to crates.io, and
105
+ (for `asterust-py`) dispatches the PyPI upload.
103
106
 
104
107
  ## Before Committing
105
108
 
@@ -108,7 +111,7 @@ micro-optimization.
108
111
  - [ ] `cargo fmt --all -- --check` passes
109
112
  - [ ] New public items have doc comments
110
113
  - [ ] No commented-out code, debug prints, or credentials
111
- - [ ] `Cargo.toml` version bumped if this change is a new feature
114
+ - [ ] Commit messages use a conventional prefix matching the change
112
115
 
113
116
  These are exactly the checks `.github/workflows/ci.yml` runs — if all
114
117
  four pass locally, CI will pass.
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.2.2](https://github.com/asterust/asterust/compare/asterust-v0.2.1...asterust-v0.2.2) - 2026-11-26
11
+
12
+ ### Other
13
+
14
+ - use the default asterust-py-v tag and release names for the Python package
15
+ - name the asterust-py GitHub Release after its py-v tag
16
+
17
+ ## [0.2.1](https://github.com/asterust/asterust/compare/asterust-v0.2.0...asterust-v0.2.1) - 2026-11-26
18
+
19
+ ### Added
20
+
21
+ - add ConfigLine keyword helpers and device traits
22
+ - add asterust.iosxe Python module
23
+ - add asterust-iosxe crate with typed IOS XE blocks
24
+ - add asterust-py PyO3 bindings (config tree + IosXrDevice)
25
+ - add asterust-iosxr workspace crate with typed IOS XR blocks
26
+
27
+ ### Other
28
+
29
+ - automate per-crate releases with release-plz
30
+ - publish wheels and sdist to PyPI on py-v* tags
31
+ - shorten IosXrDevice getters to interfaces/ospf/bgp/isis
@@ -13,23 +13,31 @@ dependencies = [
13
13
 
14
14
  [[package]]
15
15
  name = "asterust"
16
- version = "0.2.0"
16
+ version = "0.2.2"
17
17
  dependencies = [
18
18
  "regex",
19
19
  ]
20
20
 
21
+ [[package]]
22
+ name = "asterust-iosxe"
23
+ version = "0.1.1"
24
+ dependencies = [
25
+ "asterust",
26
+ ]
27
+
21
28
  [[package]]
22
29
  name = "asterust-iosxr"
23
- version = "0.1.0"
30
+ version = "0.2.1"
24
31
  dependencies = [
25
32
  "asterust",
26
33
  ]
27
34
 
28
35
  [[package]]
29
36
  name = "asterust-py"
30
- version = "0.1.0"
37
+ version = "0.2.0"
31
38
  dependencies = [
32
39
  "asterust",
40
+ "asterust-iosxe",
33
41
  "asterust-iosxr",
34
42
  "pyo3",
35
43
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "asterust"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  edition = "2021"
5
5
  description = "Vendor-aware hierarchical configuration parsing for network device CLI output (Cisco-style indentation, Juniper-style braces)."
6
6
  license = "MIT OR Apache-2.0"
@@ -13,4 +13,4 @@ name = "asterust"
13
13
  regex = "1"
14
14
 
15
15
  [workspace]
16
- members = [".", "crates/asterust-iosxr", "crates/asterust-py"]
16
+ members = [".", "crates/asterust-iosxe", "crates/asterust-iosxr", "crates/asterust-py"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: asterust
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Requires-Dist: pytest ; extra == 'test'
5
5
  Provides-Extra: test
6
6
  Summary: Hierarchical network device config parsing with typed platform views (IOS XR).
@@ -25,6 +25,27 @@ for iface in device.interfaces:
25
25
  device.ospf # list of OspfProcess
26
26
  device.bgp # list of BgpProcess
27
27
  device.isis # list of IsisInstance
28
+ device.vrfs # list of Vrf (route-targets, route-policies, maximum prefix)
29
+ ```
30
+
31
+ BGP exposes templates and VRFs as well as neighbors:
32
+
33
+ ```python
34
+ bgp = device.bgp[0]
35
+ bgp.neighbors[0].use_neighbor_group # template inheritance
36
+ bgp.neighbor_groups, bgp.session_groups, bgp.af_groups
37
+ bgp.vrfs[0].neighbors[0].address_families[0].route_policy_in
38
+ ```
39
+
40
+ IOS XE works the same way from `asterust.iosxe`:
41
+
42
+ ```python
43
+ from asterust.iosxe import IosXeDevice
44
+
45
+ device = IosXeDevice(running_config_text)
46
+ device.interfaces # includes ospf_area / isis_tag set per interface
47
+ device.bgp # neighbors assembled from `neighbor <addr> ...` lines
48
+ device.vrfs # `vrf definition` and legacy `ip vrf`
28
49
  ```
29
50
 
30
51
  The generic tree is available for any platform:
@@ -21,6 +21,7 @@ build typed views on top of it so you only depend on what you use.
21
21
  | Crate | Purpose |
22
22
  | --- | --- |
23
23
  | `asterust` (root) | Generic config tree and the `cisco` / `juniper` parsers |
24
+ | [`asterust-iosxe`](crates/asterust-iosxe) | Typed IOS XE `interface`, OSPF, BGP, and IS-IS blocks |
24
25
  | [`asterust-iosxr`](crates/asterust-iosxr) | Typed IOS XR `interface`, OSPF, BGP, and IS-IS blocks |
25
26
  | [`asterust-py`](crates/asterust-py) | PyO3 bindings, built as the `asterust` Python package |
26
27
 
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.1](https://github.com/asterust/asterust/compare/asterust-iosxe-v0.1.0...asterust-iosxe-v0.1.1) - 2026-11-26
11
+
12
+ ### Added
13
+
14
+ - *(iosxr,iosxe)* add VRF definition views
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "asterust-iosxe"
3
+ version = "0.1.1"
4
+ edition = "2021"
5
+ description = "Typed Cisco IOS XE config blocks (interface, OSPF, BGP, IS-IS) extracted from an asterust config tree."
6
+ license = "MIT OR Apache-2.0"
7
+ readme = "README.md"
8
+ repository = "https://github.com/asterust/asterust"
9
+
10
+ [lib]
11
+ name = "asterust_iosxe"
12
+
13
+ [dependencies]
14
+ asterust = { path = "../..", version = "0.2" }
@@ -0,0 +1,28 @@
1
+ # asterust-iosxe
2
+
3
+ Typed views of common Cisco IOS XE config blocks, extracted from a config
4
+ tree parsed by [asterust](https://github.com/asterust/asterust).
5
+
6
+ | Module | Block | Extracted |
7
+ | --- | --- | --- |
8
+ | `interface` | `interface <name>` | description, vrf, ipv4/ipv6 addresses, shutdown, per-interface OSPF area and IS-IS tag |
9
+ | `ospf` | `router ospf <id> [vrf <name>]` | router-id, `network` statements, passive interfaces |
10
+ | `bgp` | `router bgp <asn>` | router-id, address-families, neighbors (remote-as, description, peer-group) |
11
+ | `isis` | `router isis [tag]` | net |
12
+ | `vrf` | `vrf definition <name>`, `ip vrf <name>` | description, rd, per-address-family route-targets and import/export maps |
13
+
14
+ ```rust
15
+ use asterust_iosxe::IosXeDevice;
16
+
17
+ let device = IosXeDevice::parse(running_config_text);
18
+ for iface in device.interfaces() {
19
+ println!("{}: {:?}", iface.name, iface.ipv4_addresses);
20
+ }
21
+ ```
22
+
23
+ The per-module functions (e.g. `interface::interfaces(&config)`) work on any
24
+ `asterust::config::Config` if you already have one parsed.
25
+
26
+ ## Sources
27
+
28
+ Unlike `asterust-iosxr`, these views are not yet grounded in a Cisco guide: the test fixtures are written from the IOS XE command syntax and have not been checked against a Cisco guide or a real device. Treat the `vrf` fixtures in particular as unverified.
@@ -0,0 +1,154 @@
1
+ //! `router bgp <asn>` blocks.
2
+
3
+ use crate::{child_arg, child_args, line_arg};
4
+ use asterust::config::{Config, ConfigBlock};
5
+ use std::collections::HashSet;
6
+
7
+ /// A BGP neighbor assembled from its `neighbor <address> ...` lines.
8
+ #[derive(Clone, Debug, PartialEq, Eq)]
9
+ pub struct BgpNeighbor {
10
+ pub address: String,
11
+ pub remote_as: Option<String>,
12
+ pub description: Option<String>,
13
+ pub peer_group: Option<String>,
14
+ }
15
+
16
+ /// An IOS XE BGP process. `asn` is kept as text since it may be asdot (`"1.10"`).
17
+ /// Peer-group definitions are not listed as neighbors.
18
+ #[derive(Clone, Debug, PartialEq, Eq)]
19
+ pub struct BgpProcess {
20
+ pub asn: String,
21
+ pub router_id: Option<String>,
22
+ pub address_families: Vec<String>,
23
+ pub neighbors: Vec<BgpNeighbor>,
24
+ }
25
+
26
+ impl BgpProcess {
27
+ /// Build from a top-level `router bgp <asn>` block, or `None` for any other block.
28
+ pub fn from_block(block: &ConfigBlock) -> Option<Self> {
29
+ let root = block.get_root_line();
30
+ let asn = line_arg(&root.text, "router bgp")?.split_whitespace().next()?;
31
+ let neighbor_lines = child_args(root, "neighbor");
32
+
33
+ let peer_groups: HashSet<&str> = neighbor_lines
34
+ .iter()
35
+ .filter_map(|arg| {
36
+ let mut words = arg.split_whitespace();
37
+ let name = words.next()?;
38
+ (words.next() == Some("peer-group") && words.next().is_none()).then_some(name)
39
+ })
40
+ .collect();
41
+
42
+ let mut neighbors: Vec<BgpNeighbor> = Vec::new();
43
+ for arg in neighbor_lines {
44
+ let Some((address, setting)) = arg.split_once(' ') else {
45
+ continue;
46
+ };
47
+ if peer_groups.contains(address) {
48
+ continue;
49
+ }
50
+ let idx = neighbors.iter().position(|n| n.address == address).unwrap_or_else(|| {
51
+ neighbors.push(BgpNeighbor {
52
+ address: address.to_string(),
53
+ remote_as: None,
54
+ description: None,
55
+ peer_group: None,
56
+ });
57
+ neighbors.len() - 1
58
+ });
59
+ let setting = setting.trim();
60
+ if let Some(value) = line_arg(setting, "remote-as") {
61
+ neighbors[idx].remote_as = Some(value.to_string());
62
+ } else if let Some(value) = line_arg(setting, "description") {
63
+ neighbors[idx].description = Some(value.to_string());
64
+ } else if let Some(value) = line_arg(setting, "peer-group") {
65
+ neighbors[idx].peer_group = Some(value.to_string());
66
+ }
67
+ }
68
+
69
+ Some(Self {
70
+ asn: asn.to_string(),
71
+ router_id: child_arg(root, "bgp router-id").map(str::to_string),
72
+ address_families: child_args(root, "address-family")
73
+ .into_iter()
74
+ .map(str::to_string)
75
+ .collect(),
76
+ neighbors,
77
+ })
78
+ }
79
+ }
80
+
81
+ /// Every `router bgp` block in `config`.
82
+ pub fn bgp_processes(config: &Config) -> Vec<BgpProcess> {
83
+ config.blocks.iter().filter_map(BgpProcess::from_block).collect()
84
+ }
85
+
86
+ #[cfg(test)]
87
+ mod tests {
88
+ use super::*;
89
+ use asterust::config::cisco;
90
+
91
+ const CONFIG: &str = "
92
+ router bgp 65000
93
+ bgp router-id 10.255.0.1
94
+ bgp log-neighbor-changes
95
+ neighbor RR-CLIENTS peer-group
96
+ neighbor RR-CLIENTS remote-as 65000
97
+ neighbor 10.255.0.2 remote-as 65000
98
+ neighbor 10.255.0.2 description rr1
99
+ neighbor 10.255.0.2 update-source Loopback0
100
+ neighbor 10.255.0.3 peer-group RR-CLIENTS
101
+ neighbor 192.0.2.1 remote-as 64512
102
+ !
103
+ address-family ipv4
104
+ network 10.255.0.1 mask 255.255.255.255
105
+ neighbor 10.255.0.2 activate
106
+ exit-address-family
107
+ !
108
+ address-family vpnv4
109
+ neighbor 10.255.0.2 activate
110
+ exit-address-family
111
+ !
112
+ ";
113
+
114
+ #[test]
115
+ fn assembles_neighbors_from_flat_lines() {
116
+ let config = cisco::parse(CONFIG);
117
+ let procs = bgp_processes(&config);
118
+ assert_eq!(procs.len(), 1);
119
+
120
+ let bgp = &procs[0];
121
+ assert_eq!(bgp.asn, "65000");
122
+ assert_eq!(bgp.router_id.as_deref(), Some("10.255.0.1"));
123
+ assert_eq!(bgp.address_families, ["ipv4", "vpnv4"]);
124
+ assert_eq!(
125
+ bgp.neighbors,
126
+ [
127
+ BgpNeighbor {
128
+ address: "10.255.0.2".into(),
129
+ remote_as: Some("65000".into()),
130
+ description: Some("rr1".into()),
131
+ peer_group: None,
132
+ },
133
+ BgpNeighbor {
134
+ address: "10.255.0.3".into(),
135
+ remote_as: None,
136
+ description: None,
137
+ peer_group: Some("RR-CLIENTS".into()),
138
+ },
139
+ BgpNeighbor {
140
+ address: "192.0.2.1".into(),
141
+ remote_as: Some("64512".into()),
142
+ description: None,
143
+ peer_group: None,
144
+ },
145
+ ]
146
+ );
147
+ }
148
+
149
+ #[test]
150
+ fn non_bgp_block_is_none() {
151
+ let config = cisco::parse("router ospf 1\n router-id 1.1.1.1\n");
152
+ assert!(BgpProcess::from_block(&config.blocks[0]).is_none());
153
+ }
154
+ }
@@ -0,0 +1,85 @@
1
+ //! [`IosXeDevice`]: one parsed IOS XE config with every supported block type as a getter.
2
+
3
+ use crate::bgp::{bgp_processes, BgpProcess};
4
+ use crate::interface::{interfaces, Interface};
5
+ use crate::isis::{isis_instances, IsisInstance};
6
+ use crate::ospf::{ospf_processes, OspfProcess};
7
+ use crate::vrf::{vrfs, Vrf};
8
+ use asterust::config::{cisco, Config};
9
+
10
+ /// A parsed IOS XE running config.
11
+ #[derive(Clone, Debug)]
12
+ pub struct IosXeDevice {
13
+ config: Config,
14
+ }
15
+
16
+ impl IosXeDevice {
17
+ /// Parse raw `show running-config` text.
18
+ pub fn parse(config_text: &str) -> Self {
19
+ Self::from_config(cisco::parse(config_text))
20
+ }
21
+
22
+ /// Wrap an already-parsed [`Config`].
23
+ pub fn from_config(config: Config) -> Self {
24
+ Self { config }
25
+ }
26
+
27
+ /// The underlying generic config tree.
28
+ pub fn config(&self) -> &Config {
29
+ &self.config
30
+ }
31
+
32
+ pub fn interfaces(&self) -> Vec<Interface> {
33
+ interfaces(&self.config)
34
+ }
35
+
36
+ pub fn ospf(&self) -> Vec<OspfProcess> {
37
+ ospf_processes(&self.config)
38
+ }
39
+
40
+ pub fn bgp(&self) -> Vec<BgpProcess> {
41
+ bgp_processes(&self.config)
42
+ }
43
+
44
+ pub fn vrfs(&self) -> Vec<Vrf> {
45
+ vrfs(&self.config)
46
+ }
47
+
48
+ pub fn isis(&self) -> Vec<IsisInstance> {
49
+ isis_instances(&self.config)
50
+ }
51
+ }
52
+
53
+ #[cfg(test)]
54
+ mod tests {
55
+ use super::*;
56
+
57
+ #[test]
58
+ fn exposes_every_block_type() {
59
+ let device = IosXeDevice::parse(
60
+ "
61
+ interface Loopback0
62
+ ip address 10.255.0.1 255.255.255.255
63
+ !
64
+ router isis CORE
65
+ net 49.0001.0100.2550.0001.00
66
+ !
67
+ router ospf 1
68
+ router-id 10.255.0.1
69
+ !
70
+ router bgp 65000
71
+ neighbor 10.255.0.2 remote-as 65000
72
+ !
73
+ vrf definition CUSTOMER-A
74
+ rd 65000:1
75
+ !
76
+ ",
77
+ );
78
+ assert_eq!(device.interfaces()[0].name, "Loopback0");
79
+ assert_eq!(device.isis()[0].tag.as_deref(), Some("CORE"));
80
+ assert_eq!(device.vrfs()[0].rd.as_deref(), Some("65000:1"));
81
+ assert_eq!(device.ospf()[0].process_id, "1");
82
+ assert_eq!(device.bgp()[0].neighbors[0].address, "10.255.0.2");
83
+ assert_eq!(device.config().get_block_count(), 5);
84
+ }
85
+ }