Skip to content

Commit

Permalink
Merge pull request #36 from QualiSystems/dev
Browse files Browse the repository at this point in the history
Added steps for enabling SNMP Server before creating snmp community. Added verification of SNMP Community lenght. Fixed regex in remove VLAN flow
  • Loading branch information
alexquali committed Jul 6, 2017
2 parents d52aaeb + 2cf1d7a commit 649ead8
Show file tree
Hide file tree
Showing 67 changed files with 3,155 additions and 1,298 deletions.
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
.pypirc
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ python:
- "2.7"

install:
- pip install -r requirements.txt
# todo: fix dependecies mismatch and use python setup.py install instead
- 'if [ ${TRAVIS_BRANCH} \!= "master" ] && [ -f dev_requirements.txt ]; then
pip install --extra-index-url https://testpypi.python.org/pypi -r dev_requirements.txt;
python setup.py develop --no-deps;
else
pip install -r requirements.txt;
python setup.py develop --no-deps;
fi'
- pip install -r test_requirements.txt
- pip install coveralls

script:
- python runtests.py --with-coverage --cover-package=package
- python setup.py test
- python setup.py sdist --format zip
- nosetests --with-coverage --cover-package=cloudshell.networking.huawei tests

after_success:
coveralls
- coveralls
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# cloudshell-networking-Huawei
# cloudshell-networking-huawei
![alt tag](https://travis-ci.org/QualiSystems/cloudshell-networking-huawei.svg?branch=dev)
[![Coverage Status](https://coveralls.io/repos/github/QualiSystems/cloudshell-networking-huawei/badge.svg?branch=dev)](https://coveralls.io/github/QualiSystems/cloudshell-networking-huawei?branch=dev)
[![PyPI version](https://badge.fury.io/py/cloudshell-networking-huawei.svg)](https://badge.fury.io/py/cloudshell-networking-huawei)
[![Dependency Status](https://dependencyci.com/github/QualiSystems/cloudshell-networking-Huawei/badge)](https://dependencyci.com/github/QualiSystems/cloudshell-networking-Huawei)
[![Stories in Ready](https://badge.waffle.io/QualiSystems/cloudshell-networking-huawei.svg?label=ready&title=Ready)](http://waffle.io/QualiSystems/cloudshell-networking-huawei)

<p align="center">
<img src="https://github.com/QualiSystems/devguide_source/raw/master/logo.png"></img>
</p>
1 change: 1 addition & 0 deletions cloudshell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
3 changes: 2 additions & 1 deletion cloudshell/networking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

__path__ = extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions cloudshell/networking/huawei/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions cloudshell/networking/huawei/autoload/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
Binary file removed cloudshell/networking/huawei/autoload/__init__.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class HuaweiGenericSNMPAutoload(MibAttributes):

def __init__(self, snmp_handler, logger, supported_os, resource_name):
"""Basic init with Huawei router mib attributes handler and logger
Expand All @@ -13,30 +12,28 @@ def __init__(self, snmp_handler, logger, supported_os, resource_name):
:return:
"""

MibAttributes.__init__(self, snmp_handler, logger, supported_os,resource_name)
MibAttributes.__init__(self, snmp_handler, logger, supported_os, resource_name)

self._excluded_models = []
self.supported_os = supported_os
self.logger = logger


def discover(self):
"""Load device structure and attributes: chassis, modules, submodules, ports, port-channels and power supplies
:return: AutoLoadDetails object
"""
#
#
self._is_valid_device_os()

self.logger.info('*'*10)
self.logger.info('*' * 10)
self.logger.info('Starting Huawei SNMP discovery process')

self.load_huawei_mib()
self._get_device_details()
self.snmp.load_mib(['HUAWEI-PORT-MIB'])
self._load_snmp_objects_and_tables()


if len(self.chassis_list) < 1:
self.logger.error('Entity table error, no chassis found')
return AutoLoadDetails(list(), list())
Expand All @@ -59,19 +56,20 @@ def discover(self):

result = AutoLoadDetails(resources=self.resources, attributes=self.attributes)

self.logger.info('*'*10)
self.logger.info('*' * 10)
self.logger.info('Discover completed. The following Structure have been loaded:' +
'\nModel, Name, Relative Path, Uniqe Id')
'\nModel, Name, Relative Path, Uniqe Id')

for resource in self.resources:
self.logger.info('{0},\t\t{1},\t\t{2},\t\t{3}'.format(resource.model, resource.name,
resource.relative_address, resource.unique_identifier))
resource.relative_address,
resource.unique_identifier))
self.logger.info('------------------------------')
for attribute in self.attributes:
self.logger.info('{0},\t\t{1},\t\t{2}'.format(attribute.relative_address, attribute.attribute_name,
attribute.attribute_value))
attribute.attribute_value))

self.logger.info('*'*10)
self.logger.info('*' * 10)
self.logger.info('SNMP discovery Completed')
return result

Expand All @@ -98,10 +96,6 @@ def _is_valid_device_os(self):
self.logger.error(error_message)
raise Exception(error_message)





def _filter_lower_bay_containers(self):

upper_container = None
Expand All @@ -115,27 +109,23 @@ def _filter_lower_bay_containers(self):
lower_container = container
if lower_container and upper_container:
child_upper_items_len = len(self.entity_mib_table.filter_by_column('ContainedIn', str(upper_container)
).sort_by_column('ParentRelPos').keys())
).sort_by_column('ParentRelPos').keys())
child_lower_items = self.entity_mib_table.filter_by_column('ContainedIn', str(lower_container)
).sort_by_column('ParentRelPos').keys()
).sort_by_column('ParentRelPos').keys()
for child in child_lower_items:
self.entity_mib_table[child]['entPhysicalContainedIn'] = upper_container
self.entity_mib_table[child]['entPhysicalParentRelPos'] = str(child_upper_items_len + int(
self.entity_mib_table[child]['entPhysicalParentRelPos']))



def _add_resource(self, resource):
"""Add object data to resources and attributes lists
:param resource: object which contains all required data for certain resource
"""


self.resources.append(resource.get_resource())
self.attributes.extend(resource.get_attributes())


def _filter_entity_table(self, raw_entity_table):
"""Filters out all elements if their parents, doesn't exist, or listed in self.exclusion_list
Expand All @@ -149,7 +139,6 @@ def _filter_entity_table(self, raw_entity_table):
if parent_id not in raw_entity_table or parent_id in self.exclusion_list:
self.exclusion_list.append(element)


def _get_device_details(self):
"""Get root element attributes
Expand All @@ -159,7 +148,7 @@ def _get_device_details(self):
result = {'System Name': self.snmp.get_property('SNMPv2-MIB', 'sysName', 0),
'Vendor': "huawei",
'Model': self._get_device_model(),
'Location': self.snmp.get_property('SNMPv2-MIB', 'sysLocation',0),
'Location': self.snmp.get_property('SNMPv2-MIB', 'sysLocation', 0),
'Contact Name': self.snmp.get_property('SNMPv2-MIB', 'sysContact', 0)}

match_version = re.search(r'Version\s+(?P<software_version>\S+)\S*\s+',
Expand All @@ -168,14 +157,11 @@ def _get_device_details(self):
if match_version:
result['OS Version'] = match_version.groupdict()['software_version'].replace(',', '')


self.root_model.attributes = result
root = self.root_model
self.attributes.extend(root.get_attributes())
self.logger.info('Finished Loading Switch Attributes')



def _get_device_model(self):
"""Get device model form snmp SNMPv2 mib
Expand All @@ -188,5 +174,3 @@ def _get_device_model(self):
if match_name:
result = match_name.groupdict()['model'].capitalize()
return result


0 comments on commit 649ead8

Please sign in to comment.