This repository has been archived by the owner on May 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added preprocessing and postprocessing functions
- Loading branch information
Showing
16 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
napalm_yang/mappings/junos/parsers/config/openconfig-if-ethernet/ethernet.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
metadata: | ||
prefix: "oc-ethernet" | ||
processor: TextTree | ||
|
||
ethernet: | ||
_process: unnecessary | ||
config: | ||
_process: unnecessary | ||
auto-negotiate: | ||
_process: not_implemented | ||
duplex-mode: | ||
_process: not_implemented | ||
enable-flow-control: | ||
_process: not_implemented | ||
mac-address: | ||
_process: not_implemented | ||
port-speed: | ||
_process: not_implemented | ||
state: | ||
_process: not_implemented |
23 changes: 23 additions & 0 deletions
23
napalm_yang/mappings/junos/parsers/config/openconfig-vlan/switched-vlan.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
metadata: | ||
processor: JunosConfig | ||
pre_processor: openconfig_vlan_switched_vlan | ||
|
||
switched-vlan: | ||
_process: | ||
- path: "switched-vlan.config" | ||
config: | ||
_process: unnecessary | ||
interface-mode: | ||
_process: | ||
- path: "interface-mode" | ||
access-vlan: | ||
_process: | ||
- path: "access-vlans" | ||
native-vlan: | ||
_process: not_implemented | ||
trunk-vlans: | ||
_process: | ||
- path: "trunk-vlans" | ||
state: | ||
_process: not_implemented |
20 changes: 20 additions & 0 deletions
20
napalm_yang/mappings/junos/translators/openconfig-if-ethernet/ethernet.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
metadata: | ||
processor: XMLTranslator | ||
|
||
ethernet: | ||
_process: unnecessary | ||
config: | ||
_process: unnecessary | ||
auto-negotiate: | ||
_process: not_implemented | ||
duplex-mode: | ||
_process: not_implemented | ||
enable-flow-control: | ||
_process: not_implemented | ||
mac-address: | ||
_process: not_implemented | ||
port-speed: | ||
_process: not_implemented | ||
state: | ||
_process: not_implemented |
26 changes: 26 additions & 0 deletions
26
napalm_yang/mappings/junos/translators/openconfig-vlan/switched-vlan.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
metadata: | ||
processor: JunosTranslator | ||
|
||
switched-vlan: | ||
_process: | ||
- gate: true | ||
when: "{{ not model.config.interface_mode }}" | ||
- in: subinterface.0 | ||
container: family/ethernet-switching | ||
config: | ||
_process: unnecessary | ||
access-vlan: | ||
_process: | ||
- element: vlan/members | ||
interface-mode: | ||
_process: | ||
- element: interface-mode | ||
value: "{{ model|lower }}" | ||
native-vlan: | ||
_process: not_implemented | ||
trunk-vlans: | ||
_process: | ||
- function: openconfig_vlan_vlan_members | ||
state: | ||
_process: not_implemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
from napalm_yang.parsers.jsonp import JSONParser | ||
from napalm_yang.parsers.junos_config import JunosConfig | ||
from napalm_yang.parsers.text import TextParser | ||
from napalm_yang.parsers.text_tree import TextTree | ||
from napalm_yang.parsers.xml import XMLParser | ||
|
||
from napalm_yang.translators.text import TextTranslator | ||
from napalm_yang.translators.junos import JunosTranslator | ||
from napalm_yang.translators.xml import XMLTranslator | ||
|
||
|
||
def get_parser(parser): | ||
parsers = { | ||
"JSONParser": JSONParser, | ||
"JunosConfig": JunosConfig, | ||
"TextParser": TextParser, | ||
"TextTree": TextTree, | ||
"XMLParser": XMLParser, | ||
"TextTranslator": TextTranslator, | ||
"JunosTranslator": JunosTranslator, | ||
"XMLTranslator": XMLTranslator, | ||
} | ||
return parsers[parser] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from napalm_yang.jinja_filters.vlan_filters import vlan_range_to_oc | ||
from napalm_yang.parsers.base import _resolve_path | ||
from napalm_yang.parsers.jsonp import JSONParser | ||
|
||
|
||
class JunosConfig(JSONParser): | ||
|
||
def openconfig_vlan_switched_vlan(self, parser): | ||
result = {"switched-vlan": {"config": {}}} | ||
config = result["switched-vlan"]["config"] | ||
|
||
try: | ||
d = _resolve_path(parser.bookmarks["parent"], ["unit", "family", "ethernet-switching"]) | ||
except Exception: | ||
return | ||
vlans = _resolve_path(d, ["vlan", "members"]) | ||
if isinstance(vlans, list): | ||
vlans = ",".join([v["#text"] for v in vlans]) | ||
else: | ||
vlans = vlans["#text"] | ||
if vlans == "all": | ||
vlans = "1-4094" | ||
|
||
if d["interface-mode"]["#text"] == "trunk": | ||
config["interface-mode"] = "TRUNK" | ||
config["trunk-vlans"] = vlan_range_to_oc(vlans) | ||
else: | ||
config["interface-mode"] = "ACCESS" | ||
config["access-vlans"] = vlans | ||
parser.bookmarks["parent"] = result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ast | ||
|
||
from napalm_yang.translators.xml import XMLTranslator | ||
|
||
from lxml import etree | ||
|
||
|
||
class JunosTranslator(XMLTranslator): | ||
|
||
def openconfig_vlan_vlan_members(self, attribute, model, | ||
other, mapping, translation, bookmarks): | ||
vlans = ast.literal_eval(str(model)) | ||
vlan_xml = translation.find("vlan") or etree.SubElement(translation, "vlan") | ||
for v in vlans: | ||
t = etree.SubElement(vlan_xml, "members") | ||
v = str(v) | ||
if v == "1..4094": | ||
v = "all" | ||
t.text = str(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
test/integration/test_profiles/junos/openconfig-interfaces/config/l2_ports/candidate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{ | ||
"interfaces": { | ||
"interface": { | ||
"xe-0/0/0": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "xe-0/0/0", | ||
"type": "ethernetCsmacd" | ||
}, | ||
"ethernet": { | ||
"switched-vlan": { | ||
"config": { | ||
"interface-mode": "TRUNK", | ||
"trunk-vlans": [ | ||
"10", | ||
"20" | ||
] | ||
} | ||
} | ||
}, | ||
"name": "xe-0/0/0", | ||
"routed-vlan": { | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
}, | ||
"subinterfaces": { | ||
"subinterface": { | ||
"0": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "0" | ||
}, | ||
"index": "0", | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"xe-0/0/1": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "xe-0/0/1", | ||
"type": "ethernetCsmacd" | ||
}, | ||
"ethernet": { | ||
"switched-vlan": { | ||
"config": { | ||
"interface-mode": "TRUNK", | ||
"trunk-vlans": [ | ||
"10", | ||
"20" | ||
] | ||
} | ||
} | ||
}, | ||
"name": "xe-0/0/1", | ||
"routed-vlan": { | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
}, | ||
"subinterfaces": { | ||
"subinterface": { | ||
"0": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "0" | ||
}, | ||
"index": "0", | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"xe-0/0/3": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "xe-0/0/3", | ||
"type": "ethernetCsmacd" | ||
}, | ||
"ethernet": { | ||
"switched-vlan": { | ||
"config": { | ||
"interface-mode": "TRUNK", | ||
"trunk-vlans": [ | ||
10, | ||
20, | ||
100 | ||
] | ||
} | ||
} | ||
}, | ||
"name": "xe-0/0/3", | ||
"routed-vlan": { | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
}, | ||
"subinterfaces": { | ||
"subinterface": { | ||
"0": { | ||
"config": { | ||
"enabled": 1, | ||
"name": "0" | ||
}, | ||
"index": "0", | ||
"ipv4": { | ||
"config": { | ||
"enabled": 0 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.