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 #27 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 0.0.5
  • Loading branch information
dbarrosop committed Mar 28, 2017
2 parents d7d1d65 + c9cdf79 commit def0cf6
Show file tree
Hide file tree
Showing 14 changed files with 8,378 additions and 44 deletions.
581 changes: 579 additions & 2 deletions interactive_demo/tutorial.ipynb

Large diffs are not rendered by default.

43 changes: 38 additions & 5 deletions napalm_yang/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ def load_dict(self, data, overwrite=False):
attr = getattr(self, k)
pybindJSONDecoder.load_json(v, None, None, obj=attr, overwrite=overwrite)

def parse_config(self, device=None, profile=None, config=None):
def parse_config(self, device=None, profile=None, native=None):
"""
Parse native configuration and load it into the corresponding models. Only models
that have been added to the root object will be parsed.
If ``config`` is passed to the method that's what we will parse, otherwise, we will use the
If ``native`` is passed to the method that's what we will parse, otherwise, we will use the
``device`` to retrieve it.
Args:
device (NetworkDriver): Device to load the configuration from.
profile (list): Profiles that the device supports. If no ``profile`` is passed it will
be read from ``device``.
config (string): Configuration to parse.
native (list of strings): Native configuration to parse.
Examples:
Expand All @@ -160,11 +160,44 @@ def parse_config(self, device=None, profile=None, config=None):
>>>
>>> running_config = napalm_yang.base.Root()
>>> running_config.add_model(napalm_yang.models.openconfig_interfaces)
>>> running_config.parse_config(config=config, profile="junos")
>>> running_config.parse_config(native=config, profile="junos")
"""

for k, v in self:
parser = Parser(v, device=device, profile=profile, config=config, is_config=True)
parser = Parser(v, device=device, profile=profile, native=native, is_config=True)
parser.parse()

def parse_state(self, device=None, profile=None, native=None):
"""
Parse native state and load it into the corresponding models. Only models
that have been added to the root object will be parsed.
If ``native`` is passed to the method that's what we will parse, otherwise, we will use the
``device`` to retrieve it.
Args:
device (NetworkDriver): Device to load the configuration from.
profile (list): Profiles that the device supports. If no ``profile`` is passed it will
be read from ``device``.
native (list string): Native output to parse.
Examples:
>>> # Load from device
>>> state = napalm_yang.base.Root()
>>> state.add_model(napalm_yang.models.openconfig_interfaces)
>>> state.parse_config(device=d)
>>> # Load from file
>>> with open("junos.state", "r") as f:
>>> state_data = f.read()
>>>
>>> state = napalm_yang.base.Root()
>>> state.add_model(napalm_yang.models.openconfig_interfaces)
>>> state.parse_config(native=state_data, profile="junos")
"""
for k, v in self:
parser = Parser(v, device=device, profile=profile, native=native, is_config=False)
parser.parse()

def translate_config(self, profile, merge=None, replace=None):
Expand Down
2 changes: 1 addition & 1 deletion napalm_yang/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def read_yang_map(yang_prefix, attribute, profile, parser_path):
try:
filepath = find_yang_file(p, filename, parser_path)
found = True
logger.debug("Found on profile: {}".format(p))
logger.debug("Found on profile: {}, {}".format(p, filepath))
except IOError:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interfaces:
_parse:
mode: block
regexp: "(?P<block>interface (?P<key>(\\w|-)*\\d+)\n(?:.|\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
from: "{{ bookmarks.interfaces.0 }}"
name:
_parse: unnecessary
hold_time:
Expand Down Expand Up @@ -58,7 +58,7 @@ interfaces:
_parse:
mode: block
regexp: "(?P<block>interface {{interface_key}}\\.(?P<key>\\d+)\\n(?:.|\\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
from: "{{ bookmarks.interfaces.0 }}"
index:
_parse: unnecessary
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interfaces:
_parse:
mode: block
regexp: "(?P<block>interface (?P<key>(\\w|-)*\\d+)\n(?:.|\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
from: "{{ bookmarks.interfaces.0 }}"
name:
_parse: unnecessary
hold_time:
Expand Down Expand Up @@ -59,7 +59,7 @@ interfaces:
_parse:
mode: block
regexp: "(?P<block>interface {{interface_key}}\\.(?P<key>\\d+)\\n(?:.|\\n)*?^!$)"
from: "{{ bookmarks.interfaces }}"
from: "{{ bookmarks.interfaces.0 }}"
index:
_parse: unnecessary
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interfaces:
mode: xpath
xpath: "interfaces/interface"
key: name
from: "{{ bookmarks.interfaces }}"
from: "{{ bookmarks.interfaces.0 }}"
name:
_parse: unnecessary
hold_time:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
---
metadata:
parser: XMLParser
execute:
- method: _rpc
args:
get: "<get-interface-information><extensive/></get-interface-information>"

