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 #31 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 0.0.6
  • Loading branch information
dbarrosop committed Mar 30, 2017
2 parents def0cf6 + 95ba140 commit 1effbcc
Show file tree
Hide file tree
Showing 14 changed files with 872 additions and 14 deletions.
21 changes: 21 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
r 609e192 Load dict now update even on defaults and added compliance_report to Root class
f 90f6a83 Added docstring

# Rebase c9cdf79..90f6a83 onto c9cdf79 (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
226 changes: 217 additions & 9 deletions interactive_demo/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@
" }, \n",
" \"enabled\": True, \n",
" \"ifindex\": 531, \n",
" \"last-change\": 254456, \n",
" \"last-change\": 255203, \n",
" \"mtu\": 1518, \n",
" \"oper-status\": \"DOWN\"\n",
" }, \n",
Expand Down Expand Up @@ -2518,16 +2518,16 @@
" \"in-discards\": 0, \n",
" \"in-errors\": 0, \n",
" \"in-multicast-pkts\": 0, \n",
" \"in-unicast-pkts\": 15740, \n",
" \"in-unicast-pkts\": 16877, \n",
" \"out-broadcast-pkts\": 0, \n",
" \"out-errors\": 0, \n",
" \"out-multicast-pkts\": 0, \n",
" \"out-unicast-pkts\": 14704\n",
" \"out-unicast-pkts\": 15742\n",
" }, \n",
" \"description\": \"management interface\", \n",
" \"enabled\": True, \n",
" \"ifindex\": 507, \n",
" \"last-change\": 257720, \n",
" \"last-change\": 258467, \n",
" \"mtu\": 1400, \n",
" \"oper-status\": \"UP\"\n",
" }, \n",
Expand Down Expand Up @@ -2562,7 +2562,7 @@
" \"description\": \"ge-0/0/1\", \n",
" \"enabled\": False, \n",
" \"ifindex\": 508, \n",
" \"last-change\": 254454, \n",
" \"last-change\": 255201, \n",
" \"mtu\": 1514, \n",
" \"oper-status\": \"DOWN\"\n",
" }\n",
Expand All @@ -2584,7 +2584,7 @@
" }, \n",
" \"enabled\": True, \n",
" \"ifindex\": 509, \n",
" \"last-change\": 257720, \n",
" \"last-change\": 258467, \n",
" \"mtu\": 1514, \n",
" \"oper-status\": \"UP\"\n",
" }\n",
Expand Down Expand Up @@ -2718,7 +2718,7 @@
" \"admin-status\": \"UP\", \n",
" \"enabled\": True, \n",
" \"ifindex\": 518, \n",
" \"last-change\": 257721, \n",
" \"last-change\": 258468, \n",
" \"mtu\": 1504, \n",
" \"oper-status\": \"UP\"\n",
" }\n",
Expand Down Expand Up @@ -2821,7 +2821,7 @@
" }, \n",
" \"enabled\": True, \n",
" \"ifindex\": 515, \n",
" \"last-change\": 257721, \n",
" \"last-change\": 258468, \n",
" \"mtu\": 9192, \n",
" \"oper-status\": \"UP\"\n",
" }, \n",
Expand Down Expand Up @@ -2881,7 +2881,7 @@
" }, \n",
" \"enabled\": True, \n",
" \"ifindex\": 506, \n",
" \"last-change\": 257729, \n",
" \"last-change\": 258476, \n",
" \"mtu\": 1518, \n",
" \"oper-status\": \"DOWN\", \n",
" \"type\": \"l2vlan\"\n",
Expand Down Expand Up @@ -2990,6 +2990,214 @@
"source": [
"Diff'ing models with state is also supported."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Compliance Report\n",
"\n",
"This feature also works with YANG models. Let's assume we want to verify we have set the MTU of all of our interfaces to 9000."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"data = {\n",
" \"interfaces\": {\n",
" \"interface\":{\n",
" \"Et1\": {\n",
" \"config\": {\n",
" \"mtu\": 9000\n",
" },\n",
" },\n",
" \"Et2\": {\n",
" \"config\": {\n",
" \"mtu\": 1500\n",
" }\n",
" }\n",
" }\n",
" }\n",
"}\n",
"# We load a dict for convenience, any source will do\n",
"config = napalm_yang.base.Root()\n",
"config.add_model(napalm_yang.models.openconfig_interfaces())\n",
"config.load_dict(data)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "-"
}
},
"source": [
"Now we can load the validation file. Here is the content for reference:\n",
"\n",
"```\n",
"---\n",
"- to_dict:\n",
" _kwargs:\n",
" filter: true\n",
" interfaces:\n",
" interface:\n",
" Et1:\n",
" config:\n",
" mtu: 9000\n",
" Et2:\n",
" config:\n",
" mtu: 9000\n",
" _mode: strict\n",
"```\n",
"\n",
"Note that there is a major difference between using the `compliance_report` method on getters and on `YANG` objects. With the former you have to specify how to get the data, with the later you have to get the data yourself by any means and then specify you want to convert the data into a `dict` with the `to_dict` method."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"complies\": false, \n",
" \"skipped\": [], \n",
" \"to_dict\": {\n",
" \"complies\": false, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"interfaces\": {\n",
" \"complies\": false, \n",
" \"diff\": {\n",
" \"complies\": false, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"interface\": {\n",
" \"complies\": false, \n",
" \"diff\": {\n",
" \"complies\": false, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"Et1\": {\n",
" \"complies\": true, \n",
" \"nested\": true\n",
" }, \n",
" \"Et2\": {\n",
" \"complies\": false, \n",
" \"diff\": {\n",
" \"complies\": false, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"config\": {\n",
" \"complies\": false, \n",
" \"diff\": {\n",
" \"complies\": false, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"mtu\": {\n",
" \"actual_value\": 1500, \n",
" \"complies\": false, \n",
" \"nested\": false\n",
" }\n",
" }\n",
" }, \n",
" \"nested\": true\n",
" }\n",
" }\n",
" }, \n",
" \"nested\": true\n",
" }\n",
" }\n",
" }, \n",
" \"nested\": true\n",
" }\n",
" }\n",
" }, \n",
" \"nested\": true\n",
" }\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"report = config.compliance_report(\"validate.yaml\")\n",
"pretty_print(report)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see it's complaining that the value of `Et2`'s MTU is 1500. Let's fix it and try again:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"complies\": true, \n",
" \"skipped\": [], \n",
" \"to_dict\": {\n",
" \"complies\": true, \n",
" \"extra\": [], \n",
" \"missing\": [], \n",
" \"present\": {\n",
" \"interfaces\": {\n",
" \"complies\": true, \n",
" \"nested\": true\n",
" }\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"config.interfaces.interface[\"Et2\"].config.mtu = 9000\n",
"report = config.compliance_report(\"validate.yaml\")\n",
"pretty_print(report)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can see in the first `complies` element of the report that we are complying. This works for state as the rest of the features too."
]
}
],
"metadata": {
Expand Down
13 changes: 13 additions & 0 deletions interactive_demo/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- to_dict:
_kwargs:
filter: true
interfaces:
interface:
Et1:
config:
mtu: 9000
Et2:
config:
mtu: 9000
_mode: strict
Loading

0 comments on commit 1effbcc

Please sign in to comment.