Debian Codegraph @

ncclient/devices/nexus.py

raw
1 """
2 Handler for Cisco Nexus 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 ncclient.xml_ import BASE_NS_1_0
16 from ncclient.operations.third_party.nexus.rpc import ExecCommand
17
18 from .default import DefaultDeviceHandler
19
20 class NexusDeviceHandler(DefaultDeviceHandler):
21 """
22 Cisco Nexus handler for device specific information.
23
24 In the device_params dictionary, which is passed to __init__, you can specify
25 the parameter "ssh_subsystem_name". That allows you to configure the preferred
26 SSH subsystem name that should be tried on your Nexus switch. If connecting with
27 that name fails, or you didn't specify that name, the other known subsystem names
28 will be tried. However, if you specify it then this name will be tried first.
29
30 """
31 _EXEMPT_ERRORS = [
32 "*VLAN with the same name exists*", # returned even if VLAN was created, but
33 # name was already in use (switch will
34 # automatically choose different, unique
35 # name for VLAN)
36 ]
37
38 def __init__(self, device_params, ignore_errors=None):
39 super(NexusDeviceHandler, self).__init__(device_params, ignore_errors)
40
41 def add_additional_operations(self):
42 dict = {}
43 dict['exec_command'] = ExecCommand
44 return dict
45
46 def get_capabilities(self):
47 # Just need to replace a single value in the default capabilities
48 c = super(NexusDeviceHandler, self).get_capabilities()
49 c[0] = "urn:ietf:params:xml:ns:netconf:base:1.0"
50 return c
51
52 def get_xml_base_namespace_dict(self):
53 """
54 Base namespace needs a None key.
55
56 See 'nsmap' argument for lxml's Element().
57
58 """
59 return { None : BASE_NS_1_0 }
60
61 def get_xml_extra_prefix_kwargs(self):
62 """
63 Return keyword arguments per request, which are applied to Element().
64
65 Mostly, this is a dictionary containing the "nsmap" key.
66
67 See 'nsmap' argument for lxml's Element().
68
69 """
70 d = {
71 "nxos":"http://www.cisco.com/nxos:1.0",
72 "if":"http://www.cisco.com/nxos:1.0:if_manager",
73 "nfcli": "http://www.cisco.com/nxos:1.0:nfcli",
74 "vlan_mgr_cli": "http://www.cisco.com/nxos:1.0:vlan_mgr_cli"
75 }
76 d.update(self.get_xml_base_namespace_dict())
77 return { "nsmap" : d }
78
79 def get_ssh_subsystem_names(self):
80 """
81 Return a list of possible SSH subsystem names.
82
83 Different NXOS versions use different SSH subsystem names for netconf.
84 Therefore, we return a list so that several can be tried, if necessary.
85
86 The Nexus device handler also accepts
87
88 """
89 preferred_ssh_subsystem = self.device_params.get("ssh_subsystem_name")
90 name_list = [ "netconf", "xmlagent" ]
91 if preferred_ssh_subsystem:
92 return [ preferred_ssh_subsystem ] + \
93 [ n for n in name_list if n != preferred_ssh_subsystem ]
94 else:
95 return name_list
96