| 1 |
""" |
| 2 |
Handler for Cisco IOS-XE device specific information. |
| 3 |
|
| 4 |
Note that for proper import, the classname has to be: |
| 5 |
|
| 6 |
"<Devicename>DeviceHandler" |
| 7 |
|
| 8 |
...where <Devicename> is something like "Default", "Nexus", etc. |
| 9 |
|
| 10 |
All device-specific handlers derive from the DefaultDeviceHandler, which implements the |
| 11 |
generic information needed for interaction with a Netconf server. |
| 12 |
|
| 13 |
""" |
| 14 |
|
| 15 |
from .default import DefaultDeviceHandler |
| 16 |
|
| 17 |
from ncclient.operations.third_party.iosxe.rpc import SaveConfig |
| 18 |
from ncclient.xml_ import BASE_NS_1_0 |
| 19 |
|
| 20 |
import logging |
| 21 |
logger = logging.getLogger("ncclient.devices.iosxe") |
| 22 |
|
| 23 |
|
| 24 |
def iosxe_unknown_host_cb(host, fingerprint): |
| 25 |
# This will ignore the unknown host check when connecting to CSR devices |
| 26 |
return True |
| 27 |
|
| 28 |
class IosxeDeviceHandler(DefaultDeviceHandler): |
| 29 |
""" |
| 30 |
Cisco IOS-XE handler for device specific information. |
| 31 |
|
| 32 |
""" |
| 33 |
def __init__(self, device_params, ignore_errors=None): |
| 34 |
super(IosxeDeviceHandler, self).__init__(device_params, ignore_errors) |
| 35 |
|
| 36 |
def add_additional_operations(self): |
| 37 |
dict = {} |
| 38 |
dict["save_config"] = SaveConfig |
| 39 |
return dict |
| 40 |
|
| 41 |
def add_additional_ssh_connect_params(self, kwargs): |
| 42 |
kwargs['unknown_host_cb'] = iosxe_unknown_host_cb |
| 43 |
|
| 44 |
def transform_edit_config(self, node): |
| 45 |
# find the first node that has the tag "config" with no namespace |
| 46 |
nodes = node.findall("./config") |
| 47 |
if len(nodes) == 1: |
| 48 |
logger.debug('IOS XE handler: patching namespace of config element') |
| 49 |
nodes[0].tag = '{%s}%s' % (BASE_NS_1_0, 'config') |
| 50 |
return node |