acex-driver-juniper-junoscli 1.2.0__tar.gz → 2.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: acex-driver-juniper-junoscli
3
- Version: 1.2.0
3
+ Version: 2.1.0
4
4
  Summary: ACE-X Driver: Juniper Junos CLI
5
5
  License: AGPL-3.0
6
6
  Author: Johan Lahti
@@ -11,7 +11,8 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.13
12
12
  Classifier: Programming Language :: Python :: 3.14
13
13
  Classifier: Programming Language :: Python :: 3.15
14
- Requires-Dist: acex-devkit (>=2,<3)
14
+ Requires-Dist: acex-devkit (>=3,<4)
15
+ Requires-Dist: jinja2 (>=3.1.6)
15
16
  Requires-Dist: netmiko (>=4.6.0)
16
17
  Project-URL: Homepage, https://github.com/acex-labs/acex
17
18
  Project-URL: Repository, https://github.com/acex-labs/acex
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "acex-driver-juniper-junoscli"
3
- version = "1.2.0"
3
+ version = "2.1.0"
4
4
  description = "ACE-X Driver: Juniper Junos CLI"
5
5
  authors = ["Johan Lahti <johan.lahti@acebit.se>"]
6
6
  license = "AGPL-3.0"
@@ -14,7 +14,8 @@ packages = [
14
14
  [tool.poetry.dependencies]
15
15
  python = "^3.13"
16
16
  netmiko = ">=4.6.0"
17
- acex-devkit = "^2"
17
+ acex-devkit = "^3"
18
+ jinja2 = ">=3.1.6"
18
19
 
19
20
  [build-system]
20
21
  requires = ["poetry-core>=2.0.0,<3.0.0"]
@@ -23,6 +24,13 @@ build-backend = "poetry.core.masonry.api"
23
24
  [tool.poetry.plugins."acex.neds"]
24
25
  juniper_junos_cli = "acex_driver_juniper_junos_cli.junos_cli:JunosCLI"
25
26
 
27
+ [tool.poetry.plugins."acex.changelog"]
28
+ acex-driver-juniper-junoscli = "acex_driver_juniper_junos_cli"
29
+
30
+ # Shown as the component's name in Settings > What's new.
31
+ [tool.acex.changelog]
32
+ name = "Juniper Junos CLI driver"
33
+
26
34
  [dependency-groups]
27
35
  dev = [
28
36
  "ipython (>=9.10.0,<10.0.0)"
@@ -0,0 +1,177 @@
1
+ {
2
+ "schema_version": 1,
3
+ "component": "acex-driver-juniper-junoscli",
4
+ "name": "Juniper Junos CLI driver",
5
+ "releases": [
6
+ {
7
+ "version": "2.1.0",
8
+ "date": "2026-11-06",
9
+ "entries": [
10
+ {
11
+ "id": "20261103-the-junos-driver-lists-the-changes-it",
12
+ "kind": "changed",
13
+ "title": "The Junos driver lists the changes it can't render in a patch",
14
+ "description": "`render_patch` returns a `RenderResult`: the commands as its payload, and in `metadata.unrendered` the paths of the changes no generator handles, which were left out before without a trace. Patch runs don't reach Junos devices yet, since the driver can't parse their configuration.",
15
+ "breaking": false,
16
+ "audience": "developer",
17
+ "refs": []
18
+ },
19
+ {
20
+ "id": "20261022-the-junos-driver-installs-with-the",
21
+ "kind": "fixed",
22
+ "title": "The Junos driver installs with the jinja2 it needs",
23
+ "description": "The driver imports jinja2 but did not list it, so a collection agent that installed the driver at runtime in a container without jinja2 failed to load it, and the agent then collected nothing from any device. The driver now declares jinja2 like the Cisco driver does.",
24
+ "breaking": false,
25
+ "audience": "user",
26
+ "refs": []
27
+ }
28
+ ]
29
+ },
30
+ {
31
+ "version": "1.0.3",
32
+ "date": "2026-08-21",
33
+ "entries": [
34
+ {
35
+ "id": "01-driver-works-with-the-current-acex-devki",
36
+ "kind": "fixed",
37
+ "title": "Driver works with the current ACEX devkit instead of the legacy plugin package",
38
+ "description": "The Junos driver's renderer and parser now take their base classes from the ACEX devkit rather than the older ACEX plugin package. Installations without that older package could not load the driver before; the commands it renders are unchanged.",
39
+ "breaking": false,
40
+ "audience": "admin",
41
+ "refs": [
42
+ {
43
+ "label": "#225",
44
+ "url": null
45
+ }
46
+ ]
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "version": "1.0.1",
52
+ "date": "2026-05-01",
53
+ "entries": [
54
+ {
55
+ "id": "01-rendering-no-longer-fails-for-configurat",
56
+ "kind": "fixed",
57
+ "title": "Rendering no longer fails for configurations without link aggregation",
58
+ "description": "Rendering a full Junos configuration could fail when the node had no aggregated (LAG) interfaces, or a LAG whose member ports carry no LACP settings. The driver now always supplies those values, so such configurations render; with no LAG the `set chassis aggregated-devices ...` line is simply not sent.",
59
+ "breaking": false,
60
+ "audience": "user",
61
+ "refs": [
62
+ {
63
+ "label": "784251b6b028",
64
+ "url": null
65
+ }
66
+ ]
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "version": "1.0.0",
72
+ "date": "2026-05-01",
73
+ "entries": [
74
+ {
75
+ "id": "06-a-device-s-configuration-cannot-be-read-",
76
+ "kind": "added",
77
+ "title": "A device's configuration cannot be read back yet",
78
+ "description": "The parser is a stub: asking the driver to parse a device's configuration fails with 'JunosCLIParser.parse is not yet implemented'. ACEX therefore cannot report differences between wanted and actual configuration for Junos devices in this release.",
79
+ "breaking": false,
80
+ "audience": "user",
81
+ "refs": [
82
+ {
83
+ "label": "b1edd42704b8",
84
+ "url": null
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ "id": "04-deploys-over-ssh-configuration-is-sent-a",
90
+ "kind": "added",
91
+ "title": "Deploys over SSH: configuration is sent and committed in one session",
92
+ "description": "The driver logs in over SSH (port 22, 30 s connect timeout) with the username and password it is given, and fails at once if either is missing. It sends the `set` commands in configuration mode and commits. The running configuration is read with `show configuration | display set | no-more`.",
93
+ "breaking": false,
94
+ "audience": "user",
95
+ "refs": [
96
+ {
97
+ "label": "b1edd42704b8",
98
+ "url": null
99
+ }
100
+ ]
101
+ },
102
+ {
103
+ "id": "01-device-wide-settings-are-rendered-as-jun",
104
+ "kind": "added",
105
+ "title": "Device-wide settings are rendered as Junos set commands",
106
+ "description": "Host name, domain name, location, contact, DNS servers and NTP servers (with `prefer`) become `set system ...` lines. SSH is enabled with `set system services ssh` (plus `idle-timeout`) when SSH is enabled in the configuration; `set system services netconf ssh` is always sent.",
107
+ "breaking": false,
108
+ "audience": "user",
109
+ "refs": [
110
+ {
111
+ "label": "b1edd42704b8",
112
+ "url": null
113
+ }
114
+ ]
115
+ },
116
+ {
117
+ "id": "05-incremental-updates-cover-only-the-host-",
118
+ "kind": "added",
119
+ "title": "Incremental updates cover only the host name; interfaces get a placeholder",
120
+ "description": "When ACEX sends only the differences, a changed or removed system host name becomes `set system host-name` or `delete system host-name`. A change on any interface produces the placeholder `set interfaces TODO description \"TODO\"` instead of the real change; all other differences are ignored.",
121
+ "breaking": false,
122
+ "audience": "user",
123
+ "refs": [
124
+ {
125
+ "label": "b1edd42704b8",
126
+ "url": null
127
+ }
128
+ ]
129
+ },
130
+ {
131
+ "id": "02-interfaces-are-rendered-with-junos-names",
132
+ "kind": "added",
133
+ "title": "Interfaces are rendered with Junos names, VLAN modes and LAGs",
134
+ "description": "Ethernet ports are named ge-, xe- or et- by speed (1G or unknown, 10G, 25/40/100G) as `<stack>/<module>/<port>`; the management port is `me0`, loopbacks are `lo0 unit N`, LAGs are `ae<N>`. Description, MTU, IPv4 address, access/trunk VLANs, native VLAN, `disable` and LAG membership are sent; LACP mode and interval set on member ports are applied to the `ae` interface.",
135
+ "breaking": false,
136
+ "audience": "user",
137
+ "refs": [
138
+ {
139
+ "label": "b1edd42704b8",
140
+ "url": null
141
+ }
142
+ ]
143
+ },
144
+ {
145
+ "id": "07-lldp-neighbours-are-discovered-from-the-",
146
+ "kind": "added",
147
+ "title": "LLDP neighbours are discovered from the device's neighbour table",
148
+ "description": "The driver runs `show lldp neighbors` and reports, per neighbour, the local interface, remote device name and remote port, marked as lldp. If the command fails it returns no neighbours; CDP is not supported. The columns are read by position, so unusual table layouts may be misread.",
149
+ "breaking": false,
150
+ "audience": "user",
151
+ "refs": [
152
+ {
153
+ "label": "b1edd42704b8",
154
+ "url": null
155
+ }
156
+ ]
157
+ },
158
+ {
159
+ "id": "03-vlans-static-routes-and-snmp-communities",
160
+ "kind": "added",
161
+ "title": "VLANs, static routes and SNMP communities are rendered",
162
+ "description": "VLANs become `set vlans <name> vlan-id <id>`, static routes become `set routing-options static route ... next-hop ...` (under `routing-instances` for non-global instances), and SNMP communities get read-only or read-write authorization. Client prefixes from the Juniper SNMP community clients augment are sent as `set snmp community <name> clients <prefix>`.",
163
+ "breaking": false,
164
+ "audience": "user",
165
+ "refs": [
166
+ {
167
+ "label": "b1edd42704b8",
168
+ "url": null
169
+ }
170
+ ]
171
+ }
172
+ ]
173
+ }
174
+ ],
175
+ "coming": [],
176
+ "highlights": []
177
+ }
@@ -0,0 +1,150 @@
1
+ import asyncio
2
+ import re
3
+
4
+ from acex_devkit.configdiffer import Diff
5
+ from acex_devkit.drivers import Codec, NetworkElementDriver, State, Transport
6
+ from acex_devkit.exceptions import AuthenticationFailed, ConnectionTimeout, DriverException
7
+ from acex_devkit.models.codec_result import ParseResult, RenderResult
8
+ from acex_devkit.models.composed_configuration import ComposedConfiguration
9
+ from acex_devkit.models.lldp_neighbor import LldpNeighborEntry
10
+ from acex_devkit.models.management_connection import ConnectionType
11
+ from acex_devkit.models.ned import Platform
12
+ from acex_devkit.models.node_response import NodeInstance
13
+ from acex_devkit.models.platform import OS, Vendor
14
+ from acex_devkit.models.state import DeviceFacts
15
+ from netmiko import ConnectHandler
16
+ from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException
17
+
18
+ from .normalizer import JunosNormalizer
19
+ from .renderer import JunosCLIRenderer
20
+
21
+
22
+ class JunosCLITransport(Transport[str]):
23
+ """SSH to Junos via netmiko, which is synchronous, so every call runs in a thread.
24
+
25
+ Payloads are `set` / `delete` lines, one per line, committed as one change.
26
+ """
27
+
28
+ connection_types = {ConnectionType.ssh}
29
+
30
+ PORT = 22
31
+
32
+ async def open(self) -> None:
33
+ login = self.credential("userpass")
34
+ device = {
35
+ "device_type": "juniper_junos",
36
+ "host": self.address,
37
+ "username": login.fields["username"],
38
+ "password": login.fields["password"],
39
+ "port": self.PORT,
40
+ "conn_timeout": 30,
41
+ }
42
+ try:
43
+ self.conn = await asyncio.to_thread(ConnectHandler, **device)
44
+ except NetmikoAuthenticationException as e:
45
+ raise AuthenticationFailed(f"Authentication to {self.address} failed") from e
46
+ except NetmikoTimeoutException as e:
47
+ raise ConnectionTimeout(f"Connection to {self.address} timed out") from e
48
+
49
+ async def close(self) -> None:
50
+ try:
51
+ await asyncio.to_thread(self.conn.disconnect)
52
+ except Exception:
53
+ pass
54
+
55
+ async def get_config(self) -> str:
56
+ # `display set` flattens the hierarchy into reproducible `set` lines; `no-more` disables paging.
57
+ command = "show configuration | display set | no-more"
58
+ return await asyncio.to_thread(self.conn.send_command, command, read_timeout=120)
59
+
60
+ async def apply(self, payload: str) -> str:
61
+ commands = [line.strip() for line in payload.splitlines() if line.strip()]
62
+ if not commands:
63
+ return ""
64
+ return await asyncio.to_thread(self.commit, commands)
65
+
66
+ async def execute(self, request: list[str]) -> list[str]:
67
+ return await asyncio.to_thread(self.send_commands, request)
68
+
69
+ def commit(self, commands: list[str]) -> str:
70
+ """Load the commands and commit them. Without the commit, leaving configure mode discards them."""
71
+ output = self.conn.send_config_set(commands, exit_config_mode=False)
72
+ return output + self.conn.commit(and_quit=True)
73
+
74
+ def send_commands(self, commands: list[str]) -> list[str]:
75
+ return [self.conn.send_command(command, read_timeout=120) for command in commands]
76
+
77
+
78
+ class JunosCodec(Codec[str]):
79
+ """Junos `set` syntax. Configuration and patches render to `set` / `delete` lines."""
80
+
81
+ normalizer = JunosNormalizer()
82
+
83
+ def render(self, config: ComposedConfiguration, node: NodeInstance) -> RenderResult[str]:
84
+ return RenderResult(payload=JunosCLIRenderer().render(config, node.asset))
85
+
86
+ def parse(self, raw: str, node: NodeInstance) -> ParseResult:
87
+ raise DriverException("Parsing Junos configuration is not implemented yet")
88
+
89
+ def render_patch(self, diff: Diff, node: NodeInstance) -> RenderResult[str]:
90
+ return JunosCLIRenderer().render_patch(diff, node)
91
+
92
+ def normalize(self, raw: str) -> str:
93
+ return self.normalizer.normalize(raw).config
94
+
95
+ def mask(self, raw: str) -> str:
96
+ return self.normalizer.mask(raw).config
97
+
98
+
99
+ class JunosState(State):
100
+ async def get_facts(self, transport: JunosCLITransport) -> DeviceFacts:
101
+ version, hardware = await transport.execute(["show version", "show chassis hardware"])
102
+ chassis = re.search(r"^Chassis\s+(\S+)\s+(\S+)", hardware, re.MULTILINE)
103
+ return DeviceFacts(
104
+ vendor=Vendor.juniper,
105
+ os=OS.juniper_junos,
106
+ os_version=self.find(r"^Junos:\s*(\S+)", version),
107
+ hardware_model=self.find(r"^Model:\s*(\S+)", version) or (chassis.group(2) if chassis else None),
108
+ serial_number=chassis.group(1) if chassis else None,
109
+ )
110
+
111
+ async def get_lldp_neighbors(self, transport: JunosCLITransport) -> list[LldpNeighborEntry]:
112
+ try:
113
+ raw = (await transport.execute(["show lldp neighbors"]))[0]
114
+ except Exception:
115
+ return []
116
+ return self.parse_lldp_table(raw)
117
+
118
+ @staticmethod
119
+ def find(pattern: str, text: str) -> str | None:
120
+ match = re.search(pattern, text, re.MULTILINE)
121
+ return match.group(1) if match else None
122
+
123
+ @staticmethod
124
+ def parse_lldp_table(raw: str) -> list[LldpNeighborEntry]:
125
+ """Parse the fixed-width table:
126
+
127
+ Local Interface Parent Interface Chassis Id Port info System Name
128
+ ge-0/0/0 - 00:11:22:33:44:55 ge-0/0/1 peer-switch
129
+ """
130
+ return [
131
+ LldpNeighborEntry(
132
+ local_interface=parts[0],
133
+ remote_device=parts[-1],
134
+ remote_interface=parts[-2],
135
+ discovery_protocol="lldp",
136
+ )
137
+ for line in raw.splitlines()
138
+ if line.strip() and not line.lower().startswith("local interface")
139
+ if len(parts := line.split()) >= 5
140
+ ]
141
+
142
+
143
+ class JunosCLI(NetworkElementDriver):
144
+ """Juniper Junos CLI driver."""
145
+
146
+ codec_class = JunosCodec
147
+ transport_class = JunosCLITransport
148
+ state_class = JunosState
149
+
150
+ platforms = [Platform(vendor=Vendor.juniper, os=OS.juniper_junos)]
@@ -0,0 +1,31 @@
1
+ """Junos normalizer for `show configuration | display set` output — vendor-specific rules only."""
2
+
3
+ import re
4
+
5
+ from acex_devkit.normalizer import BaseNormalizer, LineRule, RewriteRule
6
+
7
+ # A Junos value: a quoted string or a single token.
8
+ VALUE = r'("[^"]*"|\S+)'
9
+
10
+
11
+ class JunosNormalizer(BaseNormalizer):
12
+ line_rules = [
13
+ LineRule("last_commit", re.compile(r"^##\s*Last (commit|changed)")),
14
+ LineRule("version", re.compile(r"^set version\s+")),
15
+ ]
16
+
17
+ rewrite_rules = [
18
+ RewriteRule(
19
+ "secret_value",
20
+ re.compile(
21
+ rf"^(set .*\b(?:encrypted-password|secret|authentication-key|md5 \d+ key|"
22
+ rf"pre-shared-key (?:ascii-text|hexadecimal)))\s+{VALUE}(.*)$"
23
+ ),
24
+ r'\1 "<REDACTED>"\3',
25
+ ),
26
+ RewriteRule(
27
+ "snmp_community",
28
+ re.compile(rf"^(set snmp community)\s+{VALUE}(.*)$"),
29
+ r'\1 "<REDACTED>"\3',
30
+ ),
31
+ ]
@@ -5,7 +5,7 @@ from typing import Any
5
5
 
6
6
  from acex_devkit.configdiffer import Diff
7
7
  from acex_devkit.configdiffer.command import Command, Context
8
- from acex_devkit.drivers import RendererBase
8
+ from acex_devkit.models.codec_result import RenderMetadata, RenderResult
9
9
  from acex_devkit.models.composed_configuration import ComposedConfiguration
10
10
  from jinja2 import Environment, FileSystemLoader, StrictUndefined
11
11
 
@@ -45,7 +45,7 @@ PORT_PREFIX_BY_SPEED = {
45
45
  }
46
46
 
47
47
 
48
- class JunosCLIRenderer(RendererBase):
48
+ class JunosCLIRenderer:
49
49
  def _load_template_file(self) -> str:
50
50
  path = Path(__file__).parent
51
51
  env = Environment(loader=FileSystemLoader(path), undefined=StrictUndefined)
@@ -71,19 +71,24 @@ class JunosCLIRenderer(RendererBase):
71
71
  self.registry.register(("system", "config"), self._generate_system_config_commands)
72
72
  self.registry.register(("interfaces", "*"), self._generate_interface_config_commands)
73
73
 
74
- def render_patch(self, diff: Diff, node_instance: Any):
75
- """Render device commands for a Diff using registered generators."""
74
+ def render_patch(self, diff: Diff, node_instance: Any) -> RenderResult[str]:
75
+ """Render device commands for a Diff using registered generators; a change no generator handles is
76
+ listed as unrendered."""
76
77
  self.registry = GeneratorRegistry()
77
78
  self._register()
78
79
 
79
80
  commands: list[Command] = []
81
+ unrendered: list[list[str]] = []
80
82
  for change in diff.get_all_changes():
81
83
  generator = self.registry.resolve(tuple(change.path))
82
84
  if generator is None:
85
+ unrendered.append(change.path)
83
86
  continue
84
87
  commands.extend(generator(change, node_instance))
85
88
 
86
- return "\n".join(c.command for c in commands)
89
+ return RenderResult(
90
+ payload="\n".join(c.command for c in commands), metadata=RenderMetadata(unrendered=unrendered)
91
+ )
87
92
 
88
93
  def _generate_system_config_commands(self, component_change, node_instance) -> list[Command]:
89
94
  ctx = Context(path=[])
@@ -1,138 +0,0 @@
1
- from contextlib import contextmanager
2
- from typing import Any
3
-
4
- from acex_devkit.configdiffer import Diff
5
- from acex_devkit.drivers import NetworkElementDriver, TransportBase
6
- from acex_devkit.models.composed_configuration import ComposedConfiguration
7
- from acex_devkit.models.node_response import NodeListItem
8
- from netmiko import ConnectHandler
9
-
10
- from .parser import JunosCLIParser
11
- from .renderer import JunosCLIRenderer
12
-
13
-
14
- class JunosCLITransport(TransportBase):
15
- def __init__(self):
16
- self._session_conn: ConnectHandler | None = None
17
-
18
- def _open_connection(self, target_ip: str, **kwargs) -> ConnectHandler:
19
- username = kwargs.get("username")
20
- password = kwargs.get("password")
21
- if not username or not password:
22
- raise ValueError("Credentials required: username and password must be provided")
23
- device = {
24
- "device_type": "juniper_junos",
25
- "host": target_ip,
26
- "username": username,
27
- "password": password,
28
- "port": 22,
29
- "conn_timeout": 30,
30
- }
31
- return ConnectHandler(**device)
32
-
33
- @contextmanager
34
- def session(self, target_ip: str, **kwargs):
35
- """Hold one SSH session open for the duration of the block."""
36
- conn = self._open_connection(target_ip, **kwargs)
37
- self._session_conn = conn
38
- try:
39
- yield self
40
- finally:
41
- self._session_conn = None
42
- try:
43
- conn.disconnect()
44
- except Exception:
45
- pass
46
-
47
- @contextmanager
48
- def _conn(self, target_ip: str, **kwargs):
49
- """Yield active session conn or open a one-shot, closing what we own."""
50
- if self._session_conn is not None:
51
- yield self._session_conn
52
- return
53
- conn = self._open_connection(target_ip, **kwargs)
54
- try:
55
- yield conn
56
- finally:
57
- try:
58
- conn.disconnect()
59
- except Exception:
60
- pass
61
-
62
- def get_config(self, node: NodeListItem, target_ip: str, **kwargs) -> str:
63
- with self._conn(target_ip, **kwargs) as conn:
64
- # `display set` flattens hierarchical config into reproducible
65
- # `set` lines; `no-more` disables paging.
66
- return conn.send_command(
67
- "show configuration | display set | no-more",
68
- read_timeout=120,
69
- )
70
-
71
- def send_config(self, node: NodeListItem, target_ip: str, commands: list[str], **kwargs) -> str:
72
- # netmiko's juniper_junos handler enters configure mode, sends the
73
- # commands, commits, and exits — driven by send_config_set.
74
- with self._conn(target_ip, **kwargs) as conn:
75
- return conn.send_config_set(commands)
76
-
77
- def execute(self, node: NodeListItem, target_ip: str, commands: list[str], **kwargs) -> list[str]:
78
- with self._conn(target_ip, **kwargs) as conn:
79
- return [conn.send_command(cmd, read_timeout=120) for cmd in commands]
80
-
81
- def get_lldp_neighbors(self, node: NodeListItem, target_ip: str, **kwargs) -> list[dict]:
82
- with self._conn(target_ip, **kwargs) as conn:
83
- try:
84
- raw = conn.send_command("show lldp neighbors", read_timeout=60)
85
- except Exception:
86
- return []
87
- return self._parse_lldp_table(raw)
88
-
89
- @staticmethod
90
- def _parse_lldp_table(raw: str) -> list[dict]:
91
- # `show lldp neighbors` returns a fixed-width table:
92
- # Local Interface Parent Interface Chassis Id Port info System Name
93
- # ge-0/0/0 - 00:11:22:33:44:55 ge-0/0/1 peer-switch
94
- neighbors = []
95
- lines = [ln.rstrip() for ln in raw.splitlines() if ln.strip()]
96
- # Skip header line if present
97
- for line in lines:
98
- if line.lower().startswith("local interface"):
99
- continue
100
- parts = line.split()
101
- # Expected at minimum: local, parent, chassis_id, port_id, sysname
102
- if len(parts) < 5:
103
- continue
104
- local_iface = parts[0]
105
- remote_port = parts[-2]
106
- remote_dev = parts[-1]
107
- neighbors.append(
108
- {
109
- "local_interface": local_iface,
110
- "remote_device": remote_dev,
111
- "remote_interface": remote_port,
112
- "discovery_protocol": "lldp",
113
- }
114
- )
115
- return neighbors
116
-
117
-
118
- class JunosCLI(NetworkElementDriver):
119
- """Juniper Junos CLI driver."""
120
-
121
- version = "1.0.0"
122
- renderer_class = JunosCLIRenderer
123
- transport_class = JunosCLITransport
124
- parser_class = JunosCLIParser
125
-
126
- def render(self, configuration: ComposedConfiguration, asset):
127
- return self.renderer.render(configuration, asset)
128
-
129
- def parse(self, configuration: str) -> ComposedConfiguration:
130
- return self.parser.parse(configuration)
131
-
132
- def render_patch(self, diff: Diff, node_instance: Any):
133
- return self.renderer.render_patch(diff, node_instance)
134
-
135
- def apply_patch(self, diff: Diff, node_instance, node: NodeListItem, target_ip: str, **kwargs):
136
- rendered = self.render_patch(diff, node_instance=node_instance)
137
- commands = [c.strip() for c in rendered.splitlines() if c.strip()]
138
- return self.transport.send_config(node, target_ip, commands, **kwargs)
@@ -1,17 +0,0 @@
1
- """Junos CLI configuration parser.
2
-
3
- Parsing a real Junos `show configuration` (hierarchical or set-format) into
4
- the device-agnostic model is a significant undertaking. This stub keeps the
5
- driver instantiable so deployment-side flows (render/render_patch/apply_patch)
6
- work; calling parse() raises until a real implementation lands.
7
- """
8
-
9
- from acex_devkit.drivers import ParserBase
10
-
11
-
12
- class JunosCLIParser(ParserBase):
13
- def parse(self, configuration: str):
14
- raise NotImplementedError(
15
- "JunosCLIParser.parse is not yet implemented. "
16
- "Implement parsing of `show configuration | display set` output here."
17
- )