Skip to content

Commit

Permalink
Merge pull request #25 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
mirceaulinic committed Sep 29, 2016
2 parents f82497e + 6a91ff7 commit e2ac0fd
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 49 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Description of Issue/Question


### Did you follow the steps from https://github.com/napalm-automation/napalm#faq
[ ] Yes
[ ] No


### Setup

### napalm-pluribus version
(Paste verbatim output from `pip freeze | grep napalm-pluribus` between quotes below)

```

```

### Netvisor OS version
(Paste verbatim output from `software-show` between quotes below)

```

```

### Steps to Reproduce the Issue

### Error Traceback
(Paste the complete traceback of the exception between quotes below)

```

```
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- Make sure you have read http://napalm.readthedocs.io/en/latest/contributing/index.html --!>
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ python:
- 2.7

install:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install .
- pip install -e git+https://github.com/napalm-automation/napalm-base.git@develop#egg=napalm-base
- pip install coveralls

deploy:
provider: pypi
Expand All @@ -18,15 +19,19 @@ deploy:
branch: master

script:
- pylama .
- cd test/unit
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_facts
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_interfaces
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_lldp_neighbors
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_lldp_neighbors_detail
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_mac_address_table
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_ntp_stats
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_ntp_servers
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_snmp_information
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_get_users
- nosetests -v TestPluribusDriver:TestGetterPluribusDriver.test_traceroute
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_facts
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_interfaces
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_lldp_neighbors
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_lldp_neighbors_detail
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_mac_address_table
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_ntp_stats
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_ntp_servers
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_snmp_information
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_users
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_traceroute
- nosetests --with-coverage --cover-package napalm_pluribus -v TestPluribusDriver:TestGetterPluribusDriver.test_get_config
- cd ../..
- coverage combine test/unit/.coverage
after_success: coveralls
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![PyPI](https://img.shields.io/pypi/v/napalm-pluribus.svg)](https://pypi.python.org/pypi/napalm-pluribus)
[![PyPI](https://img.shields.io/pypi/dm/napalm-pluribus.svg)](https://pypi.python.org/pypi/napalm-pluribus)
[![Build Status](https://travis-ci.org/napalm-automation/napalm-pluribus.svg?branch=master)](https://travis-ci.org/napalm-automation/napalm-pluribus)
[![Coverage Status](https://coveralls.io/repos/github/napalm-automation/napalm-pluribus/badge.svg?branch=master)](https://coveralls.io/github/napalm-automation/napalm-pluribus)

# napalm-pluribus
15 changes: 14 additions & 1 deletion napalm_pluribus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 CloudFlare, Inc. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
Expand All @@ -13,4 +14,16 @@
# the License.

"""napalm_pluribus package."""
from pluribus import PluribusDriver

# Import stdlib
import pkg_resources

# Import local modules
from pluribus import PluribusDriver # noqa

__all__ = ('PluribusDriver',)

try:
__version__ = pkg_resources.get_distribution('napalm-pluribus').version
except pkg_resources.DistributionNotFound:
__version__ = "Not installed"
62 changes: 36 additions & 26 deletions napalm_pluribus/pluribus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 CloudFlare, Inc. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
Expand All @@ -12,6 +13,8 @@
# License for the specific language governing permissions and limitations under
# the License.

"""Pluribus driver."""

# python std lib
import re

Expand All @@ -20,6 +23,7 @@
from pyPluribus import PluribusDevice

# NAPALM base
import napalm_base.helpers
import napalm_base.exceptions
from napalm_base.base import NetworkDriver

Expand All @@ -43,38 +47,30 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)

self.device = PluribusDevice(hostname, username, password, self.port, timeout)


def open(self):
try:
self.device.open()
except pyPluribus.exceptions.ConnectionError as connerr:
raise napalm_base.exceptions.ConnectionException(connerr.message)


def close(self):
self.device.close()


def load_merge_candidate(self, filename=None, config=None):
return self.device.config.load_candidate(filename=filename, config=config)


def config_compare(self):
return self.device.config.compare()


def commit_config(self):
return self.device.config.commit()


def discard_config(self):
return self.device.config.discard()


def rollback(self):
return self.device.config.rollback(number=1)


def get_facts(self):

switch_info = self.device.show('switch info', delim='@$@')
Expand All @@ -96,7 +92,6 @@ def get_facts(self):
uptime_days_split = uptime_str.split('d')
uptime_days = int(uptime_days_split[0])
uptime_hours_split = uptime_days_split[-1].split('h')
uptime_hours = int(uptime_hours_split[0])
uptime_minutes_split = uptime_hours_split[-1].split('m')
uptime_minutes = int(uptime_minutes_split[0])
uptime_seconds = int(uptime_minutes_split[-1].replace('s', ''))
Expand All @@ -123,7 +118,6 @@ def get_facts(self):

return facts


def cli(self, commands=None):

cli_output = {}
Expand All @@ -136,12 +130,11 @@ def cli(self, commands=None):

return cli_output


def get_interfaces(self):

interfaces = {}

interface_info = self.device.show('port config', delim='@$@')
interface_info = self.device.show('port config', delim='@$@')
interfaces_lines = interface_info.splitlines()[1:-1]

for line in interfaces_lines:
Expand All @@ -162,12 +155,12 @@ def get_interfaces(self):
'description': description,
'last_flapped': last_flap,
'speed': speed,
'mac_address': mac_address
'mac_address': napalm_base.helpers.convert(
napalm_base.helpers.mac, mac_address)
}

return interfaces


def get_mac_address_table(self):

mac_table = []
Expand All @@ -177,14 +170,13 @@ def get_mac_address_table(self):

for line in lines:
mac_details = line.split('@$@')
mac_raw = unicode(mac_details[2].strip())
mac_all = mac_raw.replace('.', '').replace(':', '')
mac_format = unicode(':'.join([mac_all[i:i+2] for i in range(12)[::2]]))
mac_raw = mac_details[2].strip()
vlan = int(mac_details[3].strip())
ports = unicode(mac_details[8].strip())
active = (mac_details[9].strip == 'active')
mac_table.append({
'mac': mac_format,
'mac': napalm_base.helpers.convert(
napalm_base.helpers.mac, mac_raw),
'interface': ports,
'vlan': vlan,
'active': active,
Expand All @@ -195,7 +187,6 @@ def get_mac_address_table(self):

return mac_table


def get_lldp_neighbors(self):

lldp_neighbors = {}
Expand All @@ -217,7 +208,6 @@ def get_lldp_neighbors(self):

return lldp_neighbors


def get_lldp_neighbors_detail(self):

lldp_neighbors = {}
Expand All @@ -228,7 +218,8 @@ def get_lldp_neighbors_detail(self):
for line in lines:
neighbor_details = line.split('@$@')
port = unicode(neighbor_details[1].strip())
chassis = unicode(neighbor_details[2].strip())
chassis = napalm_base.helpers.convert(
napalm_base.helpers.mac, neighbor_details[2].strip())
port_id = unicode(neighbor_details[3].strip())
port_descr = unicode(neighbor_details[4].strip())
system_name = unicode(neighbor_details[6].strip())
Expand All @@ -250,7 +241,10 @@ def get_lldp_neighbors_detail(self):
def get_ntp_servers(self):

ntp_stats = self.get_ntp_stats()
return {ntp_peer.get('remote'): {} for ntp_peer in ntp_stats if ntp_peer.get('remote', '')}
return {
napalm_base.helpers.convert(napalm_base.helpers.ip, ntp_peer.get('remote')): {}
for ntp_peer in ntp_stats if ntp_peer.get('remote', '')
}

def get_ntp_stats(self):

Expand Down Expand Up @@ -285,7 +279,7 @@ def get_snmp_information(self):
}

switch_info = self.device.show('switch info', delim='@$@')
chassis_id = switch_info.splitlines()[2].split('@$@')[-1]
chassis_id = switch_info.splitlines()[2].split('@$@')[-1]

snmp_information['chassis_id'] = unicode(chassis_id)
snmp_information['contact'] = u''
Expand Down Expand Up @@ -327,7 +321,8 @@ def get_users(self):
running_config = role_details[6]
if access == 'read-write' and running_config == 'permit':
level = 15
if (access == 'read-write' and running_config == 'deny') or (access == 'read-only' and running_config == 'permit'):
if (access == 'read-write' and running_config == 'deny') or\
(access == 'read-only' and running_config == 'permit'):
level = 5
if access == 'read-only' and running_config == 'deny':
level = 1
Expand Down Expand Up @@ -413,10 +408,11 @@ def traceroute(self, destination, source='', ttl=0, timeout=0):
hop_index = int(hop_details[0])
previous_probe_host_name = '*'
previous_probe_ip_address = '*'
traceroute_result['success'][hop_index] = {'probes':{}}
traceroute_result['success'][hop_index] = {'probes': {}}
for probe_index in range(probes):
host_name = hop_details[3+probe_index*5]
ip_address = hop_details[4+probe_index*5]
ip_address = napalm_base.helpers.convert(
napalm_base.helpers.ip, hop_details[4+probe_index*5])
rtt = hop_details[5+probe_index*5]
if rtt:
rtt = float(rtt)
Expand All @@ -438,3 +434,17 @@ def traceroute(self, destination, source='', ttl=0, timeout=0):
previous_probe_ip_address = ip_address

return traceroute_result

def get_config(self, retrieve='all'):

config = {
'startup': '',
'running': '',
'candidate': ''
} # default values

if retrieve.lower() in ['running', 'all']:
config['running'] = self.device.show('running config')
# no startup as pluribus is WYSIWYG, no commit needed

return config
6 changes: 0 additions & 6 deletions pylama.ini

This file was deleted.

7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pytest
pytest-cov
pytest-json
pytest-pythonpath
pylama
flake8-import-order
-r requirements.txt
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pylama]
linters = mccabe,pep8,pyflakes
ignore = D203,C901

[pylama:pep8]
max_line_length = 100
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm-pluribus",
version="0.3.0",
version="0.4.0",
packages=find_packages(),
author="David Barroso",
author_email="dbarrosop@dravetech.com",
Expand Down
4 changes: 0 additions & 4 deletions test/unit/TestPluribusDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ def setUpClass(cls):

class FakePluribusConfig:


def __init__(self, device):
self._device = device


def _download_running_config(self):
return self._device.show('running config')

Expand All @@ -67,13 +65,11 @@ class FakePluribusDevice:
def __init__(self):
self.config = FakePluribusConfig(self)


@staticmethod
def read_txt_file(filename):
with open(filename) as data_file:
return data_file.read()


def execute_show(self, command):

cmd = re.sub(r'[\[\]\*\^\+\s\|]', '_', command)
Expand Down

0 comments on commit e2ac0fd

Please sign in to comment.