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 #23 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release beta 0.0.3
  • Loading branch information
dbarrosop committed Mar 27, 2017
2 parents 61aa969 + 7661290 commit 98ded5c
Show file tree
Hide file tree
Showing 44 changed files with 4,302 additions and 39 deletions.
10 changes: 8 additions & 2 deletions napalm_yang/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import jinja2

from napalm_yang.jinja_filters import ip_filters

import logging
logger = logging.getLogger("napalm-yang")

Expand Down Expand Up @@ -106,8 +108,12 @@ def resolve_rule(rule, attribute, keys, extra_vars=None, translation_model=None,


def template(string, **kwargs):
template = jinja2.Environment(
env = jinja2.Environment(
undefined=jinja2.StrictUndefined,
keep_trailing_newline=True,
).from_string(string)
)
env.filters.update(ip_filters.filters())

template = env.from_string(string)

return template.render(**kwargs)
Empty file.
18 changes: 18 additions & 0 deletions napalm_yang/jinja_filters/ip_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import netaddr


def filters():
return {
"netmask_to_cidr": netmask_to_cidr,
"cidr_to_netmask": cidr_to_netmask,
}


def netmask_to_cidr(value):
""" Converts a network mask to it's CIDR value. """
return netaddr.IPAddress(value).netmask_bits()


def cidr_to_netmask(value):
""" Converts a CIDR prefix-length to a network mask. """
return netaddr.IPNetwork("1.1.1.1/{}".format(value)).netmask
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vlan:
_translation:
- mode: element
value: " encapsulation dot1q vlan {{ model }}\n"
negate: " default encapsulation dot1q vlan {{ model }}\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
metadata:
prefix: "napalm-ip"
parser: TextParser

secondary:
_parse:
mode: value
value: "{{ extra_vars.secondary != None }}"
82 changes: 82 additions & 0 deletions napalm_yang/mappings/ios/parsers/config/openconfig-if-ip/ipv4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
metadata:
parser: TextParser

ipv4:
_parse: unnecessary
config:
_parse: unnecessary
enabled:
_parse: # TODO look at this one, I think this is different depending on IOS version
mode: is_absent
regexp: "(?P<value>^\\W*switchport$)"
from: "{{ bookmarks['parent'] }}"
mtu:
_parse: not_implemented
addresses:
_parse: unnecessary
address:
_parse:
mode: block
regexp: "(?P<block>ip address (?P<key>(?P<ip>.*)) (?P<prefix>([0-255]|\\.)*)(?P<secondary> secondary)*)$"
from: "{{ bookmarks['parent'] }}"
ip:
_parse: unnecessary
config:
_parse: unnecessary
ip:
_parse:
mode: value
value: "{{ extra_vars.ip }}"
prefix_length:
_parse:
mode: value
value: "{{ extra_vars.prefix|netmask_to_cidr }}"
vrrp:
_parse: not_implemented
vrrp_group:
_parse: not_implemented
virtual_router_id:
_parse: not_implemented
config:
_parse: not_implemented
virtual_address:
_parse: not_implemented
priority:
_parse: not_implemented
preempt:
_parse: not_implemented
advertisement_interval:
_parse: not_implemented
virtual_router_id:
_parse: not_implemented
preempt_delay:
_parse: not_implemented
accept_mode:
_parse: not_implemented
unnumbered:
_parse: not_implemented
config:
_parse: not_implemented
enabled:
_parse: not_implemented
interface_ref:
_parse: not_implemented
config:
_parse: not_implemented
interface:
_parse: not_implemented
subinterface:
_parse: not_implemented
neighbors:
_parse: not_implemented
neighbor:
_parse: not_implemented
ip:
_parse: not_implemented
config:
_parse: not_implemented
ip:
_parse: not_implemented
link_layer_address:
_parse: not_implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
metadata:
parser: TextParser
execute:
- method: cli
args:
commands: ["show running-config all"]
interfaces:
_parse: unnecessary
interface:
_parse:
mode: block
regexp: "(?P<block>interface (?P<key>(\\w|-)*\\d+)\n(?:.|\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
name:
_parse: unnecessary
hold_time:
_parse: not_implemented
config:
_parse: not_implemented
down:
_parse: not_implemented
up:
_parse: not_implemented
config:
_parse: unnecessary
name:
_parse: unnecessary
type:
_parse:
mode: map
regexp: "(?P<value>(\\w|-)*)\\d+"
from: "{{ interface_key }}"
map:
GigabitEthernet: ethernetCsmacd
Management: ethernetCsmacd
Loopback: softwareLoopback
Port-Channel: ieee8023adLag
Port-channel: ieee8023adLag
Vlan: l3ipvlan
enabled:
_parse:
mode: is_present
regexp: "(?P<value>no shutdown)"
from: "{{ bookmarks.interface[interface_key] }}"
description:
_parse:
mode: search
regexp: "description (?P<value>.*)"
from: "{{ bookmarks.interface[interface_key] }}"
mtu:
_parse:
mode: search
regexp: "mtu (?P<value>[0-9]+)"
from: "{{ bookmarks.interface[interface_key] }}"
subinterfaces:
_parse: unnecessary
subinterface:
_parse:
mode: block
regexp: "(?P<block>interface {{interface_key}}\\.(?P<key>\\d+)\\n(?:.|\\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
index:
_parse: unnecessary
config:
_parse: unnecessary
index:
_parse: unnecessary
name:
_parse:
mode: value
value: "{{ interface_key }}.{{ subinterface_key}}"
enabled:
_parse:
mode: is_present
regexp: "(?P<value>no shutdown)"
from: "{{ bookmarks.subinterface[subinterface_key] }}"
description:
_parse:
mode: search
regexp: "description (?P<value>.*)"
from: "{{ bookmarks.subinterface[subinterface_key] }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
metadata:
prefix: "oc-vlan"
parser: TextParser

routed-vlan:
_parse: unnecessary
config:
_parse: unnecessary
enabled:
_parse: unnecessary
vlan:
_parse: unnecessary
14 changes: 14 additions & 0 deletions napalm_yang/mappings/ios/parsers/config/openconfig-vlan/vlan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
metadata:
prefix: "oc-vlan"
parser: TextParser

vlan:
_parse: unnecessary
config:
_parse: unnecessary
vlan_id:
_parse:
mode: search
regexp: "^\\W*encapsulation dot1q (?P<value>[0-9]+)"
from: "{{ bookmarks['parent'] }}"
80 changes: 80 additions & 0 deletions napalm_yang/mappings/ios/translators/openconfig-if-ip/ipv4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
metadata:
translator: TextTranslator

ipv4:
_translation: unnecessary
config:
_translation: unnecessary
enabled:
_translation: # TODO look at this one, I think this is different depending on IOS version
- mode: element
value: " no switchport\n"
negate: " switchport\n"
in: "interface.{{ interface_key }}"
when: "{{ model and interface_key[0:4] not in ['Mana', 'Loop'] }}"
mtu:
_translation: not_implemented
addresses:
_translation: unnecessary
address:
_translation:
mode: default_only
negate: " default ip address {{ model.config.ip }} {{ model.config.prefix_length|cidr_to_netmask }}{{ ' secondary' if model.config.secondary else '' }}\n"
ip:
_translation: unnecessary
config:
_translation: unnecessary
ip:
_translation: unnecessary
prefix_length:
_translation:
- mode: element
value: " ip address {{ model._parent.ip }} {{ model|cidr_to_netmask }}{{ ' secondary' if model._parent.secondary else '' }}\n"
vrrp:
_translation: not_implemented
vrrp_group:
_translation: not_implemented
virtual_router_id:
config:
virtual_address:
_translation: not_implemented
priority:
_translation: not_implemented
preempt:
_translation: not_implemented
advertisement_interval:
_translation: not_implemented
virtual_router_id:
_translation: not_implemented
preempt_delay:
_translation: not_implemented
accept_mode:
_translation: not_implemented
unnumbered:
_translation: not_implemented
config:
_translation: not_implemented
enabled:
_translation: not_implemented
interface_ref:
_translation: not_implemented
config:
_translation: not_implemented
interface:
_translation: not_implemented
subinterface:
_translation: not_implemented
neighbors:
_translation: not_implemented
neighbor:
_translation: not_implemented
ip:
_translation: not_implemented
config:
_translation: not_implemented
ip:
_translation: not_implemented
link_layer_address:
_translation: not_implemented

Loading

0 comments on commit 98ded5c

Please sign in to comment.