Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Commit

Permalink
Adapted to more general API (#135)
Browse files Browse the repository at this point in the history
* Replace list() with [] and dict() with {}

I don't like them anymore :(

* Various improvements for get_route_to

Also fix #109

* Version 0.5.3

* empty inactive_reason rather than None

* Consistent expected output as well

* Group neighbors without peer-group under the '_' key

Painful stuff here.
@itdependsnetworks owes me a beer for that :D

* Fix previously wrong mock

* Remove too generic Exception

* Testcase for #119

* Adapted to more general API

* Adding napalm-yang to requirements

* Renaming file so py.test doesn't try to run it as a test
  • Loading branch information
dbarrosop committed Feb 5, 2017
1 parent 60710e9 commit 5f71a5b
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 149 deletions.
202 changes: 105 additions & 97 deletions napalm_eos/eos.py

Large diffs are not rendered by default.

@@ -1,4 +1,10 @@
---
_model: napalm_yang.oc_if.Interfaces()
_execute:
config:
cli:
- show running-config all

interfaces:
interface:
_block_capture: "(?P<block>interface (?P<key>(Ethernet|Management|Loopback|Port-Channel)\\d+)\n(?:.|\n)*?^!$)"
Expand Down
72 changes: 72 additions & 0 deletions oc_example.py
@@ -0,0 +1,72 @@
from napalm_eos.eos import EOSDriver

import napalm_yang

import pprint


eos_configuration = {
'hostname': '127.0.0.1',
'username': 'vagrant',
'password': 'vagrant',
'optional_args': {'port': 12443}
}


d = EOSDriver(**eos_configuration)
d.open()

# Get current interfaces configuration
running = d.parse_config("interfaces")

# Print the exact model as defined by OC
# This is mostly informative, as quick reference
print(running.model_to_text())

# We can get a representation of the data in text
print(running.data_to_text())

# Or as a dict
pprint.pprint(running.data_to_dict())

# We can also translate the object backto native configuration
print(d.translate_model(running, "interfaces"))

# Let's change some configuration
candidate = d.parse_config("interfaces")
candidate.interfaces.interface["Management1"].config.description("Connected to oob1:et2")
candidate.interfaces.interface["Ethernet2"].config.description("Connected to spine")
candidate.interfaces.interface["Port-Channel1"].config.description("Connected to blah")
candidate.interfaces.interface["Loopback1"].config.enabled(False)

# Let's create a new loopback interface
candidate.interfaces.interface.new_element("Loopback0")
candidate.interfaces.interface["Loopback0"].name("Loopback0")
candidate.interfaces.interface["Loopback0"].config.name("Loopback0")
candidate.interfaces.interface["Loopback0"].config.description("loopback0")
candidate.interfaces.interface["Loopback0"].config.enabled(True)
candidate.interfaces.interface["Loopback0"].config.mtu(1500)
candidate.interfaces.interface["Loopback0"].hold_time.config.up(0)
candidate.interfaces.interface["Loopback0"].hold_time.config.down(0)
candidate.interfaces.interface["Loopback0"].config.type_(napalm_yang.ianaift.Softwareloopback)

# Let's see a diff of the running and the candidate configuration
pprint.pprint(running.diff(candidate))

# Let's turn this into native configuration
new_config = d.translate_model(candidate, "interfaces")
print(new_config)


# Load it into the device
d.load_merge_candidate(config=new_config)

# See the diff matches our expectations
print(d.compare_config())

# Let's commit the configuration now
d.commit_config()

# if now get a new running and candidate config, let's compare it with out previous candidate
running = d.parse_config("interfaces")
pprint.pprint(running.diff(candidate))
49 changes: 0 additions & 49 deletions oc_test.py

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
@@ -1,2 +1,3 @@
napalm_base>=0.19.0
pyeapi
-e git+https://github.com/napalm-automation/napalm-yang.git@develop#egg=napalm-yang
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm-eos",
version="0.5.2",
version="0.5.3",
packages=find_packages(),
author="David Barroso, Mircea Ulinic",
author_email="dbarrosop@dravetech.com, mircea@cloudflare.com",
Expand Down
@@ -0,0 +1,66 @@
{
"_": {
"multipath": false,
"multihop_ttl": 0,
"apply_groups": [],
"export_policy": "",
"import_policy": "",
"remove_private_as": false,
"local_as": 13335,
"local_address": "",
"type": "",
"remote_as": 0,
"prefix_limit": {},
"description": "",
"neighbors": {
"192.168.0.1": {
"route_reflector_client": false,
"nhs": false,
"authentication_key": "",
"export_policy": "export-policy",
"import_policy": "import-policy",
"local_as": 13335,
"local_address": "",
"remote_as": 32934,
"prefix_limit": {},
"description": ""
},
"2001:db8::0:1": {
"route_reflector_client": false,
"nhs": false,
"authentication_key": "",
"export_policy": "export-policy",
"import_policy": "import-policy",
"local_as": 13335,
"local_address": "",
"remote_as": 8403,
"prefix_limit": {},
"description": ""
},
"172.17.17.1": {
"route_reflector_client": false,
"nhs": false,
"authentication_key": "",
"export_policy": "export-policy",
"import_policy": "import-policy",
"local_as": 13335,
"local_address": "",
"remote_as": 13414,
"prefix_limit": {},
"description": ""
},
"2001:db8::0:2": {
"route_reflector_client": false,
"nhs": false,
"authentication_key": "",
"export_policy": "export-policy",
"import_policy": "import-policy",
"local_as": 13335,
"local_address": "",
"remote_as": 54113,
"prefix_limit": {},
"description": ""
}
}
}
}
@@ -0,0 +1,18 @@
router bgp 13335
maximum-paths 32
neighbor 192.168.0.1 remote-as 32934
neighbor 192.168.0.1 maximum-routes 100
neighbor 192.168.0.1 route-map import-policy in
neighbor 192.168.0.1 route-map export-policy out
neighbor 172.17.17.1 remote-as 13414
neighbor 172.17.17.1 maximum-routes 500
neighbor 172.17.17.1 route-map import-policy in
neighbor 172.17.17.1 route-map export-policy out
neighbor 2001:db8::0:1 remote-as 8403
neighbor 2001:db8::0:1 maximum-routes 500
neighbor 2001:db8::0:1 route-map import-policy in
neighbor 2001:db8::0:1 route-map export-policy out
neighbor 2001:db8::0:2 remote-as 54113
neighbor 2001:db8::0:2 route-map import-policy in
neighbor 2001:db8::0:2 route-map export-policy out
!
@@ -1 +1 @@
{"IPv6-PEERS-GROUP-NAME": {"neighbors": {"2001:db8::0:2": {"export_policy": "", "prefix_limit": {}, "import_policy": "", "local_as": 0, "route_reflector_client": false, "nhs": false, "local_address": "", "remote_as": 54113, "authentication_key": "", "description": ""}, "2001:db8::0:1": {"export_policy": "", "prefix_limit": {}, "import_policy": "", "local_as": 0, "route_reflector_client": false, "nhs": false, "local_address": "", "remote_as": 8403, "authentication_key": "", "description": ""}}, "export_policy": "reject-all", "multipath": false, "prefix_limit": {}, "import_policy": "reject-all", "local_as": 0, "multihop_ttl": 0, "apply_groups": [], "remote_as": 0, "remove_private_as": true, "local_address": "", "type": "", "description": ""}, "IPv4-PEERS-GROUP-NAME": {"neighbors": {"192.168.0.1": {"export_policy": "", "prefix_limit": {}, "import_policy": "", "local_as": 0, "route_reflector_client": false, "nhs": false, "local_address": "", "remote_as": 32934, "authentication_key": "", "description": ""}, "172.17.17.1": {"export_policy": "", "prefix_limit": {}, "import_policy": "", "local_as": 0, "route_reflector_client": false, "nhs": false, "local_address": "", "remote_as": 13414, "authentication_key": "", "description": ""}}, "export_policy": "4-public-peer-anycast-out", "multipath": false, "prefix_limit": {}, "import_policy": "reject-all", "local_as": 0, "multihop_ttl": 0, "apply_groups": [], "remote_as": 0, "remove_private_as": true, "local_address": "", "type": "", "description": ""}}
{"IPv4-PEERS-GROUP-NAME": {"local_address": "", "description": "", "type": "", "local_as": 13335, "apply_groups": [], "multihop_ttl": 0, "remove_private_as": true, "remote_as": 0, "import_policy": "reject-all", "export_policy": "4-public-peer-anycast-out", "neighbors": {"172.17.17.1": {"local_address": "", "authentication_key": "", "description": "", "nhs": false, "local_as": 13335, "route_reflector_client": false, "remote_as": 13414, "import_policy": "", "export_policy": "", "prefix_limit": {}}, "192.168.0.1": {"local_address": "", "authentication_key": "", "description": "", "nhs": false, "local_as": 13335, "route_reflector_client": false, "remote_as": 32934, "import_policy": "", "export_policy": "", "prefix_limit": {}}}, "prefix_limit": {}, "multipath": false}, "IPv6-PEERS-GROUP-NAME": {"local_address": "", "description": "", "type": "", "local_as": 13335, "apply_groups": [], "multihop_ttl": 0, "remove_private_as": true, "remote_as": 0, "import_policy": "reject-all", "export_policy": "reject-all", "neighbors": {"2001:db8::0:2": {"local_address": "", "authentication_key": "", "description": "", "nhs": false, "local_as": 13335, "route_reflector_client": false, "remote_as": 54113, "import_policy": "", "export_policy": "", "prefix_limit": {}}, "2001:db8::0:1": {"local_address": "", "authentication_key": "", "description": "", "nhs": false, "local_as": 13335, "route_reflector_client": false, "remote_as": 8403, "import_policy": "", "export_policy": "", "prefix_limit": {}}}, "prefix_limit": {}, "multipath": false}}
@@ -1 +1 @@
{"1.0.4.0/24": [{"protocol": "EBGP", "inactive_reason": "", "last_active": true, "age": 0, "routing_table": "default", "next_hop": "192.168.0.1", "outgoing_interface": "", "preference": 200, "current_active": true, "selected_next_hop": true, "protocol_attributes": {"local_preference": 50, "remote_as": 43515, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "preference2": 0, "metric": 0, "local_as": 13335, "as_path": "1299 15169 43515", "remote_address": "192.168.0.1"}}]}
{"1.0.4.0/24": [{"next_hop": "192.168.0.1", "preference": 200, "protocol": "eBGP", "selected_next_hop": true, "current_active": true, "routing_table": "default", "protocol_attributes": {"remote_as": 43515, "as_path": "1299 15169 43515", "local_preference": 50, "remote_address": "192.168.0.1", "preference2": 0, "metric": 0, "communities": ["1299:1234", "1299:5678", "1299:91011", "1299:12134"], "local_as": 13335}, "outgoing_interface": "Port-Channel2", "last_active": true, "inactive_reason": "", "age": 0}]}

0 comments on commit 5f71a5b

Please sign in to comment.