Skip to content

Commit 1324db6

Browse files
authored
Merge pull request #46 from QualiSystems/dev
Version 4.0.0
2 parents e546ea2 + ae1e1b6 commit 1324db6

61 files changed

Lines changed: 3499 additions & 3389 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Quali-Shells-Open-Source.rtf linguist-documentation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ target/
6363
.pypirc
6464
.idea
6565
cloudshell/snmp/test.py
66+
/cloudshell/snmp/test*.py

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-isort
3+
rev: v4.3.21
4+
hooks:
5+
- id: isort
6+
language_version: python3.7
7+
exclude: '/mibs'
8+
- repo: https://github.com/python/black
9+
rev: 19.3b0
10+
hooks:
11+
- id: black
12+
language_version: python3.7
13+
exclude: '/mibs'
14+
- repo: https://gitlab.com/pycqa/flake8
15+
rev: 3.7.8
16+
hooks:
17+
- id: flake8
18+
additional_dependencies: [
19+
flake8-docstrings,
20+
flake8-builtins,
21+
flake8-comprehensions,
22+
flake8-print,
23+
flake8-eradicate,
24+
]
25+
language_version: python3.7
26+
exclude: '/mibs'

.travis.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
language: python
2-
python:
3-
- "2.7"
42

5-
install:
6-
- pip install -r requirements.txt
7-
- pip install -r test_requirements.txt
8-
- pip install codecov
3+
jobs:
4+
include:
5+
- if: branch = master
6+
python: 2.7
7+
env: TOXENV=py27-master
8+
after_success: codecov
9+
- if: branch = master
10+
python: 3.7
11+
env: TOXENV=py37-master
12+
after_success: codecov
13+
- if: branch != master
14+
python: 2.7
15+
env: TOXENV=py27-dev
16+
after_success: codecov
17+
- if: branch != master
18+
python: 3.7
19+
env: TOXENV=py37-dev
20+
after_success: codecov
21+
- env: TOXENV=build
22+
python: 2.7
23+
- env: TOXENV=pre-commit
24+
python: 3.7
925

10-
script:
11-
- python setup.py develop
12-
- nosetests --with-coverage --cover-package=cloudshell.snmp --where=tests
13-
- python setup.py sdist --format zip
26+
install:
27+
- pip install tox
28+
- pip install codecov
1429

15-
after_success:
16-
codecov
30+
script: tox

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# cloudshell-snmp
2-
![alt tag](https://travis-ci.org/QualiSystems/cloudshell-snmp.svg)
2+
3+
[![Build status](https://travis-ci.org/QualiSystems/cloudshell-snmp.svg?branch=dev)](https://travis-ci.org/QualiSystems/cloudshell-snmp)
34
[![codecov](https://codecov.io/gh/QualiSystems/cloudshell-snmp/branch/dev/graph/badge.svg)](https://codecov.io/gh/QualiSystems/cloudshell-snmp)
45
[![PyPI version](https://badge.fury.io/py/cloudshell-snmp.svg)](https://badge.fury.io/py/cloudshell-snmp)
5-
[![Dependency Status](https://dependencyci.com/github/QualiSystems/cloudshell-snmp/badge)](https://dependencyci.com/github/QualiSystems/cloudshell-snmp)
6-
[![Stories in Ready](https://badge.waffle.io/QualiSystems/cloudshell-snmp.svg?label=ready&title=Ready)](http://waffle.io/QualiSystems/cloudshell-snmp)
6+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
77

88
<p align="center">
99
<img src="https://github.com/QualiSystems/devguide_source/raw/master/logo.png"></img>
1010
</p>
1111

12-
# Cloudshell SNMP
12+
We use tox and pre-commit for testing. [Services description](https://github.com/QualiSystems/cloudshell-package-repo-template#description-of-services)

cloudshell/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from pkgutil import extend_path
2+
23
__path__ = extend_path(__path__, __name__)

cloudshell/snmp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from pkgutil import extend_path
2+
23
__path__ = extend_path(__path__, __name__)

cloudshell/snmp/cloudshell_snmp.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from pysnmp.entity import config, engine
2+
3+
from cloudshell.snmp.core.snmp_context_manager import SnmpContextManager
4+
from cloudshell.snmp.core.tools.snmp_constants import SNMP_RETRIES_COUNT, SNMP_TIMEOUT
5+
from cloudshell.snmp.core.tools.snmp_context import SnmpContext
6+
from cloudshell.snmp.core.tools.snmp_parameters_helper import SnmpParametersConverter
7+
from cloudshell.snmp.core.tools.snmp_security import SnmpSecurity
8+
from cloudshell.snmp.core.tools.snmp_trasnport import SnmpTransport
9+
10+
11+
class Snmp(object):
12+
def __init__(self, timeout=SNMP_TIMEOUT, retry_count=SNMP_RETRIES_COUNT):
13+
self._snmp_timeout = timeout
14+
self._snmp_retry_count = retry_count
15+
16+
def get_snmp_service(self, snmp_parameters, logger):
17+
"""Get SNMP service.
18+
19+
:param cloudshell.snmp.snmp_parameters.SnmpV2Parameters snmp_parameters:
20+
:param logging.Logger logger:
21+
"""
22+
pysnmp_params = SnmpParametersConverter(snmp_parameters)
23+
snmp_engine = self._get_snmp_engine(pysnmp_params, logger)
24+
snmp_context = SnmpContext(
25+
snmp_parameters.context_engine_id, snmp_parameters.context_name
26+
)
27+
get_bulk_flag = pysnmp_params.version > 0
28+
return SnmpContextManager(
29+
snmp_engine=snmp_engine,
30+
v3_context_engine_id=snmp_context.context_engine_id,
31+
v3_context_name=snmp_context.context_name,
32+
logger=logger,
33+
get_bulk_flag=get_bulk_flag,
34+
is_snmp_read_only=pysnmp_params.is_read_only,
35+
)
36+
37+
def _get_snmp_engine(self, pysnmp_params, logger):
38+
"""Get SNMP engine.
39+
40+
:param cloudshell.snmp.core.tools.snmp_parameters_helper.SnmpParametersConverter pysnmp_params: # noqa: E501
41+
"""
42+
snmp_engine = engine.SnmpEngine()
43+
config.addTargetParams(
44+
snmp_engine,
45+
"pms",
46+
pysnmp_params.user,
47+
pysnmp_params.security,
48+
pysnmp_params.version,
49+
)
50+
transport = SnmpTransport(
51+
snmp_parameters=pysnmp_params.snmp_parameters, logger=logger
52+
)
53+
transport.add_udp_endpoint(
54+
snmp_engine, self._snmp_timeout, self._snmp_retry_count
55+
)
56+
security = SnmpSecurity(py_snmp_params=pysnmp_params, logger=logger)
57+
security.add_security(snmp_engine)
58+
59+
return snmp_engine
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from pkgutil import extend_path
2+
23
__path__ = extend_path(__path__, __name__)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pkgutil import extend_path
2+
3+
__path__ = extend_path(__path__, __name__)

0 commit comments

Comments
 (0)