Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #40 from napalm-automation/create_dummy_templates
Browse files Browse the repository at this point in the history
Adding simple script to create dummy mapping files
  • Loading branch information
dbarrosop committed Apr 28, 2017
2 parents 8f845d3 + 80f8442 commit 015dd39
Show file tree
Hide file tree
Showing 53 changed files with 11,910 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ models_openconfig:
submodule:
git submodule update --init --recursive

.PHONY: templates
templates:
rm -rf napalm_yang/mappings/dummy/
python generate_templates.py

.PHONY: tests
tests:
python test.py
py.test
104 changes: 104 additions & 0 deletions generate_templates.py
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
metadata:
processor: unset

secondary:
_process: not_implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
metadata:
processor: unset

aggregate-id:
_process: not_implemented
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
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
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
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
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
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
Loading

0 comments on commit 015dd39

Please sign in to comment.