diff options
Diffstat (limited to 'python-routeros-api.spec')
| -rw-r--r-- | python-routeros-api.spec | 475 |
1 files changed, 475 insertions, 0 deletions
diff --git a/python-routeros-api.spec b/python-routeros-api.spec new file mode 100644 index 0000000..b1f073f --- /dev/null +++ b/python-routeros-api.spec @@ -0,0 +1,475 @@ +%global _empty_manifest_terminate_build 0 +Name: python-RouterOS-api +Version: 0.17.0 +Release: 1 +Summary: Python API to RouterBoard devices produced by MikroTik. +License: MIT +URL: https://github.com/socialwifi/RouterOS-api +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/8f/ba/82083e74a915aa5e891be14359ec03bb4e5cf30251c3ca79fb93152b87c5/RouterOS-api-0.17.0.tar.gz +BuildArch: noarch + +Requires: python3-six + +%description +Python API to RouterBoard devices produced by MikroTik. +[](https://travis-ci.org/socialwifi/RouterOS-api) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://github.com/socialwifi/RouterOS-api/blob/master/LICENSE) +## Welcome to RouterOs Api + +Python API to RouterBoard devices produced by MikroTik. +## Usage +### Connection +```python +#!/usr/bin/python +import routeros_api +connection = routeros_api.RouterOsApiPool('IP', username='admin', password='') +api = connection.get_api() +``` +#### Connect Options +```python +routeros_api.RouterOsApiPool( + host, + username='admin', + password='', + port=8728, + use_ssl=False, + ssl_verify=True, + ssl_verify_hostname=True, + ssl_context=None, +) +``` +Parameters: +* `host` - String - Hostname or IP of device +Optional Parameters: +* `username` - String - Login username - Default 'admin' +* `password` - String - Login password - Default empty string +* `port` - Integer - TCP Port for API - Default 8728 or 8729 when using SSL +* `plaintext_login` - Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default **False** +* `use_ssl` - Boolean - Use SSL or not? - Default **False** +* `ssl_verify` - Boolean - Verify the SSL certificate? - Default **True** +* `ssl_verify_hostname` - Boolean - Verify the SSL certificate hostname matches? - Default **True** +* `ssl_context` - Object - Pass in a custom SSL context object. Overrides other options. - Default **None** +#### Using SSL +If we want to use SSL, we can simply specify `use_ssl` as `True`: +```python +connection = routeros_api.RouterOsApiPool('<IP>', username='admin', password='', use_ssl=True) +``` +This will automatically verify SSL certificate and hostname. +The most flexible way to modify SSL parameters is to provide an SSL Context object using the +`ssl_context` parameter, but for typical use-cases with self-signed certificates, the shorthand options of + `ssl_verify` and `ssl_verify_hostname` are provided. +e.g. if using a self-signed certificate, you can (but probably shouldn't) use: +```python +connection = routeros_api.RouterOsApiPool( + '<IP>', + username='admin', + password='', + use_ssl=True, + ssl_verify=False, + ssl_verify_hostname=False, +) +``` +#### Login for RouterOS v6.43 onwards +RouterOS Versions v6.43 onwards now use a different login method. +The disadvantage is that it passes the password in plain text. +For security we only attempt the plaintext login if requested using the `plaintext_login` parameter. +It is highly recommended only to use this option with SSL enabled. +```python +routeros_api.RouterOsApiPool(host, username='admin', password='', plaintext_login=True) +``` +### Execute Commands +Call this with a resource and parameters as name/value pairs. +```python +api.get_binary_resource('/').call('<resource>',{ <dict of params> }) +``` +#### Examples +```python +api.get_binary_resource('/').call('tool/fetch',{ 'url': "https://dummy.url" }) +api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' }) +``` +### Fetch List/Resource +```python +list = api.get_resource('/command') +``` +#### Example +```python +list_queues = api.get_resource('/queue/simple') +``` +#### Show all elements +```python +list_queues.get() +``` +### Add rules +```python +list.add(attribute="vale", attribute_n="value") +``` +**NOTE**: Atributes with `-`, like `max-limit` use underscore `_`: `max_limit` +#### Example: +```python +list_queues.add(name="001", max_limit="512k/4M", target="192.168.10.1/32") +``` +### Update Values +```python +list.set(id, attributes) +``` +#### Example: +```python +list_queues.set(id="*2", name="jhon") +``` +### Get element: +```python +list.get(attribute=value) +``` +#### Example: +```python +list_queues.get(name="jhon") +``` +### Remove element: +```python +list.remove(id) +``` +#### Example: +```python +list_queues.remove(id="*2") +``` +### Close conection: +```python +connection.disconnect() +``` +#### Other Example: +```python +list_address = api.get_resource('/ip/firewall/address-list') +list_address.add(address="192.168.0.1",comment="P1",list="10M") +list_address.get(comment="P1") +list_address.remove(id="*7") +``` + +%package -n python3-RouterOS-api +Summary: Python API to RouterBoard devices produced by MikroTik. +Provides: python-RouterOS-api +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-RouterOS-api +Python API to RouterBoard devices produced by MikroTik. +[](https://travis-ci.org/socialwifi/RouterOS-api) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://github.com/socialwifi/RouterOS-api/blob/master/LICENSE) +## Welcome to RouterOs Api + +Python API to RouterBoard devices produced by MikroTik. +## Usage +### Connection +```python +#!/usr/bin/python +import routeros_api +connection = routeros_api.RouterOsApiPool('IP', username='admin', password='') +api = connection.get_api() +``` +#### Connect Options +```python +routeros_api.RouterOsApiPool( + host, + username='admin', + password='', + port=8728, + use_ssl=False, + ssl_verify=True, + ssl_verify_hostname=True, + ssl_context=None, +) +``` +Parameters: +* `host` - String - Hostname or IP of device +Optional Parameters: +* `username` - String - Login username - Default 'admin' +* `password` - String - Login password - Default empty string +* `port` - Integer - TCP Port for API - Default 8728 or 8729 when using SSL +* `plaintext_login` - Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default **False** +* `use_ssl` - Boolean - Use SSL or not? - Default **False** +* `ssl_verify` - Boolean - Verify the SSL certificate? - Default **True** +* `ssl_verify_hostname` - Boolean - Verify the SSL certificate hostname matches? - Default **True** +* `ssl_context` - Object - Pass in a custom SSL context object. Overrides other options. - Default **None** +#### Using SSL +If we want to use SSL, we can simply specify `use_ssl` as `True`: +```python +connection = routeros_api.RouterOsApiPool('<IP>', username='admin', password='', use_ssl=True) +``` +This will automatically verify SSL certificate and hostname. +The most flexible way to modify SSL parameters is to provide an SSL Context object using the +`ssl_context` parameter, but for typical use-cases with self-signed certificates, the shorthand options of + `ssl_verify` and `ssl_verify_hostname` are provided. +e.g. if using a self-signed certificate, you can (but probably shouldn't) use: +```python +connection = routeros_api.RouterOsApiPool( + '<IP>', + username='admin', + password='', + use_ssl=True, + ssl_verify=False, + ssl_verify_hostname=False, +) +``` +#### Login for RouterOS v6.43 onwards +RouterOS Versions v6.43 onwards now use a different login method. +The disadvantage is that it passes the password in plain text. +For security we only attempt the plaintext login if requested using the `plaintext_login` parameter. +It is highly recommended only to use this option with SSL enabled. +```python +routeros_api.RouterOsApiPool(host, username='admin', password='', plaintext_login=True) +``` +### Execute Commands +Call this with a resource and parameters as name/value pairs. +```python +api.get_binary_resource('/').call('<resource>',{ <dict of params> }) +``` +#### Examples +```python +api.get_binary_resource('/').call('tool/fetch',{ 'url': "https://dummy.url" }) +api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' }) +``` +### Fetch List/Resource +```python +list = api.get_resource('/command') +``` +#### Example +```python +list_queues = api.get_resource('/queue/simple') +``` +#### Show all elements +```python +list_queues.get() +``` +### Add rules +```python +list.add(attribute="vale", attribute_n="value") +``` +**NOTE**: Atributes with `-`, like `max-limit` use underscore `_`: `max_limit` +#### Example: +```python +list_queues.add(name="001", max_limit="512k/4M", target="192.168.10.1/32") +``` +### Update Values +```python +list.set(id, attributes) +``` +#### Example: +```python +list_queues.set(id="*2", name="jhon") +``` +### Get element: +```python +list.get(attribute=value) +``` +#### Example: +```python +list_queues.get(name="jhon") +``` +### Remove element: +```python +list.remove(id) +``` +#### Example: +```python +list_queues.remove(id="*2") +``` +### Close conection: +```python +connection.disconnect() +``` +#### Other Example: +```python +list_address = api.get_resource('/ip/firewall/address-list') +list_address.add(address="192.168.0.1",comment="P1",list="10M") +list_address.get(comment="P1") +list_address.remove(id="*7") +``` + +%package help +Summary: Development documents and examples for RouterOS-api +Provides: python3-RouterOS-api-doc +%description help +Python API to RouterBoard devices produced by MikroTik. +[](https://travis-ci.org/socialwifi/RouterOS-api) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://pypi.python.org/pypi/RouterOS-api/) +[](https://github.com/socialwifi/RouterOS-api/blob/master/LICENSE) +## Welcome to RouterOs Api + +Python API to RouterBoard devices produced by MikroTik. +## Usage +### Connection +```python +#!/usr/bin/python +import routeros_api +connection = routeros_api.RouterOsApiPool('IP', username='admin', password='') +api = connection.get_api() +``` +#### Connect Options +```python +routeros_api.RouterOsApiPool( + host, + username='admin', + password='', + port=8728, + use_ssl=False, + ssl_verify=True, + ssl_verify_hostname=True, + ssl_context=None, +) +``` +Parameters: +* `host` - String - Hostname or IP of device +Optional Parameters: +* `username` - String - Login username - Default 'admin' +* `password` - String - Login password - Default empty string +* `port` - Integer - TCP Port for API - Default 8728 or 8729 when using SSL +* `plaintext_login` - Boolean - Try plaintext login (for RouterOS 6.43 onwards) - Default **False** +* `use_ssl` - Boolean - Use SSL or not? - Default **False** +* `ssl_verify` - Boolean - Verify the SSL certificate? - Default **True** +* `ssl_verify_hostname` - Boolean - Verify the SSL certificate hostname matches? - Default **True** +* `ssl_context` - Object - Pass in a custom SSL context object. Overrides other options. - Default **None** +#### Using SSL +If we want to use SSL, we can simply specify `use_ssl` as `True`: +```python +connection = routeros_api.RouterOsApiPool('<IP>', username='admin', password='', use_ssl=True) +``` +This will automatically verify SSL certificate and hostname. +The most flexible way to modify SSL parameters is to provide an SSL Context object using the +`ssl_context` parameter, but for typical use-cases with self-signed certificates, the shorthand options of + `ssl_verify` and `ssl_verify_hostname` are provided. +e.g. if using a self-signed certificate, you can (but probably shouldn't) use: +```python +connection = routeros_api.RouterOsApiPool( + '<IP>', + username='admin', + password='', + use_ssl=True, + ssl_verify=False, + ssl_verify_hostname=False, +) +``` +#### Login for RouterOS v6.43 onwards +RouterOS Versions v6.43 onwards now use a different login method. +The disadvantage is that it passes the password in plain text. +For security we only attempt the plaintext login if requested using the `plaintext_login` parameter. +It is highly recommended only to use this option with SSL enabled. +```python +routeros_api.RouterOsApiPool(host, username='admin', password='', plaintext_login=True) +``` +### Execute Commands +Call this with a resource and parameters as name/value pairs. +```python +api.get_binary_resource('/').call('<resource>',{ <dict of params> }) +``` +#### Examples +```python +api.get_binary_resource('/').call('tool/fetch',{ 'url': "https://dummy.url" }) +api.get_binary_resource('/').call('ping', { 'address': '192.168.56.1', 'count': '4' }) +``` +### Fetch List/Resource +```python +list = api.get_resource('/command') +``` +#### Example +```python +list_queues = api.get_resource('/queue/simple') +``` +#### Show all elements +```python +list_queues.get() +``` +### Add rules +```python +list.add(attribute="vale", attribute_n="value") +``` +**NOTE**: Atributes with `-`, like `max-limit` use underscore `_`: `max_limit` +#### Example: +```python +list_queues.add(name="001", max_limit="512k/4M", target="192.168.10.1/32") +``` +### Update Values +```python +list.set(id, attributes) +``` +#### Example: +```python +list_queues.set(id="*2", name="jhon") +``` +### Get element: +```python +list.get(attribute=value) +``` +#### Example: +```python +list_queues.get(name="jhon") +``` +### Remove element: +```python +list.remove(id) +``` +#### Example: +```python +list_queues.remove(id="*2") +``` +### Close conection: +```python +connection.disconnect() +``` +#### Other Example: +```python +list_address = api.get_resource('/ip/firewall/address-list') +list_address.add(address="192.168.0.1",comment="P1",list="10M") +list_address.get(comment="P1") +list_address.remove(id="*7") +``` + +%prep +%autosetup -n RouterOS-api-0.17.0 + +%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-RouterOS-api -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.17.0-1 +- Package Spec generated |
