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

Commit

Permalink
Now you can have a closing steatement for list elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Apr 9, 2017
1 parent a525f02 commit 916ae8a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interfaces:
mode: container
key_value: "interface {{ interface_key }}\n"
negate: "{{ 'no' if interface_key[0:4] in ['Port', 'Loop'] else 'default' }} interface {{ interface_key }}\n"
end: " exit\n"
name:
_process: unnecessary
hold-time:
Expand Down Expand Up @@ -49,6 +50,7 @@ interfaces:
key_value: "interface {{ interface_key}}.{{ subinterface_key }}\n"
negate: "no interface {{ interface_key}}.{{ subinterface_key }}\n"
in: "interfaces"
end: " exit\n"
index:
_process: unnecessary
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interfaces:
mode: container
key_value: "interface {{ interface_key }}\n"
negate: "{{ 'no' if interface_key[0:4] in ['Port', 'Loop'] else 'default' }} interface {{ interface_key }}\n"
end: " exit\n"
name:
_process: unnecessary
hold-time:
Expand Down Expand Up @@ -51,6 +52,7 @@ interfaces:
key_value: "interface {{ interface_key}}.{{ subinterface_key }}\n"
negate: "no interface {{ interface_key}}.{{ subinterface_key }}\n"
in: "interfaces"
end: " exit\n"
index:
_process: unnecessary
config:
Expand Down
11 changes: 9 additions & 2 deletions napalm_yang/translators/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ def _init_element_container(self, attribute, model, other, mapping, translation)
return

if not model._changed() and other is not None and not self.replace:
print(attribute, model, other)
mapping["key_value"] = mapping["negate"]
if not model._changed() and other is not None and self.replace:
return translation

mapping["key_element"] = "command"
mapping["container"] = model._yang_name
return super()._init_element_container(attribute, model, other, mapping, translation)

t = super()._init_element_container(attribute, model, other, mapping, translation)

end = mapping.get("end", "")
if end and t is not None:
e = etree.SubElement(translation, "command")
e.text = end

return t

# def _parse_container_container(self, attribute, model, other, mapping, translation):
# mapping["key_element"] = "container"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
interface GigabitEthernet1
default description
exit
interface GigabitEthernet2
mtu 9000
exit
interface GigabitEthernet2.1
no encapsulation dot1q
ip address 192.168.20.1 255.255.255.0 secondary
default ip address 172.20.0.1 255.255.255.0 secondary
exit
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ interface Port-channel1
no switchport
description blah
mtu 9000
exit
no interface Port-channel1.1
interface Port-channel1.1
exit
no interface Loopback1
interface Loopback1
description a loopback
exit
default interface GigabitEthernet1
interface GigabitEthernet1
no switchport
mtu 1500
exit
default interface GigabitEthernet2
interface GigabitEthernet2
no switchport
Expand All @@ -22,18 +26,22 @@ interface GigabitEthernet2
shutdown
description so much oc
mtu 9000
exit
no interface GigabitEthernet2.1
interface GigabitEthernet2.1
ip address 192.168.20.1 255.255.255.0 secondary
ip address 192.168.1.1 255.255.255.0
description another subiface
exit
no interface GigabitEthernet2.2
interface GigabitEthernet2.2
encapsulation dot1q 2
ip address 192.168.2.1 255.255.255.0
description asdasdasd
exit
default interface GigabitEthernet3
interface GigabitEthernet3
no switchport
shutdown
mtu 1500
exit
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ interface Port-channel1
no switchport
description blah
mtu 9000
exit
interface Port-channel1.1
exit
interface Loopback1
description a loopback
exit
interface GigabitEthernet1
no switchport
description This is a description
mtu 1500
exit
interface GigabitEthernet2
no switchport
ip address 192.168.0.1 255.255.255.0
Expand All @@ -18,16 +22,20 @@ interface GigabitEthernet2
shutdown
description so much oc
mtu 1500
exit
interface GigabitEthernet2.1
encapsulation dot1q 1
ip address 172.20.0.1 255.255.255.0 secondary
ip address 192.168.1.1 255.255.255.0
description another subiface
exit
interface GigabitEthernet2.2
encapsulation dot1q 2
ip address 192.168.2.1 255.255.255.0
description asdasdasd
exit
interface GigabitEthernet3
no switchport
shutdown
mtu 1500
exit
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
interface Port-Channel1
default mtu
exit
interface Loopback0
description new loopback
exit
no interface Loopback1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ interface Port-Channel1
no switchport
no switchport
description blah
exit
no interface Port-Channel1.1
interface Port-Channel1.1
exit
default interface Ethernet1
interface Ethernet1
description This is a description
exit
default interface Ethernet2
interface Ethernet2
no switchport
Expand All @@ -17,22 +20,27 @@ interface Ethernet2
shutdown
description so much oc
mtu 1500
exit
no interface Ethernet2.1
interface Ethernet2.1
encapsulation dot1q vlan 1
ip address 192.168.1.1/24
ip address 172.20.0.1/24 secondary
description another subiface
exit
no interface Ethernet2.2
interface Ethernet2.2
encapsulation dot1q vlan 2
ip address 192.168.2.1/24
description asdasdasd
exit
default interface Management1
interface Management1
ip address 10.0.2.15/24
mtu 1500
exit
no interface Loopback0
interface Loopback0
description new loopback
exit
no interface Loopback1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ interface et1
ip address 192.168.1.1/24
description Uplink1
mtu 9000
exit
interface et2
ip address 192.168.2.1/24
description Uplink2
mtu 9000
exit

0 comments on commit 916ae8a

Please sign in to comment.