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

Commit d7d1d65

Browse files
authored
Merge pull request #25 from napalm-automation/develop
Release beta 0.0.4
2 parents 98ded5c + e62e141 commit d7d1d65

File tree

9 files changed

+820
-72
lines changed

9 files changed

+820
-72
lines changed

interactive_demo/tutorial.ipynb

Lines changed: 778 additions & 38 deletions
Large diffs are not rendered by default.

napalm_yang/jinja_filters/ip_filters.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ def filters():
99

1010

1111
def netmask_to_cidr(value):
12-
""" Converts a network mask to it's CIDR value. """
12+
"""
13+
Converts a network mask to it's CIDR value.
14+
15+
Examples:
16+
>>> "{{ '255.255.255.0'|netmask_to_cidr }}" -> "24"
17+
"""
1318
return netaddr.IPAddress(value).netmask_bits()
1419

1520

1621
def cidr_to_netmask(value):
17-
""" Converts a CIDR prefix-length to a network mask. """
22+
"""
23+
Converts a CIDR prefix-length to a network mask.
24+
25+
Examples:
26+
>>> "{{ '24'|cidr_to_netmask }}" -> "255.255.255.0"
27+
"""
1828
return netaddr.IPNetwork("1.1.1.1/{}".format(value)).netmask

napalm_yang/mappings/eos/translators/openconfig-if-ip/ipv4.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ ipv4:
1818
addresses:
1919
_translation: unnecessary
2020
address:
21-
_translation: unnecessary
21+
_translation:
22+
mode: container
23+
key_value: " ip address {{ model.config.ip }}/{{ model.config.prefix_length }} {{ 'secondary' if model.config.secondary else '' }}\n"
24+
negate: " default ip address {{ model.config.ip }}/{{ model.config.prefix_length }} {{ 'secondary' if model.config.secondary else '' }}\n"
25+
replace: false
2226
ip:
2327
_translation: unnecessary
2428
config:
2529
_translation: unnecessary
2630
ip:
2731
_translation: unnecessary
2832
prefix_length:
29-
_translation:
30-
- mode: element
31-
value: " ip address {{ model._parent.ip }}/{{ model }} {{ 'secondary' if model._parent.secondary else '' }}\n"
32-
negate: " default ip address {{ model._parent.ip }}/{{ model }} {{ 'secondary' if model._parent.secondary else '' }}\n"
33+
_translation: unnecessary
3334
vrrp:
3435
_translation: not_implemented
3536
vrrp_group:

napalm_yang/mappings/ios/translators/openconfig-if-ip/ipv4.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ ipv4:
1919
_translation: unnecessary
2020
address:
2121
_translation:
22-
mode: default_only
22+
mode: container
23+
key_value: " ip address {{ model.config.ip }} {{ model.config.prefix_length|cidr_to_netmask }}{{ ' secondary' if model.config.secondary else '' }}\n"
2324
negate: " default ip address {{ model.config.ip }} {{ model.config.prefix_length|cidr_to_netmask }}{{ ' secondary' if model.config.secondary else '' }}\n"
25+
replace: false
2426
ip:
2527
_translation: unnecessary
2628
config:
2729
_translation: unnecessary
2830
ip:
2931
_translation: unnecessary
3032
prefix_length:
31-
_translation:
32-
- mode: element
33-
value: " ip address {{ model._parent.ip }} {{ model|cidr_to_netmask }}{{ ' secondary' if model._parent.secondary else '' }}\n"
33+
_translation: unnecessary
3434
vrrp:
3535
_translation: not_implemented
3636
vrrp_group:

napalm_yang/translator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def _translate_list(self, attribute, model, mapping, translation, other):
125125
translation_point)
126126

127127
if et is None:
128-
logger.info("Skipping {} as it seems to be not implemented".format(attribute))
129-
break
128+
logger.info("Skipping {} as not implemented or objects are equal".format(attribute))
129+
continue
130130

131131
self.bookmarks[attribute][key] = et
132132
self.bookmarks["parent"] = et

napalm_yang/translators/text.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from lxml import etree
66

7+
import napalm_yang
8+
79

810
class TextTranslator(XMLTranslator):
911

@@ -30,11 +32,19 @@ def _parse_leaf_element(self, attribute, model, other, mapping, translation):
3032
mapping["element"] = "command"
3133
super()._parse_leaf_element(attribute, model, other, mapping, translation, force)
3234

33-
def _init_element_default_only(self, attribute, model, other, mapping, translation):
34-
# There is nothing to do here, default_only action is only useful to remove lists
35-
return translation
36-
3735
def _init_element_container(self, attribute, model, other, mapping, translation):
36+
if other is not None:
37+
if not napalm_yang.utils.diff(model, other) and not self.replace:
38+
# If objects are equal we return None as that aborts translating
39+
# the rest of the object
40+
return
41+
42+
if not model._changed() and other is not None and not self.replace:
43+
print(attribute, model, other)
44+
mapping["key_value"] = mapping["negate"]
45+
if not model._changed() and other is not None and self.replace:
46+
return translation
47+
3848
mapping["key_element"] = "command"
3949
mapping["container"] = model._yang_name
4050
return super()._init_element_container(attribute, model, other, mapping, translation)
@@ -45,6 +55,9 @@ def _init_element_container(self, attribute, model, other, mapping, translation)
4555
# return super()._init_element_container(attribute, model, other, mapping, translation)
4656

4757
def _default_element_container(self, mapping, translation, replacing):
58+
if (replacing or self.replace) and not mapping.get("replace", True):
59+
return
60+
4861
if not self.merge and not self.replace:
4962
return
5063

@@ -54,11 +67,6 @@ def _default_element_container(self, mapping, translation, replacing):
5467
e = etree.SubElement(translation, "command")
5568
e.text = mapping["negate"]
5669

57-
def _default_element_default_only(self, mapping, translation, replacing):
58-
if self.replace:
59-
return
60-
self._default_element_container(mapping, translation, replacing)
61-
6270
def _xml_to_text(self, xml, text=""):
6371
for element in xml:
6472
if element.tag == "command":

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="napalm-yang",
15-
version="0.0.3",
15+
version="0.0.4",
1616
packages=find_packages(),
1717
author="David Barroso",
1818
author_email="dbarrosop@dravetech.com",
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
interface Port-channel1
2-
interface Port-channel1.1
3-
interface Loopback1
41
interface GigabitEthernet1
52
default description
63
interface GigabitEthernet2
@@ -9,5 +6,3 @@ interface GigabitEthernet2.1
96
no encapsulation dot1q
107
ip address 192.168.20.1 255.255.255.0 secondary
118
default ip address 172.20.0.1 255.255.255.0 secondary
12-
interface GigabitEthernet2.2
13-
interface GigabitEthernet3
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
interface Port-Channel1
22
default mtu
3-
interface Port-Channel1.1
4-
interface Ethernet1
5-
interface Ethernet2
6-
interface Ethernet2.1
7-
interface Ethernet2.2
8-
interface Management1
93
interface Loopback0
104
description new loopback
115
no interface Loopback1

0 commit comments

Comments
 (0)