diff options
Diffstat (limited to 'python-cannon.spec')
-rw-r--r-- | python-cannon.spec | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/python-cannon.spec b/python-cannon.spec new file mode 100644 index 0000000..21eed1b --- /dev/null +++ b/python-cannon.spec @@ -0,0 +1,320 @@ +%global _empty_manifest_terminate_build 0 +Name: python-cannon +Version: 0.0.80 +Release: 1 +Summary: An SSH automation tool based on Exscript +License: BSD-3-Clause +URL: https://github.com/mpenning/cannon +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/06/2b/e236809c880f4b642df9518675b2488c8ff0defb12e07b7bff4a35f12bc9/cannon-0.0.80.tar.gz +BuildArch: noarch + +Requires: python3-exscript +Requires: python3-loguru +Requires: python3-traits +Requires: python3-textfsm +Requires: python3-arrow + +%description +# Introduction + +[cannon][1] is a wrapper around [exscript][2] to connect with remote server or network +devices with ssh. + + +## Example Usage - Cisco IOS + +This script will login, run a few show commands. If you want an interactive session, set `interact=True` when calling Shell() + +```python +import sys + +from cannon import Shell, Account +from loguru import logger + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + sess = Shell( + host='route-views.routeviews.org', + # route-views doesn't need password + account= Account(name='rviews', password=''), + debug=0, + json_logfile='/tmp/cmd_log.json', + ) + + sess.execute('term len 0') + + sess.execute('show clock') + + sess.execute('show version') + version_text = sess.response + + # template is a TextFSM template + values = sess.execute('show ip int brief', + template="""Value INTF (\S+)\nValue IPADDR (\S+)\nValue STATUS (up|down|administratively down)\nValue PROTO (up|down)\n\nStart\n ^${INTF}\s+${IPADDR}\s+\w+\s+\w+\s+${STATUS}\s+${PROTO} -> Record""") + print("VALUES "+str(values)) + sess.close() +``` + +## Example Usage - Linux + +```python +from getpass import getpass +import sys + +from cannon.main import Shell, Account + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + account = Account("mpenning", getpass("Login password: ")) + conn = Shell(host="127.0.0.1", port=22, account=account, driver="generic", debug=0) + assert conn is not None + example_tfsm_template = """Value UNAME_LINE (.+) + +Start + ^${UNAME_LINE} +""" + print(conn.execute("sudo uname -a", debug=0, template=example_tfsm_template, timeout=2)) + print(conn.execute("whoami", debug=0, template=None, timeout=2)) + #print("FOO2", conn.response) + conn.close(force=True) + +if __name__=="__main__": + main() +``` + +## Example test suite setup + +- `git clone git@github.com:knipknap/Exscript` +- `cd` into `Exscript/tests/Exscript/protocols` and `chmod 600 id_rsa` +- exscript spawns a local tests ssh daemon, `pytest Exscript/tests/Exscript/protocols/SSH2Test.py` +- Connect with `ssh -i id_rsa -p 1236 user@localhost` +- one command is supported: `ls` + + [1]: https://pypi.python.org/pypi/cannon # cannon on pypi + [2]: https://pypi.python.org/pypi/exscript # Exscript on pypi + + +%package -n python3-cannon +Summary: An SSH automation tool based on Exscript +Provides: python-cannon +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-cannon +# Introduction + +[cannon][1] is a wrapper around [exscript][2] to connect with remote server or network +devices with ssh. + + +## Example Usage - Cisco IOS + +This script will login, run a few show commands. If you want an interactive session, set `interact=True` when calling Shell() + +```python +import sys + +from cannon import Shell, Account +from loguru import logger + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + sess = Shell( + host='route-views.routeviews.org', + # route-views doesn't need password + account= Account(name='rviews', password=''), + debug=0, + json_logfile='/tmp/cmd_log.json', + ) + + sess.execute('term len 0') + + sess.execute('show clock') + + sess.execute('show version') + version_text = sess.response + + # template is a TextFSM template + values = sess.execute('show ip int brief', + template="""Value INTF (\S+)\nValue IPADDR (\S+)\nValue STATUS (up|down|administratively down)\nValue PROTO (up|down)\n\nStart\n ^${INTF}\s+${IPADDR}\s+\w+\s+\w+\s+${STATUS}\s+${PROTO} -> Record""") + print("VALUES "+str(values)) + sess.close() +``` + +## Example Usage - Linux + +```python +from getpass import getpass +import sys + +from cannon.main import Shell, Account + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + account = Account("mpenning", getpass("Login password: ")) + conn = Shell(host="127.0.0.1", port=22, account=account, driver="generic", debug=0) + assert conn is not None + example_tfsm_template = """Value UNAME_LINE (.+) + +Start + ^${UNAME_LINE} +""" + print(conn.execute("sudo uname -a", debug=0, template=example_tfsm_template, timeout=2)) + print(conn.execute("whoami", debug=0, template=None, timeout=2)) + #print("FOO2", conn.response) + conn.close(force=True) + +if __name__=="__main__": + main() +``` + +## Example test suite setup + +- `git clone git@github.com:knipknap/Exscript` +- `cd` into `Exscript/tests/Exscript/protocols` and `chmod 600 id_rsa` +- exscript spawns a local tests ssh daemon, `pytest Exscript/tests/Exscript/protocols/SSH2Test.py` +- Connect with `ssh -i id_rsa -p 1236 user@localhost` +- one command is supported: `ls` + + [1]: https://pypi.python.org/pypi/cannon # cannon on pypi + [2]: https://pypi.python.org/pypi/exscript # Exscript on pypi + + +%package help +Summary: Development documents and examples for cannon +Provides: python3-cannon-doc +%description help +# Introduction + +[cannon][1] is a wrapper around [exscript][2] to connect with remote server or network +devices with ssh. + + +## Example Usage - Cisco IOS + +This script will login, run a few show commands. If you want an interactive session, set `interact=True` when calling Shell() + +```python +import sys + +from cannon import Shell, Account +from loguru import logger + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + sess = Shell( + host='route-views.routeviews.org', + # route-views doesn't need password + account= Account(name='rviews', password=''), + debug=0, + json_logfile='/tmp/cmd_log.json', + ) + + sess.execute('term len 0') + + sess.execute('show clock') + + sess.execute('show version') + version_text = sess.response + + # template is a TextFSM template + values = sess.execute('show ip int brief', + template="""Value INTF (\S+)\nValue IPADDR (\S+)\nValue STATUS (up|down|administratively down)\nValue PROTO (up|down)\n\nStart\n ^${INTF}\s+${IPADDR}\s+\w+\s+\w+\s+${STATUS}\s+${PROTO} -> Record""") + print("VALUES "+str(values)) + sess.close() +``` + +## Example Usage - Linux + +```python +from getpass import getpass +import sys + +from cannon.main import Shell, Account + +log_stderr_id = logger.add(sink=sys.stderr) + +@logger.catch(default=True, onerror=lambda _: sys.exit(1)) +def main(): + account = Account("mpenning", getpass("Login password: ")) + conn = Shell(host="127.0.0.1", port=22, account=account, driver="generic", debug=0) + assert conn is not None + example_tfsm_template = """Value UNAME_LINE (.+) + +Start + ^${UNAME_LINE} +""" + print(conn.execute("sudo uname -a", debug=0, template=example_tfsm_template, timeout=2)) + print(conn.execute("whoami", debug=0, template=None, timeout=2)) + #print("FOO2", conn.response) + conn.close(force=True) + +if __name__=="__main__": + main() +``` + +## Example test suite setup + +- `git clone git@github.com:knipknap/Exscript` +- `cd` into `Exscript/tests/Exscript/protocols` and `chmod 600 id_rsa` +- exscript spawns a local tests ssh daemon, `pytest Exscript/tests/Exscript/protocols/SSH2Test.py` +- Connect with `ssh -i id_rsa -p 1236 user@localhost` +- one command is supported: `ls` + + [1]: https://pypi.python.org/pypi/cannon # cannon on pypi + [2]: https://pypi.python.org/pypi/exscript # Exscript on pypi + + +%prep +%autosetup -n cannon-0.0.80 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-cannon -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.80-1 +- Package Spec generated |