Debian Codegraph @

ansible_collections/community/ciscosmb/plugins/cliconf/ciscosmb.py

raw
1 #
2 # (c) 2017 Red Hat Inc.
3 #
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19 from __future__ import absolute_import, division, print_function
20
21 __metaclass__ = type
22
23 DOCUMENTATION = """
24 ---
25 author: Egor Zaitsev (@heuels)
26 name: ciscosmb
27 short_description: Use ciscosmb cliconf to run command on Cisco SMB network devices
28 description:
29 - This ciscosmb plugin provides low level abstraction apis for
30 sending and receiving CLI commands from Cisco SMB network devices.
31 """
32
33 import json
34
35 from ansible.plugins.cliconf import CliconfBase, enable_mode
36
37
38 class Cliconf(CliconfBase):
39
40 def get_device_info(self):
41 device_info = {}
42 device_info["network_os"] = "ciscosmb"
43
44 return device_info
45
46 @enable_mode
47 def get_config(self, source="running", flags=None, format=None):
48 if source not in ("running", "startup"):
49 raise ValueError("fetching configuration from %s is not supported" % source)
50
51 if format:
52 raise ValueError(
53 "'format' value %s is not supported for get_config" % format
54 )
55
56 if flags:
57 raise ValueError("'flags' value %s is not supported for get_config" % flags)
58
59 if source == "running":
60 cmd = "show running-config "
61 else:
62 cmd = "show startup-config "
63
64 return self.send_command(cmd)
65
66 def edit_config(self, command):
67 return
68
69 def get(
70 self,
71 command,
72 prompt=None,
73 answer=None,
74 sendonly=False,
75 newline=True,
76 check_all=False,
77 ):
78 return self.send_command(
79 command=command + "\n",
80 prompt=prompt,
81 answer=answer,
82 sendonly=sendonly,
83 newline=newline,
84 check_all=check_all,
85 )
86
87 def get_capabilities(self):
88 result = super().get_capabilities()
89 return json.dumps(result)
90
91 def get_serialization_profile(self, command=None):
92 return "ciscosmb" # This must match a profile defined elsewhere