Skip to content

Commit

Permalink
[change] Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
purhan authored and Aryamanz29 committed May 3, 2022
1 parent 1606f4a commit 44297e9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
37 changes: 26 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ the administration dashboard, it also adds different endpoints to the
Connection App
~~~~~~~~~~~~~~

This app enables the controller to instantiate connections to the devices
This app allows OpenWISP Controller to use different protocols to reach network devices.
Currently, the default connnection protocols are SSH and SNMP, but the protocol
mechanism is extensible and more protocols can be implemented if needed.

SSH
###

The SSH connector allows the controller to initialize connections to the devices
in order perform `push operations <#how-to-configure-push-updates>`__:

- Sending configuration updates.
Expand All @@ -137,6 +144,13 @@ Access via SSH key is recommended, the SSH key algorithms supported are:
- RSA
- Ed25519

SNMP
####

The SNMP connector is useful to collect monitoring information and it's used in
`openwisp-monitoring`_ for performing checks to collect monitoring information.
`Read more <https://github.com/openwisp/openwisp-monitoring/pull/309#discussion_r692566202>`_ on how to use it.

Geo App
~~~~~~~

Expand Down Expand Up @@ -2264,16 +2278,17 @@ Configure timeout for the TCP connect when establishing a SSH connection.
``OPENWISP_CONNECTORS``
~~~~~~~~~~~~~~~~~~~~~~~

+--------------+-----------------------------------------------------------------------+
| **type**: | ``tuple`` |
+--------------+-----------------------------------------------------------------------+
| **default**: | .. code-block:: python |
| | |
| | ( |
| | ('openwisp_controller.connection.connectors.ssh.Ssh', 'SSH'), |
| | ('openwisp_controller.connection.connectors.snmp.Snmp', 'SNMP'), |
| | ) |
+--------------+-----------------------------------------------------------------------+
+--------------+-------------------------------------------------------------------------------------------+
| **type**: | ``tuple`` |
+--------------+-------------------------------------------------------------------------------------------+
| **default**: | .. code-block:: python |
| | |
| | ( |
| | ('openwisp_controller.connection.connectors.ssh.Ssh', 'SSH'), |
| | ('openwisp_controller.connection.connectors.snmp.Snmp', 'OpenWRT SNMP'), |
| | ('openwisp_controller.connection.connectors.airos.snmp.Snmp', 'Ubiquiti AirOS SNMP'), |
| | ) |
+--------------+-------------------------------------------------------------------------------------------+

Available connector classes. Connectors are python classes that specify ways
in which OpenWISP can connect to devices in order to launch commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class Migration(migrations.Migration):
field=models.GenericIPAddressField(
blank=True,
db_index=True,
help_text='ip address of the management interface, if available',
help_text='IP address used by OpenWISP to reach the device when '
'performing any type of push operation or active check. The '
'value of this field is generally sent by the device and hence '
'does not need to be changed, but can be changed or cleared '
'manually if needed.',
null=True,
),
),
Expand Down
6 changes: 3 additions & 3 deletions openwisp_controller/connection/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def clean(self):
self._validate_connector_schema()

def _get_connector(self):
if not hasattr(self, '_connectors'):
self._connectors = dict(app_settings.CONNECTORS)
try:
if self._connectors[self.credentials.connector] != 'SSH':
if not getattr(
import_string(self.credentials.connector), 'has_update_strategy'
):
return self.credentials.connector
except AttributeError:
pass
Expand Down
30 changes: 13 additions & 17 deletions openwisp_controller/connection/connectors/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@ class Snmp(object):
schema = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'title': 'Credentials type',
'oneOf': [
{
'title': 'SNMP',
'required': ['community', 'agent'],
'additionalProperties': False,
'properties': {
'community': {'type': 'string', 'default': 'public'},
'agent': {'type': 'string'},
'port': {
'type': 'integer',
'default': 161,
'minimum': 1,
'maximum': 65535,
},
},
'required': ['community', 'agent'],
'additionalProperties': False,
'properties': {
'community': {'type': 'string', 'default': 'public'},
'agent': {'type': 'string'},
'port': {
'type': 'integer',
'default': 161,
'minimum': 1,
'maximum': 65535,
},
],
},
}

has_update_strategy = False

def __init__(self, params, addresses):
self.params = params
self.addresses = addresses
Expand Down
2 changes: 2 additions & 0 deletions openwisp_controller/connection/connectors/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Ssh(object):
],
}

has_update_strategy = True

def __init__(self, params, addresses):
self._params = params
self.addresses = addresses
Expand Down
7 changes: 5 additions & 2 deletions openwisp_controller/connection/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

DEFAULT_CONNECTORS = (
('openwisp_controller.connection.connectors.ssh.Ssh', 'SSH'),
('openwisp_controller.connection.connectors.snmp.Snmp', 'SNMP'),
('openwisp_controller.connection.connectors.airos.snmp.Snmp', 'AiOS SNMP'),
('openwisp_controller.connection.connectors.snmp.Snmp', 'OpenWRT SNMP'),
(
'openwisp_controller.connection.connectors.airos.snmp.Snmp',
'Ubiquiti AirOS SNMP',
),
)

CONNECTORS = getattr(settings, 'OPENWISP_CONNECTORS', DEFAULT_CONNECTORS)
Expand Down

0 comments on commit 44297e9

Please sign in to comment.