Skip to content

Commit

Permalink
Add Ciena driver (#570)
Browse files Browse the repository at this point in the history
* Create test_ciena.py
* add ciena
* remove unnecessary
  • Loading branch information
jgroom33 committed Dec 17, 2023
1 parent ab2d852 commit f8207de
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 25 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,19 @@ Device handlers are easy to implement and prove to be futureproof.

When instantiating a connection to a known type of NETCONF server:

* Juniper: `device_params={'name':'junos'}`
* Alcatel Lucent: `device_params={'name':'alu'}`
* Ciena: `device_params={'name':'ciena'}`
* Cisco:
- CSR: `device_params={'name':'csr'}`
- Nexus: `device_params={'name':'nexus'}`
- IOS XR: `device_params={'name':'iosxr'}`
- IOS XE: `device_params={'name':'iosxe'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Huawei:
- `device_params={'name':'huawei'}`
- `device_params={'name':'huaweiyang'}`
* Nokia SR OS: `device_params={'name':'sros'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Juniper: `device_params={'name':'junos'}`
* Server or anything not in above: `device_params={'name':'default'}`


Expand Down
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ Device handlers are easy to implement and prove to be futureproof.
Supported device handlers
'''''''''''''''''''''''''

* Juniper: `device_params={'name':'junos'}`
* Alcatel Lucent: `device_params={'name':'alu'}`
* Ciena: `device_params={'name':'ciena'}`
* Cisco:
- CSR: `device_params={'name':'csr'}`
- Nexus: `device_params={'name':'nexus'}`
- IOS XR: `device_params={'name':'iosxr'}`
- IOS XE: `device_params={'name':'iosxe'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Huawei:
- `device_params={'name':'huawei'}`
- `device_params={'name':'huaweiyang'}`
* Nokia SR OS: `device_params={'name':'sros'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Juniper: `device_params={'name':'junos'}`
* Server or anything not in above: `device_params={'name':'default'}`

Changes \| brief
Expand Down
9 changes: 5 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ The latest pull request merge includes support for Huawei devices with name **hu

Supported device handlers
-------------------------
* Juniper: `device_params={'name':'junos'}`
* Alcatel Lucent: `device_params={'name':'alu'}`
* Ciena: `device_params={'name':'ciena'}`
* Cisco:
- CSR: `device_params={'name':'csr'}`
- Nexus: `device_params={'name':'nexus'}`
- IOS XR: `device_params={'name':'iosxr'}`
- IOS XE: `device_params={'name':'iosxe'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Huawei:
- `device_params={'name':'huawei'}`
- `device_params={'name':'huaweiyang'}`
* Alcatel Lucent: `device_params={'name':'alu'}`
* H3C: `device_params={'name':'h3c'}`
* HP Comware: `device_params={'name':'hpcomware'}`
* Juniper: `device_params={'name':'junos'}`
* Server or anything not in above: `device_params={'name':'default'}`


Expand Down
30 changes: 17 additions & 13 deletions ncclient/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# supported devices config, add new device (eg: 'device name':'device label').
supported_devices_cfg = {'junos':'Juniper',
'csr':'Cisco CSR1000v',
'nexus':'Cisco Nexus',
'iosxr':'Cisco IOS XR',
'iosxe':'Cisco IOS XE',
'huawei':'Huawei',
'huaweiyang':'Huawei',
'alu':'Alcatel Lucent',
'h3c':'H3C',
'hpcomware':'HP Comware',
'sros':'Nokia SR OS',
'default':'Server or anything not in above'}
supported_devices_cfg = {
"alu": "Alcatel Lucent",
"ciena": "Ciena",
"csr": "Cisco CSR1000v",
"h3c": "H3C",
"hpcomware": "HP Comware",
"huawei": "Huawei",
"huaweiyang": "Huawei",
"iosxe": "Cisco IOS XE",
"iosxr": "Cisco IOS XR",
"junos": "Juniper",
"nexus": "Cisco Nexus",
"sros": "Nokia SR OS",
"default": "Server or anything not in above",
}


def get_supported_devices():
return tuple(supported_devices_cfg.keys())


def get_supported_device_labels():
return supported_devices_cfg

19 changes: 19 additions & 0 deletions ncclient/devices/ciena.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .default import DefaultDeviceHandler
from ncclient.xml_ import BASE_NS_1_0


class CienaDeviceHandler(DefaultDeviceHandler):
"""
Ciena handler for device specific information.
"""

def __init__(self, device_params):
super(CienaDeviceHandler, self).__init__(device_params)

def get_xml_base_namespace_dict(self):
return {None: BASE_NS_1_0}

def get_xml_extra_prefix_kwargs(self):
d = {}
d.update(self.get_xml_base_namespace_dict())
return {"nsmap": d}
18 changes: 18 additions & 0 deletions test/unit/devices/test_ciena.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
from ncclient.devices.ciena import *
from ncclient.xml_ import *


class TestCienaDevice(unittest.TestCase):

def setUp(self):
self.obj = CienaDeviceHandler({'name': 'ciena'})

def test_get_xml_base_namespace_dict(self):
expected = {None: BASE_NS_1_0}
self.assertDictEqual(expected, self.obj.get_xml_base_namespace_dict())

def test_get_xml_extra_prefix_kwargs(self):
expected = dict()
expected["nsmap"] = self.obj.get_xml_base_namespace_dict()
self.assertDictEqual(expected, self.obj.get_xml_extra_prefix_kwargs())
2 changes: 2 additions & 0 deletions test/unit/devices/test_get_supported_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_get_supported_devices(self):
supported_devices = devices.get_supported_devices()
self.assertEqual(sorted(supported_devices), sorted(('junos',
'csr',
'ciena',
'nexus',
'iosxr',
'iosxe',
Expand All @@ -22,6 +23,7 @@ def test_get_supported_device_labels(self):
supported_device_labels = devices.get_supported_device_labels()
self.assertEqual(supported_device_labels, {'junos':'Juniper',
'csr':'Cisco CSR1000v',
'ciena': 'Ciena',
'nexus':'Cisco Nexus',
'iosxr':'Cisco IOS XR',
'iosxe':'Cisco IOS XE',
Expand Down

0 comments on commit f8207de

Please sign in to comment.