interfaces:
_parse: not_implemented
interface:
_parse:
mode: xpath
xpath: "physical-interface"
key: name
from: "{{ bookmarks.interfaces.0 }}"
config:
_parse: unnecessary
hold_time:
_parse: not_implemented
config:
_parse: unnecessary
state:
_parse: not_implemented
down:
_parse: not_implemented
up:
_parse: not_implemented
state:
_parse: not_implemented
admin_status:
_parse:
mode: map
xpath: "admin-status"
from: "{{ bookmarks['parent'] }}"
map:
up: UP
down: DOWN
description:
_parse:
mode: xpath
xpath: "description"
from: "{{ bookmarks['parent'] }}"
enabled:
_parse:
mode: map
xpath: "admin-status"
from: "{{ bookmarks['parent'] }}"
map:
up: true
down: false
ifindex:
_parse:
mode: xpath
xpath: "snmp-index"
from: "{{ bookmarks['parent'] }}"
last_change:
_parse:
mode: xpath
xpath: "interface-flapped"
attribute: "seconds"
from: "{{ bookmarks['parent'] }}"
mtu:
_parse:
mode: xpath
xpath: "mtu"
regexp: "(?P<value>\\d+)" # Someone thought mixing strings and ints was a good idea
from: "{{ bookmarks['parent'] }}"
name:
_parse: unnecessary
oper_status:
_parse:
mode: map
xpath: "oper-status"
from: "{{ bookmarks['parent'] }}"
map:
up: UP
down: DOWN
type:
_parse:
mode: map
xpath: "if-type"
from: "{{ bookmarks['parent'] }}"
map:
GRE: tunnel
IPIP: tunnel
Logical-tunnel: tunnel
Multicast-GRE: tunnel
Secure-Tunnel: tunnel
Ethernet: ethernetCsmacd
Loopback: softwareLoopback
VLAN: l2vlan
Adaptive-Services: null
Software-Pseudo: null
PIMD: null
PIME: null
PPPoE: null
counters:
_parse: not_implemented
in_broadcast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/input-broadcasts"
from: "{{ bookmarks['parent'] }}"
in_discards:
_parse:
mode: xpath
xpath: "input-error-list/input-discards"
from: "{{ bookmarks['parent'] }}"
in_errors:
_parse:
mode: xpath
xpath: "input-error-list/input-errors"
from: "{{ bookmarks['parent'] }}"
in_multicast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/input-multicasts"
from: "{{ bookmarks['parent'] }}"
in_octets:
_parse: not_implemented
in_unicast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/input-unicasts"
from: "{{ bookmarks['parent'] }}"
in_unknown_protos:
_parse: not_implemented
last_clear:
_parse: not_implemented
out_broadcast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/output-broadcasts"
from: "{{ bookmarks['parent'] }}"
out_discards:
_parse: not_implemented
out_errors:
_parse:
mode: xpath
xpath: "output-error-list/output-errors"
from: "{{ bookmarks['parent'] }}"
out_multicast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/output-multicasts"
from: "{{ bookmarks['parent'] }}"
out_octets:
_parse: not_implemented
out_unicast_pkts:
_parse:
mode: xpath
xpath: "ethernet-mac-statistics/output-unicasts"
from: "{{ bookmarks['parent'] }}"
subinterfaces:
_parse: unnecessary
subinterface:
_parse:
mode: xpath
xpath: "logical-interface"
from: "{{ bookmarks['parent'] }}"
index:
_parse: unnecessary
config:
_parse: unnecessary
state:
_parse: not_implemented
index:
_parse: not_implemented
description:
_parse:
mode: xpath
xpath: "description"
from: "{{ bookmarks['parent'] }}"
enabled:
_parse: not_implemented
admin_status:
_parse: not_implemented
ifindex:
_parse:
mode: xpath
xpath: "snmp-index"
from: "{{ bookmarks['parent'] }}"
last_change:
_parse: not_implemented
name:
_parse:
mode: value
value: "{{ subinterface_key }}"
oper_status:
_parse: not_implemented
counters:
_parse: not_implemented
in_broadcast_pkts:
_parse: not_implemented
in_discards:
_parse: not_implemented
in_errors:
_parse: not_implemented
in_multicast_pkts:
_parse: not_implemented
in_octets:
_parse: not_implemented
in_unicast_pkts:
_parse: not_implemented
in_unknown_protos:
_parse: not_implemented
last_clear:
_parse: not_implemented
out_broadcast_pkts:
_parse: not_implemented
out_discards:
_parse: not_implemented
out_errors:
_parse: not_implemented
out_multicast_pkts:
_parse: not_implemented
out_octets:
_parse: not_implemented
out_unicast_pkts:
_parse: not_implemented
Loading

0 comments on commit def0cf6

Please sign in to comment.