linuxfabrik-lib 2.0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- linuxfabrik_lib-2.0.0.0/LICENSE.txt +24 -0
- linuxfabrik_lib-2.0.0.0/PKG-INFO +171 -0
- linuxfabrik_lib-2.0.0.0/README.md +122 -0
- linuxfabrik_lib-2.0.0.0/__init__.py +1 -0
- linuxfabrik_lib-2.0.0.0/args.py +107 -0
- linuxfabrik_lib-2.0.0.0/base.py +695 -0
- linuxfabrik_lib-2.0.0.0/cache.py +144 -0
- linuxfabrik_lib-2.0.0.0/db_mysql.py +154 -0
- linuxfabrik_lib-2.0.0.0/db_sqlite.py +518 -0
- linuxfabrik_lib-2.0.0.0/disk.py +321 -0
- linuxfabrik_lib-2.0.0.0/distro.py +263 -0
- linuxfabrik_lib-2.0.0.0/dmidecode.py +233 -0
- linuxfabrik_lib-2.0.0.0/endoflifedate.py +2894 -0
- linuxfabrik_lib-2.0.0.0/feedparser.py +129 -0
- linuxfabrik_lib-2.0.0.0/globals.py +42 -0
- linuxfabrik_lib-2.0.0.0/grassfish.py +157 -0
- linuxfabrik_lib-2.0.0.0/huawei.py +563 -0
- linuxfabrik_lib-2.0.0.0/human.py +358 -0
- linuxfabrik_lib-2.0.0.0/icinga.py +225 -0
- linuxfabrik_lib-2.0.0.0/infomaniak.py +96 -0
- linuxfabrik_lib-2.0.0.0/jitsi.py +52 -0
- linuxfabrik_lib-2.0.0.0/keycloak.py +67 -0
- linuxfabrik_lib-2.0.0.0/lftest.py +42 -0
- linuxfabrik_lib-2.0.0.0/librenms.py +68 -0
- linuxfabrik_lib-2.0.0.0/linuxfabrik_lib.egg-info/PKG-INFO +171 -0
- linuxfabrik_lib-2.0.0.0/linuxfabrik_lib.egg-info/SOURCES.txt +82 -0
- linuxfabrik_lib-2.0.0.0/linuxfabrik_lib.egg-info/dependency_links.txt +1 -0
- linuxfabrik_lib-2.0.0.0/linuxfabrik_lib.egg-info/requires.txt +14 -0
- linuxfabrik_lib-2.0.0.0/linuxfabrik_lib.egg-info/top_level.txt +1 -0
- linuxfabrik_lib-2.0.0.0/net.py +297 -0
- linuxfabrik_lib-2.0.0.0/nodebb.py +34 -0
- linuxfabrik_lib-2.0.0.0/powershell.py +41 -0
- linuxfabrik_lib-2.0.0.0/psutil.py +41 -0
- linuxfabrik_lib-2.0.0.0/pyproject.toml +68 -0
- linuxfabrik_lib-2.0.0.0/qts.py +80 -0
- linuxfabrik_lib-2.0.0.0/redfish.py +308 -0
- linuxfabrik_lib-2.0.0.0/rocket.py +82 -0
- linuxfabrik_lib-2.0.0.0/setup.cfg +4 -0
- linuxfabrik_lib-2.0.0.0/shell.py +165 -0
- linuxfabrik_lib-2.0.0.0/smb.py +85 -0
- linuxfabrik_lib-2.0.0.0/time.py +84 -0
- linuxfabrik_lib-2.0.0.0/txt.py +438 -0
- linuxfabrik_lib-2.0.0.0/url.py +188 -0
- linuxfabrik_lib-2.0.0.0/veeam.py +60 -0
- linuxfabrik_lib-2.0.0.0/version.py +252 -0
- linuxfabrik_lib-2.0.0.0/wildfly.py +44 -0
- linuxfabrik_lib-2.0.0.0/winrm.py +83 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: linuxfabrik-lib
|
|
3
|
+
Version: 2.0.0.0
|
|
4
|
+
Summary: Python libraries used in various Linuxfabrik projects, including the 'Linuxfabrik Monitoring Plugins' project.
|
|
5
|
+
Author-email: "Linuxfabrik GmbH, Zurich, Switzerland" <info@linuxfabrik.ch>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Linuxfabrik/lib
|
|
7
|
+
Project-URL: Documentation, https://github.com/Linuxfabrik/lib/blob/master/README.md
|
|
8
|
+
Project-URL: Source, https://github.com/Linuxfabrik/lib
|
|
9
|
+
Project-URL: Tracker, https://github.com/Linuxfabrik/lib/issues
|
|
10
|
+
Project-URL: Download, https://github.com/Linuxfabrik/lib/releases
|
|
11
|
+
Keywords: lib,libs,monitoring,monitoring plugins,icinga,nagios
|
|
12
|
+
Classifier: Development Status :: 6 - Mature
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
|
17
|
+
Classifier: Intended Audience :: Manufacturing
|
|
18
|
+
Classifier: Intended Audience :: Other Audience
|
|
19
|
+
Classifier: Intended Audience :: Science/Research
|
|
20
|
+
Classifier: Intended Audience :: System Administrators
|
|
21
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
22
|
+
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
|
23
|
+
Classifier: Natural Language :: English
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Classifier: Programming Language :: Python
|
|
26
|
+
Classifier: Programming Language :: Python :: 3
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Classifier: Topic :: System
|
|
30
|
+
Classifier: Topic :: System :: Monitoring
|
|
31
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
32
|
+
Requires-Python: >=3.6
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE.txt
|
|
35
|
+
Requires-Dist: beautifulsoup4
|
|
36
|
+
Requires-Dist: lxml
|
|
37
|
+
Requires-Dist: netifaces
|
|
38
|
+
Requires-Dist: psutil
|
|
39
|
+
Requires-Dist: pymysql
|
|
40
|
+
Requires-Dist: pysmbclient
|
|
41
|
+
Requires-Dist: python-keystoneclient
|
|
42
|
+
Requires-Dist: python-novaclient
|
|
43
|
+
Requires-Dist: python-swiftclient
|
|
44
|
+
Requires-Dist: pywinrm
|
|
45
|
+
Requires-Dist: requests
|
|
46
|
+
Requires-Dist: smbprotocol
|
|
47
|
+
Requires-Dist: vici
|
|
48
|
+
Requires-Dist: xmltodict
|
|
49
|
+
|
|
50
|
+
# Linuxfabrik's Python Libraries
|
|
51
|
+
|
|
52
|
+
These Python libraries are used in various projects of Linuxfabrik, including the [Linuxfabrik Monitoring Plugins project](https://github.com/Linuxfabrik/monitoring-plugins).
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
`pip install linuxfabrik-lib`
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
For example by browsing http://localhost:8080/ after starting `pydoc -p 8080`.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## List of libraries
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
* args.py:
|
|
69
|
+
Extends argparse by new input argument data types on demand.
|
|
70
|
+
|
|
71
|
+
* base.py:
|
|
72
|
+
Provides very common every-day functions.
|
|
73
|
+
|
|
74
|
+
* cache.py:
|
|
75
|
+
Simple Cache in the form of a Key-Value Store (KVS) like Redis, based on SQLite, optionally supporting expiration of keys. No detailed error handling here. If the cache does not work, we (currently) don't report the reason and simply return `False`.
|
|
76
|
+
|
|
77
|
+
* db_mysql.py:
|
|
78
|
+
Library for accessing MySQL/MariaDB servers.
|
|
79
|
+
|
|
80
|
+
* db_sqlite.py:
|
|
81
|
+
Library for accessing SQLite databases.
|
|
82
|
+
|
|
83
|
+
* disk.py:
|
|
84
|
+
Offers file and disk related functions, like getting a list of partitions, grepping a file, etc.
|
|
85
|
+
|
|
86
|
+
* distro.py:
|
|
87
|
+
Provides information about the Linux distribution it runs on, such as a reliable machine-readable distro ID and "os_family" (known from Ansible).
|
|
88
|
+
|
|
89
|
+
* dmidecode.py:
|
|
90
|
+
Library for parsing information from dmidecode. Have a look at `man dmidecode` for details about dmidecode.
|
|
91
|
+
|
|
92
|
+
* endoflifedate.py:
|
|
93
|
+
This library stores information from https://endoflife.date/api/ for offline usage and therefore needs to be updated periodically when version checks don't have access to the Internet.
|
|
94
|
+
|
|
95
|
+
* feedparser.py:
|
|
96
|
+
Parse Atom and RSS feeds in Python.
|
|
97
|
+
|
|
98
|
+
* globals.py:
|
|
99
|
+
This library defines the global plugin states, based on the POSIX spec of returning a positive value and just like in `monitoring-plugins/plugins-scripts/utils.sh.in`, except that we do not make use of `STATE_DEPENDENT`.
|
|
100
|
+
|
|
101
|
+
* grassfish.py:
|
|
102
|
+
Provides functions using the Grassfish REST-API.
|
|
103
|
+
|
|
104
|
+
* huawei.py:
|
|
105
|
+
This library collects some Huawei related functions that are needed by Huawei check plugins.
|
|
106
|
+
|
|
107
|
+
* human.py:
|
|
108
|
+
Functions to convert raw numbers, times etc. to a human readable representation (and sometimes back).
|
|
109
|
+
|
|
110
|
+
* icinga.py:
|
|
111
|
+
This module tries to make accessing the Icinga2 API easier.
|
|
112
|
+
|
|
113
|
+
* infomaniak.py:
|
|
114
|
+
Provides functions using the Infomanik REST-API.
|
|
115
|
+
|
|
116
|
+
* jitsi.py:
|
|
117
|
+
This library collects some Jitsi related functions that are needed by more than one Jitsi plugin.
|
|
118
|
+
|
|
119
|
+
* keycloak.py:
|
|
120
|
+
This library collects some Keycloak related functions that are needed by more than one Keycloak plugin.
|
|
121
|
+
|
|
122
|
+
* librenms.py:
|
|
123
|
+
This library collects some LibreNMS related functions that are needed by LibreNMS check plugins.
|
|
124
|
+
|
|
125
|
+
* net.py:
|
|
126
|
+
Provides network related functions and variables.
|
|
127
|
+
|
|
128
|
+
* nodebb.py:
|
|
129
|
+
This library collects some NodeBB related functions that are needed by more than one NodeBB plugin.
|
|
130
|
+
|
|
131
|
+
* powershell.py:
|
|
132
|
+
This library collects some Microsoft PowerShell related functions.
|
|
133
|
+
|
|
134
|
+
* psutil.py:
|
|
135
|
+
Wrapper library for functions from psutil.
|
|
136
|
+
|
|
137
|
+
* redfish.py:
|
|
138
|
+
This library parses data returned from the Redfish API.
|
|
139
|
+
|
|
140
|
+
* rocket.py:
|
|
141
|
+
This library collects some Rocket.Chat related functions that are needed by more than one Rocket.Chat plugin.
|
|
142
|
+
|
|
143
|
+
* shell.py:
|
|
144
|
+
Communicates with the Shell.
|
|
145
|
+
|
|
146
|
+
* smb.py:
|
|
147
|
+
Provides functions to establish native SMB connections.
|
|
148
|
+
|
|
149
|
+
* test.py:
|
|
150
|
+
Provides test functions for unit tests.
|
|
151
|
+
|
|
152
|
+
* time.py:
|
|
153
|
+
Provides datetime functions.
|
|
154
|
+
|
|
155
|
+
* txt.py:
|
|
156
|
+
A collection of text functions.
|
|
157
|
+
|
|
158
|
+
* url.py:
|
|
159
|
+
Get for example HTML or JSON from an URL.
|
|
160
|
+
|
|
161
|
+
* veeam.py:
|
|
162
|
+
This library interacts with the Veeam Enterprise Manager API.
|
|
163
|
+
|
|
164
|
+
* version.py:
|
|
165
|
+
Provides functions for handling software versions.
|
|
166
|
+
|
|
167
|
+
* wildfly.py:
|
|
168
|
+
This library collects some WildFly/JBoss related functions that are needed by more than one WildFly/JBoss plugin.
|
|
169
|
+
|
|
170
|
+
* winrm.py:
|
|
171
|
+
This library collects some Microsoft WinRM related functions.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Linuxfabrik's Python Libraries
|
|
2
|
+
|
|
3
|
+
These Python libraries are used in various projects of Linuxfabrik, including the [Linuxfabrik Monitoring Plugins project](https://github.com/Linuxfabrik/monitoring-plugins).
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
`pip install linuxfabrik-lib`
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
For example by browsing http://localhost:8080/ after starting `pydoc -p 8080`.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## List of libraries
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
* args.py:
|
|
20
|
+
Extends argparse by new input argument data types on demand.
|
|
21
|
+
|
|
22
|
+
* base.py:
|
|
23
|
+
Provides very common every-day functions.
|
|
24
|
+
|
|
25
|
+
* cache.py:
|
|
26
|
+
Simple Cache in the form of a Key-Value Store (KVS) like Redis, based on SQLite, optionally supporting expiration of keys. No detailed error handling here. If the cache does not work, we (currently) don't report the reason and simply return `False`.
|
|
27
|
+
|
|
28
|
+
* db_mysql.py:
|
|
29
|
+
Library for accessing MySQL/MariaDB servers.
|
|
30
|
+
|
|
31
|
+
* db_sqlite.py:
|
|
32
|
+
Library for accessing SQLite databases.
|
|
33
|
+
|
|
34
|
+
* disk.py:
|
|
35
|
+
Offers file and disk related functions, like getting a list of partitions, grepping a file, etc.
|
|
36
|
+
|
|
37
|
+
* distro.py:
|
|
38
|
+
Provides information about the Linux distribution it runs on, such as a reliable machine-readable distro ID and "os_family" (known from Ansible).
|
|
39
|
+
|
|
40
|
+
* dmidecode.py:
|
|
41
|
+
Library for parsing information from dmidecode. Have a look at `man dmidecode` for details about dmidecode.
|
|
42
|
+
|
|
43
|
+
* endoflifedate.py:
|
|
44
|
+
This library stores information from https://endoflife.date/api/ for offline usage and therefore needs to be updated periodically when version checks don't have access to the Internet.
|
|
45
|
+
|
|
46
|
+
* feedparser.py:
|
|
47
|
+
Parse Atom and RSS feeds in Python.
|
|
48
|
+
|
|
49
|
+
* globals.py:
|
|
50
|
+
This library defines the global plugin states, based on the POSIX spec of returning a positive value and just like in `monitoring-plugins/plugins-scripts/utils.sh.in`, except that we do not make use of `STATE_DEPENDENT`.
|
|
51
|
+
|
|
52
|
+
* grassfish.py:
|
|
53
|
+
Provides functions using the Grassfish REST-API.
|
|
54
|
+
|
|
55
|
+
* huawei.py:
|
|
56
|
+
This library collects some Huawei related functions that are needed by Huawei check plugins.
|
|
57
|
+
|
|
58
|
+
* human.py:
|
|
59
|
+
Functions to convert raw numbers, times etc. to a human readable representation (and sometimes back).
|
|
60
|
+
|
|
61
|
+
* icinga.py:
|
|
62
|
+
This module tries to make accessing the Icinga2 API easier.
|
|
63
|
+
|
|
64
|
+
* infomaniak.py:
|
|
65
|
+
Provides functions using the Infomanik REST-API.
|
|
66
|
+
|
|
67
|
+
* jitsi.py:
|
|
68
|
+
This library collects some Jitsi related functions that are needed by more than one Jitsi plugin.
|
|
69
|
+
|
|
70
|
+
* keycloak.py:
|
|
71
|
+
This library collects some Keycloak related functions that are needed by more than one Keycloak plugin.
|
|
72
|
+
|
|
73
|
+
* librenms.py:
|
|
74
|
+
This library collects some LibreNMS related functions that are needed by LibreNMS check plugins.
|
|
75
|
+
|
|
76
|
+
* net.py:
|
|
77
|
+
Provides network related functions and variables.
|
|
78
|
+
|
|
79
|
+
* nodebb.py:
|
|
80
|
+
This library collects some NodeBB related functions that are needed by more than one NodeBB plugin.
|
|
81
|
+
|
|
82
|
+
* powershell.py:
|
|
83
|
+
This library collects some Microsoft PowerShell related functions.
|
|
84
|
+
|
|
85
|
+
* psutil.py:
|
|
86
|
+
Wrapper library for functions from psutil.
|
|
87
|
+
|
|
88
|
+
* redfish.py:
|
|
89
|
+
This library parses data returned from the Redfish API.
|
|
90
|
+
|
|
91
|
+
* rocket.py:
|
|
92
|
+
This library collects some Rocket.Chat related functions that are needed by more than one Rocket.Chat plugin.
|
|
93
|
+
|
|
94
|
+
* shell.py:
|
|
95
|
+
Communicates with the Shell.
|
|
96
|
+
|
|
97
|
+
* smb.py:
|
|
98
|
+
Provides functions to establish native SMB connections.
|
|
99
|
+
|
|
100
|
+
* test.py:
|
|
101
|
+
Provides test functions for unit tests.
|
|
102
|
+
|
|
103
|
+
* time.py:
|
|
104
|
+
Provides datetime functions.
|
|
105
|
+
|
|
106
|
+
* txt.py:
|
|
107
|
+
A collection of text functions.
|
|
108
|
+
|
|
109
|
+
* url.py:
|
|
110
|
+
Get for example HTML or JSON from an URL.
|
|
111
|
+
|
|
112
|
+
* veeam.py:
|
|
113
|
+
This library interacts with the Veeam Enterprise Manager API.
|
|
114
|
+
|
|
115
|
+
* version.py:
|
|
116
|
+
Provides functions for handling software versions.
|
|
117
|
+
|
|
118
|
+
* wildfly.py:
|
|
119
|
+
This library collects some WildFly/JBoss related functions that are needed by more than one WildFly/JBoss plugin.
|
|
120
|
+
|
|
121
|
+
* winrm.py:
|
|
122
|
+
This library collects some Microsoft WinRM related functions.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# needed in order to be able to import from this directory
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8; py-indent-offset: 4 -*-
|
|
3
|
+
#
|
|
4
|
+
# Author: Linuxfabrik GmbH, Zurich, Switzerland
|
|
5
|
+
# Contact: info (at) linuxfabrik (dot) ch
|
|
6
|
+
# https://www.linuxfabrik.ch/
|
|
7
|
+
# License: The Unlicense, see LICENSE file.
|
|
8
|
+
|
|
9
|
+
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst
|
|
10
|
+
|
|
11
|
+
"""Extends argparse by new input argument data types on demand.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import re # pylint: disable=C0413
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
|
|
18
|
+
__version__ = '2024033101'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def csv(arg):
|
|
22
|
+
"""Returns a list from a `csv` input argument.
|
|
23
|
+
"""
|
|
24
|
+
return [x.strip() for x in arg.split(',')]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def float_or_none(arg):
|
|
28
|
+
"""Returns None or float from a `float_or_none` input argument.
|
|
29
|
+
"""
|
|
30
|
+
if arg is None or str(arg).lower() == 'none':
|
|
31
|
+
return None
|
|
32
|
+
return float(arg)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def help(param):
|
|
36
|
+
"""Return global valid help text for a parameter.
|
|
37
|
+
"""
|
|
38
|
+
h = {
|
|
39
|
+
'--match':
|
|
40
|
+
'Uses Python regular expressions without any external flags like `re.IGNORECASE`. '
|
|
41
|
+
'The regular expression is applied to each line of the output. '
|
|
42
|
+
'Examples: '
|
|
43
|
+
'`(?i)example` to match the word "example" in a case-insensitive manner. '
|
|
44
|
+
'`^(?!.*example).*$` to match any string except "example" (negative lookahead). '
|
|
45
|
+
'`(?: ... )*` is a non-capturing group that matches any sequence of characters '
|
|
46
|
+
'that satisfy the condition inside it, zero or more times. ',
|
|
47
|
+
}
|
|
48
|
+
return h[param]
|
|
49
|
+
try:
|
|
50
|
+
return h[param]
|
|
51
|
+
except KeyError:
|
|
52
|
+
return ''
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def int_or_none(arg):
|
|
56
|
+
"""Returns None or int from a `int_or_none` input argument.
|
|
57
|
+
"""
|
|
58
|
+
if arg is None or str(arg).lower() == 'none':
|
|
59
|
+
return None
|
|
60
|
+
return int(arg)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def number_unit_method(arg, unit='%', method='USED'):
|
|
64
|
+
"""Expects '<number>[unit][method]. Useful for threshold arguments.
|
|
65
|
+
Number is an integer or float.
|
|
66
|
+
Unit is one of `%%|K|M|G|T|P`.
|
|
67
|
+
If "unit" is omitted, `%` is assumed.
|
|
68
|
+
`K` means `kibibyte` etc.
|
|
69
|
+
Method is one of `USED|FREE`.
|
|
70
|
+
If "method" is ommitted, `USED` is assumed.
|
|
71
|
+
Examples: '
|
|
72
|
+
* `95`: returns (95, '%', 'USED')
|
|
73
|
+
* `9.5M`: returns (9.5, 'M', 'USED')
|
|
74
|
+
* `95%USED`: returns (95, '%', 'USED')
|
|
75
|
+
* `5FREE`: : returns (5, '%', 'FREE')
|
|
76
|
+
* `5%FREE`: : returns (5, '%', 'FREE')
|
|
77
|
+
* `9.5GFREE`: returns (9.5, 'G', 'FREE')
|
|
78
|
+
* `1400GUSED`: returns (1400, 'G', 'USED')
|
|
79
|
+
"""
|
|
80
|
+
# use named groups in regex
|
|
81
|
+
regex = re.compile(
|
|
82
|
+
r'(?P<number>\d*\.?\d*)(?P<unit>%|K|M|G|T|P)?(?P<method>USED|FREE)?',
|
|
83
|
+
re.IGNORECASE,
|
|
84
|
+
)
|
|
85
|
+
match = re.search(regex, arg)
|
|
86
|
+
if match and match.groupdict().get('number'):
|
|
87
|
+
arg = match.groupdict().get('number').strip()
|
|
88
|
+
if match and match.groupdict().get('unit'):
|
|
89
|
+
unit = match.groupdict().get('unit').strip()
|
|
90
|
+
if match and match.groupdict().get('method'):
|
|
91
|
+
method = match.groupdict().get('method').strip()
|
|
92
|
+
return arg, unit.upper(), method.upper()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def range_or_none(arg):
|
|
96
|
+
"""Returns None or range from a `range_or_none` input argument.
|
|
97
|
+
"""
|
|
98
|
+
return str_or_none(arg)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def str_or_none(arg):
|
|
102
|
+
"""Returns None or str from a `str_or_none` input argument.
|
|
103
|
+
"""
|
|
104
|
+
if arg is None or str(arg).lower() == 'none':
|
|
105
|
+
return None
|
|
106
|
+
return str(arg)
|
|
107
|
+
|