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.
Merge pull request #40 from napalm-automation/create_dummy_templates
Adding simple script to create dummy mapping files
- Loading branch information
Showing
53 changed files
with
11,910 additions
and
1 deletion.
There are no files selected for viewing
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,104 @@ | ||
from collections import defaultdict | ||
|
||
import os | ||
|
||
|
||
import napalm_yang | ||
|
||
import yaml | ||
|
||
models = [ | ||
napalm_yang.models.openconfig_network_instance, | ||
napalm_yang.models.openconfig_interfaces, | ||
napalm_yang.models.openconfig_platform, | ||
napalm_yang.models.openconfig_vlan, | ||
] | ||
|
||
profile = "dummy" | ||
|
||
|
||
def nested_dd(): | ||
return defaultdict(nested_dd) | ||
|
||
|
||
def process(model, r_config, r_state): | ||
if model._yang_type in ("container", ): | ||
ctr = model | ||
elif model._yang_type in ("list", None): | ||
ctr = model._contained_class() | ||
else: | ||
if model._is_config or model._yang_name == "config": | ||
r_config[model._yang_name] = {"_process": "not_implemented"} | ||
else: | ||
r_state[model._yang_name] = {"_process": "not_implemented"} | ||
return | ||
|
||
for k, v in ctr: | ||
if model._yang_name == "config": | ||
rr_config = r_config[model._yang_name] | ||
rr_config["_process"] = "not_implemented" | ||
rr_state = r_state | ||
elif v._is_config: | ||
rr_config = r_config[model._yang_name] | ||
rr_config["_process"] = "not_implemented" | ||
rr_state = r_state[model._yang_name] | ||
rr_state["_process"] = "not_implemented" | ||
else: | ||
rr_config = r_config | ||
rr_state = r_state[model._yang_name] | ||
rr_state["_process"] = "not_implemented" | ||
|
||
process_module(v, model._defining_module, rr_config, rr_state) | ||
|
||
|
||
def process_module(model, module, r_config=None, r_state=None): | ||
if model._defining_module != module: | ||
r_config = result["config"][os.path.join(model._defining_module, | ||
"{}.yaml".format(model._yang_name))] | ||
r_state = result["state"][os.path.join(model._defining_module, | ||
"{}.yaml".format(model._yang_name))] | ||
|
||
process(model, r_config, r_state) | ||
|
||
|
||
def ddict2dict(d): | ||
for k, v in d.items(): | ||
if isinstance(v, dict): | ||
d[k] = ddict2dict(v) | ||
return dict(d) | ||
|
||
|
||
def main(): | ||
global result | ||
result = nested_dd() | ||
|
||
for model in models: | ||
m = model() | ||
for _, v in m: | ||
process_module(v, None, result["config"], result["state"]) | ||
|
||
for mode, data in result.items(): | ||
for module, model in data.items(): | ||
module, filename = module.split("/") | ||
|
||
for action in ["parsers", "translators"]: | ||
if action == "translators" and mode == "state": | ||
continue | ||
elif action == "translators": | ||
directory = os.path.join("napalm_yang", "mappings", "dummy", action, module) | ||
else: | ||
directory = os.path.join("napalm_yang", "mappings", "dummy", action, | ||
mode, module) | ||
|
||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
model = ddict2dict(model) | ||
metadata = "---\nmetadata:\n processor: unset\n\n" | ||
|
||
with open(os.path.join(directory, filename), 'w+') as f: | ||
f.write(metadata + yaml.safe_dump(model, indent=4, default_flow_style=False)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
6 changes: 6 additions & 0 deletions
6
napalm_yang/mappings/dummy/parsers/config/napalm-if-ip/secondary.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,6 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
secondary: | ||
_process: not_implemented |
6 changes: 6 additions & 0 deletions
6
napalm_yang/mappings/dummy/parsers/config/openconfig-if-aggregate/aggregate-id.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,6 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
aggregate-id: | ||
_process: not_implemented |
12 changes: 12 additions & 0 deletions
12
napalm_yang/mappings/dummy/parsers/config/openconfig-if-aggregate/aggregation.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,12 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
aggregation: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
lag-type: | ||
_process: not_implemented | ||
min-links: | ||
_process: not_implemented |
18 changes: 18 additions & 0 deletions
18
napalm_yang/mappings/dummy/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,18 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
ethernet: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
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 |
16 changes: 16 additions & 0 deletions
16
napalm_yang/mappings/dummy/parsers/config/openconfig-if-ip-ext/autoconf.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,16 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
autoconf: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
create-global-addresses: | ||
_process: not_implemented | ||
create-temporary-addresses: | ||
_process: not_implemented | ||
temporary-preferred-lifetime: | ||
_process: not_implemented | ||
temporary-valid-lifetime: | ||
_process: not_implemented |
80 changes: 80 additions & 0 deletions
80
napalm_yang/mappings/dummy/parsers/config/openconfig-if-ip/ipv4.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,80 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
ipv4: | ||
_process: not_implemented | ||
addresses: | ||
_process: not_implemented | ||
address: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
prefix-length: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
vrrp: | ||
_process: not_implemented | ||
vrrp-group: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
accept-mode: | ||
_process: not_implemented | ||
advertisement-interval: | ||
_process: not_implemented | ||
preempt: | ||
_process: not_implemented | ||
preempt-delay: | ||
_process: not_implemented | ||
priority: | ||
_process: not_implemented | ||
virtual-address: | ||
_process: not_implemented | ||
virtual-router-id: | ||
_process: not_implemented | ||
interface-tracking: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
priority-decrement: | ||
_process: not_implemented | ||
track-interface: | ||
_process: not_implemented | ||
virtual-router-id: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
mtu: | ||
_process: not_implemented | ||
neighbors: | ||
_process: not_implemented | ||
neighbor: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
link-layer-address: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
unnumbered: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
interface-ref: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
interface: | ||
_process: not_implemented | ||
subinterface: | ||
_process: not_implemented |
84 changes: 84 additions & 0 deletions
84
napalm_yang/mappings/dummy/parsers/config/openconfig-if-ip/ipv6.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,84 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
ipv6: | ||
_process: not_implemented | ||
addresses: | ||
_process: not_implemented | ||
address: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
prefix-length: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
vrrp: | ||
_process: not_implemented | ||
vrrp-group: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
accept-mode: | ||
_process: not_implemented | ||
advertisement-interval: | ||
_process: not_implemented | ||
preempt: | ||
_process: not_implemented | ||
preempt-delay: | ||
_process: not_implemented | ||
priority: | ||
_process: not_implemented | ||
virtual-address: | ||
_process: not_implemented | ||
virtual-link-local: | ||
_process: not_implemented | ||
virtual-router-id: | ||
_process: not_implemented | ||
interface-tracking: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
priority-decrement: | ||
_process: not_implemented | ||
track-interface: | ||
_process: not_implemented | ||
virtual-router-id: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
dup-addr-detect-transmits: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
mtu: | ||
_process: not_implemented | ||
neighbors: | ||
_process: not_implemented | ||
neighbor: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
link-layer-address: | ||
_process: not_implemented | ||
ip: | ||
_process: not_implemented | ||
unnumbered: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
interface-ref: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
interface: | ||
_process: not_implemented | ||
subinterface: | ||
_process: not_implemented |
46 changes: 46 additions & 0 deletions
46
napalm_yang/mappings/dummy/parsers/config/openconfig-interfaces/interfaces.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,46 @@ | ||
--- | ||
metadata: | ||
processor: unset | ||
|
||
interfaces: | ||
_process: not_implemented | ||
interface: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
description: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
mtu: | ||
_process: not_implemented | ||
name: | ||
_process: not_implemented | ||
type: | ||
_process: not_implemented | ||
hold-time: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
down: | ||
_process: not_implemented | ||
up: | ||
_process: not_implemented | ||
name: | ||
_process: not_implemented | ||
subinterfaces: | ||
_process: not_implemented | ||
subinterface: | ||
_process: not_implemented | ||
config: | ||
_process: not_implemented | ||
description: | ||
_process: not_implemented | ||
enabled: | ||
_process: not_implemented | ||
index: | ||
_process: not_implemented | ||
name: | ||
_process: not_implemented | ||
index: | ||
_process: not_implemented |
Oops, something went wrong.