Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------
* IOSXE
* Added AcmReplaceDiff:
* acm replace {configlet_file} diff
102 changes: 59 additions & 43 deletions sdk_generator/outputs/github_parser.json

Large diffs are not rendered by default.

75 changes: 73 additions & 2 deletions src/genie/libs/parser/iosxe/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from genie.metaparser import MetaParser
from genie.metaparser.util.schemaengine import Any, Optional
from genie.metaparser.util.exceptions import SchemaEmptyParserError

# ====================
# Schema for:
Expand Down Expand Up @@ -842,10 +843,11 @@ class AcmReplaceValidateSchema(MetaParser):

schema = {
"target": str,
"validation": {
Optional("validation"): {
"status": str,
"time_ms": int
}
},
Optional("no_diff"): bool
}


Expand All @@ -863,6 +865,11 @@ def cli(self, configlet_file='', output=None):
for line in output.splitlines():
line = line.strip()

m = re.match(r'^Config diff empty\.\s+No Diff to Validate/Apply$',line)
Comment thread
Sripadvallabh marked this conversation as resolved.
Comment thread
DevadharshniK03 marked this conversation as resolved.
if m:
ret_dict["no_diff"] = True
continue

# Config Validation to Target: flash:day1
m = re.match(r'^Config Validation to Target:\s+(?P<target>\S+)', line)
if m:
Expand All @@ -881,4 +888,68 @@ def cli(self, configlet_file='', output=None):
ret_dict.setdefault('validation', {})['time_ms'] = int(m.group('time'))
continue

return ret_dict

class AcmReplaceDiffSchema(MetaParser):
"""Schema for 'acm replace <configlet_file> diff'."""

schema = {
'target': str,
'diff': list,
Comment thread
DevadharshniK03 marked this conversation as resolved.
Outdated
}


class AcmReplaceDiff(AcmReplaceDiffSchema):
"""Parser for 'acm replace <configlet_file> diff'."""

cli_command = 'acm replace {configlet_file} diff'

def cli(self, configlet_file='', output=None):

if output is None:
output = self.device.execute(
self.cli_command.format(configlet_file=configlet_file)
)
if not output or not output.strip():
raise SchemaEmptyParserError("Parser output is empty")

ret_dict = {
'target': configlet_file,
Comment thread
DevadharshniK03 marked this conversation as resolved.
Outdated
'diff': [],
}

in_diff = False

for raw_line in output.splitlines():
# Preserve leading indentation; remove only trailing whitespace.
line = raw_line.rstrip()
normalized_line = line.strip()

if not normalized_line:
continue

# No configuration difference
m = re.match(
Comment thread
DevadharshniK03 marked this conversation as resolved.
r'^Config diff empty\.\s+No Diff to Validate/Apply$',
normalized_line
)
if m:
ret_dict['diff'] = []
in_diff = False
continue

# Configuration difference starts
m = re.match(r'^Configuration Net-Diff:\s*$', normalized_line)
Comment thread
DevadharshniK03 marked this conversation as resolved.
if m:
in_diff = True
continue

if in_diff:
# Preserve IOS-XE configuration indentation.
ret_dict['diff'].append(line)

# End of configuration diff
if line == 'end':
in_diff = False

return ret_dict
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
expected_output = {
"target": "",
"diff": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Config diff empty. No Diff to Validate/Apply
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
expected_output = {
"target": "",
"diff": [
"!",
"hostname Router",
"interface GigabitEthernet1",
" description Uplink",
" no shutdown",
"end",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Configuration Net-Diff:
!
hostname Router
interface GigabitEthernet1
description Uplink
no shutdown
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Comment thread
Sripadvallabh marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
expected_output = {
'diff': ['interface Loopback1000',
Comment thread
DevadharshniK03 marked this conversation as resolved.
' description ACM-N-FEATURE-LOOPBACK',
' ip address 192.0.2.100 255.255.255.255',
' no ip route-cache',
'end'],
'target': ''}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Configuration Net-Diff:
interface Loopback1000
description ACM-N-FEATURE-LOOPBACK
ip address 192.0.2.100 255.255.255.255
no ip route-cache
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"configlet_file": "bootflash:acm_n1_day1_test.cfg"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
expected_output = {
"target": "flash:acm_n1_day1_test.cfg",
"no_diff": True
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config Validation to Target: flash:acm_n1_day1_test.cfg
Config diff empty. No Diff to Validate/Apply