Commit b95c26ab authored by David Seaward's avatar David Seaward
Browse files

Create ping and debug commands.


Signed-off-by: David Seaward's avatarDavid Seaward <david.seaward@puri.sm>
parent a7075ed8
.idea
*.egg-info
*~
dist/
build/
......@@ -4,10 +4,18 @@ verify_ssl = true
name = "pypi"
[packages]
click = '>=6.0,<7.0'
click = "<=7.0"
distro = "<=1.3.0"
strictyaml = "<=1.0.6"
pythonping = "<=1.0.8"
sh = "<=1.12.14"
[requires]
python_version = "3.7"
[dev-packages]
whipstaff = {path = ".", editable = true}
twine = "==1.12.1"
[requires]
python_version = "3.6"
[dev-packages.e1839a8]
path = "."
editable = true
{
"_meta": {
"hash": {
"sha256": "97259154cd5fd9090e2da105e033896c6562f26ea7a53b24cc2cac63c4a9c08e"
"sha256": "690bc12d2b88fe44ba57b8a17a05bc3aba42399a81d157b24119608c39d16959"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.6"
"python_version": "3.7"
},
"sources": [
{
......@@ -18,25 +18,261 @@
"default": {
"click": {
"hashes": [
"sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
"sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
],
"index": "pypi",
"version": "==6.7"
"version": "==7.0"
},
"distro": {
"hashes": [
"sha256:224041cef9600e72d19ae41ba006e71c05c4dc802516da715d7fda55ba3d8742",
"sha256:6ec8e539cf412830e5ccf521aecf879f2c7fcf60ce446e33cd16eef1ed8a0158"
],
"index": "pypi",
"version": "==1.3.0"
},
"python-dateutil": {
"hashes": [
"sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
"sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
],
"version": "==2.8.1"
},
"pythonping": {
"hashes": [
"sha256:05269d459d2290ff57665aa3b3c9ed1b64bb96106d22712e0054b52d51c6bb13"
],
"index": "pypi",
"version": "==1.0.8"
},
"ruamel.yaml": {
"hashes": [
"sha256:0962fd7999e064c4865f96fb1e23079075f4a2a14849bcdc5cdba53a24f9759b",
"sha256:099c644a778bf72ffa00524f78dd0b6476bca94a1da344130f4bf3381ce5b954"
],
"version": "==0.16.10"
},
"ruamel.yaml.clib": {
"hashes": [
"sha256:1e77424825caba5553bbade750cec2277ef130647d685c2b38f68bc03453bac6",
"sha256:392b7c371312abf27fb549ec2d5e0092f7ef6e6c9f767bfb13e83cb903aca0fd",
"sha256:4d55386129291b96483edcb93b381470f7cd69f97585829b048a3d758d31210a",
"sha256:550168c02d8de52ee58c3d8a8193d5a8a9491a5e7b2462d27ac5bf63717574c9",
"sha256:57933a6986a3036257ad7bf283529e7c19c2810ff24c86f4a0cfeb49d2099919",
"sha256:615b0396a7fad02d1f9a0dcf9f01202bf9caefee6265198f252c865f4227fcc6",
"sha256:77556a7aa190be9a2bd83b7ee075d3df5f3c5016d395613671487e79b082d784",
"sha256:7aee724e1ff424757b5bd8f6c5bbdb033a570b2b4683b17ace4dbe61a99a657b",
"sha256:8073c8b92b06b572e4057b583c3d01674ceaf32167801fe545a087d7a1e8bf52",
"sha256:9c6d040d0396c28d3eaaa6cb20152cb3b2f15adf35a0304f4f40a3cf9f1d2448",
"sha256:a0ff786d2a7dbe55f9544b3f6ebbcc495d7e730df92a08434604f6f470b899c5",
"sha256:b1b7fcee6aedcdc7e62c3a73f238b3d080c7ba6650cd808bce8d7761ec484070",
"sha256:b66832ea8077d9b3f6e311c4a53d06273db5dc2db6e8a908550f3c14d67e718c",
"sha256:be018933c2f4ee7de55e7bd7d0d801b3dfb09d21dad0cce8a97995fd3e44be30",
"sha256:d0d3ac228c9bbab08134b4004d748cf9f8743504875b3603b3afbb97e3472947",
"sha256:d10e9dd744cf85c219bf747c75194b624cc7a94f0c80ead624b06bfa9f61d3bc",
"sha256:ea4362548ee0cbc266949d8a441238d9ad3600ca9910c3fe4e82ee3a50706973",
"sha256:ed5b3698a2bb241b7f5cbbe277eaa7fe48b07a58784fba4f75224fd066d253ad",
"sha256:f9dcc1ae73f36e8059589b601e8e4776b9976effd76c21ad6a855a74318efd6e"
],
"markers": "platform_python_implementation == 'CPython' and python_version < '3.9'",
"version": "==0.2.0"
},
"sh": {
"hashes": [
"sha256:ae3258c5249493cebe73cb4e18253a41ed69262484bad36fdb3efcb8ad8870bb",
"sha256:b52bf5833ed01c7b5c5fb73a7f71b3d98d48e9b9b8764236237bdc7ecae850fc"
],
"index": "pypi",
"version": "==1.12.14"
},
"six": {
"hashes": [
"sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a",
"sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"
],
"version": "==1.14.0"
},
"strictyaml": {
"hashes": [
"sha256:dd687a32577e0b832619ce0552eac86d6afad5fa7b61ab041bb765881c6a1f36"
],
"index": "pypi",
"version": "==1.0.6"
}
},
"develop": {
"bleach": {
"hashes": [
"sha256:44f69771e2ac81ff30d929d485b7f9919f3ad6d019b6b20c74f3b8687c3f70df",
"sha256:aa8b870d0f46965bac2c073a93444636b0e1ca74e9777e34f03dd494b8a59d48"
],
"version": "==3.1.1"
},
"certifi": {
"hashes": [
"sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3",
"sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"
],
"version": "==2019.11.28"
},
"chardet": {
"hashes": [
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
],
"version": "==3.0.4"
},
"click": {
"hashes": [
"sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
"sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
"sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"
],
"index": "pypi",
"version": "==7.0"
},
"distro": {
"hashes": [
"sha256:224041cef9600e72d19ae41ba006e71c05c4dc802516da715d7fda55ba3d8742",
"sha256:6ec8e539cf412830e5ccf521aecf879f2c7fcf60ce446e33cd16eef1ed8a0158"
],
"index": "pypi",
"version": "==6.7"
"version": "==1.3.0"
},
"whipstaff": {
"docutils": {
"hashes": [
"sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af",
"sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc"
],
"version": "==0.16"
},
"e1839a8": {
"editable": true,
"path": "."
},
"idna": {
"hashes": [
"sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb",
"sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa"
],
"version": "==2.9"
},
"pkginfo": {
"hashes": [
"sha256:7424f2c8511c186cd5424bbf31045b77435b37a8d604990b79d4e70d741148bb",
"sha256:a6d9e40ca61ad3ebd0b72fbadd4fba16e4c0e4df0428c041e01e06eb6ee71f32"
],
"version": "==1.5.0.1"
},
"pygments": {
"hashes": [
"sha256:2a3fe295e54a20164a9df49c75fa58526d3be48e14aceba6d6b1e8ac0bfd6f1b",
"sha256:98c8aa5a9f778fcd1026a17361ddaf7330d1b7c62ae97c3bb0ae73e0b9b6b0fe"
],
"version": "==2.5.2"
},
"python-dateutil": {
"hashes": [
"sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
"sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
],
"version": "==2.8.1"
},
"readme-renderer": {
"hashes": [
"sha256:bb16f55b259f27f75f640acf5e00cf897845a8b3e4731b5c1a436e4b8529202f",
"sha256:c8532b79afc0375a85f10433eca157d6b50f7d6990f337fa498c96cd4bfc203d"
],
"version": "==24.0"
},
"requests": {
"hashes": [
"sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee",
"sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"
],
"version": "==2.23.0"
},
"requests-toolbelt": {
"hashes": [
"sha256:380606e1d10dc85c3bd47bf5a6095f815ec007be7a8b69c878507068df059e6f",
"sha256:968089d4584ad4ad7c171454f0a5c6dac23971e9472521ea3b6d49d610aa6fc0"
],
"version": "==0.9.1"
},
"ruamel.yaml": {
"hashes": [
"sha256:0962fd7999e064c4865f96fb1e23079075f4a2a14849bcdc5cdba53a24f9759b",
"sha256:099c644a778bf72ffa00524f78dd0b6476bca94a1da344130f4bf3381ce5b954"
],
"version": "==0.16.10"
},
"ruamel.yaml.clib": {
"hashes": [
"sha256:1e77424825caba5553bbade750cec2277ef130647d685c2b38f68bc03453bac6",
"sha256:392b7c371312abf27fb549ec2d5e0092f7ef6e6c9f767bfb13e83cb903aca0fd",
"sha256:4d55386129291b96483edcb93b381470f7cd69f97585829b048a3d758d31210a",
"sha256:550168c02d8de52ee58c3d8a8193d5a8a9491a5e7b2462d27ac5bf63717574c9",
"sha256:57933a6986a3036257ad7bf283529e7c19c2810ff24c86f4a0cfeb49d2099919",
"sha256:615b0396a7fad02d1f9a0dcf9f01202bf9caefee6265198f252c865f4227fcc6",
"sha256:77556a7aa190be9a2bd83b7ee075d3df5f3c5016d395613671487e79b082d784",
"sha256:7aee724e1ff424757b5bd8f6c5bbdb033a570b2b4683b17ace4dbe61a99a657b",
"sha256:8073c8b92b06b572e4057b583c3d01674ceaf32167801fe545a087d7a1e8bf52",
"sha256:9c6d040d0396c28d3eaaa6cb20152cb3b2f15adf35a0304f4f40a3cf9f1d2448",
"sha256:a0ff786d2a7dbe55f9544b3f6ebbcc495d7e730df92a08434604f6f470b899c5",
"sha256:b1b7fcee6aedcdc7e62c3a73f238b3d080c7ba6650cd808bce8d7761ec484070",
"sha256:b66832ea8077d9b3f6e311c4a53d06273db5dc2db6e8a908550f3c14d67e718c",
"sha256:be018933c2f4ee7de55e7bd7d0d801b3dfb09d21dad0cce8a97995fd3e44be30",
"sha256:d0d3ac228c9bbab08134b4004d748cf9f8743504875b3603b3afbb97e3472947",
"sha256:d10e9dd744cf85c219bf747c75194b624cc7a94f0c80ead624b06bfa9f61d3bc",
"sha256:ea4362548ee0cbc266949d8a441238d9ad3600ca9910c3fe4e82ee3a50706973",
"sha256:ed5b3698a2bb241b7f5cbbe277eaa7fe48b07a58784fba4f75224fd066d253ad",
"sha256:f9dcc1ae73f36e8059589b601e8e4776b9976effd76c21ad6a855a74318efd6e"
],
"markers": "platform_python_implementation == 'CPython' and python_version < '3.9'",
"version": "==0.2.0"
},
"six": {
"hashes": [
"sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a",
"sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"
],
"version": "==1.14.0"
},
"strictyaml": {
"hashes": [
"sha256:dd687a32577e0b832619ce0552eac86d6afad5fa7b61ab041bb765881c6a1f36"
],
"index": "pypi",
"version": "==1.0.6"
},
"tqdm": {
"hashes": [
"sha256:0d8b5afb66e23d80433102e9bd8b5c8b65d34c2a2255b2de58d97bd2ea8170fd",
"sha256:f35fb121bafa030bd94e74fcfd44f3c2830039a2ddef7fc87ef1c2d205237b24"
],
"version": "==4.43.0"
},
"twine": {
"hashes": [
"sha256:7d89bc6acafb31d124e6e5b295ef26ac77030bf098960c2a4c4e058335827c5c",
"sha256:fad6f1251195f7ddd1460cb76d6ea106c93adb4e56c41e0da79658e56e547d2c"
],
"index": "pypi",
"version": "==1.12.1"
},
"urllib3": {
"hashes": [
"sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc",
"sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc"
],
"version": "==1.25.8"
},
"webencodings": {
"hashes": [
"sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78",
"sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"
],
"version": "==0.5.1"
}
}
}
......@@ -9,16 +9,22 @@ implementation for an LDH operator toolkit.
## Installation
The preferred way to install Whipstaff is with your package manager.
The recommended package name is `ldh_operator`. For example:
The recommended package name is `ldh-operator`. For example:
sudo apt install ldh_operator # Debian-based (doesn't exist yet)
```bash
sudo apt install ldh-operator # Debian-based
```
or
pipx install ldh_operator # Python-based (doesn't exist yet)
```bash
pipx install ldh-operator # Python-based
```
## Usage
For help and a list of available commands:
```bash
whipstaff --help
```
......@@ -32,25 +38,57 @@ If you'd prefer to run from source...
2. Get source:
git clone https://source.puri.sm/liberty/ldh_operator.git
git clone https://source.puri.sm/liberty/tool/operator.git ldh_operator_toolkit
3. Install with pipenv:
cd ldh_operator
pipenv install
cd ldh_operator_toolkit
pipenv install --dev -e .
## Usage (from source)
```bash
cd ldh_operator
cd ldh_operator_toolkit
pipenv run whipstaff --help
```
or
```bash
cd ldh_operator_toolkit
pipenv shell
whipstaff --help
```
## Build wheel package (and optionally upload)
Follow these instructions to build Liberty CLI as a Python package:
```bash
git clone https://source.puri.sm/liberty/tool/operator.git ldh_operator_toolkit
cd ldh_operator_toolkit
pipenv install --dev
pipenv shell
# optionally edit default.yaml
python setup.py sdist bdist_wheel
```
If everything works as expected you should end up with the files:
* `dist/ldh_operator-<version>-py3-none-any.whl`
* `dist/ldh_operator-<version>.tar.gz`
You can now optionally upload the created Python package to PyPI using twine:
```bash
twine upload dist/*
```
## Sharing and contributions
Whipstaff (LDH operator)
<https://source.puri.sm/liberty/ldh_operator>
Copyright 2018 Purism SPC
Whipstaff (LDH operator toolkit)
<https://source.puri.sm/liberty/tool/operator>
Copyright 2018-2020 Purism SPC
SPDX-License-Identifier: AGPL-3.0-or-later
Shared under AGPL-3.0-or-later. We adhere to the Community Covenant
......@@ -65,9 +103,9 @@ For details see:
<!-- Links -->
[project]: https://source.puri.sm/liberty/ldh_operator
[code]: https://source.puri.sm/liberty/ldh_operator/tree/master
[tracker]: https://source.puri.sm/liberty/ldh_operator/issues
[project]: https://source.puri.sm/liberty/tool/operator
[code]: https://source.puri.sm/liberty/tool/operator/tree/master
[tracker]: https://source.puri.sm/liberty/tool/operator/issues
[SETUP.md]: SETUP.md
[COPYING.AGPL.md]: COPYING.AGPL.md
[CODE_OF_CONDUCT.md]: CODE_OF_CONDUCT.md
......
"localhost":
"localhost":
- ping
"Host":
"*":
- ping
"Chat":
"chat.*":
- ping
"xmpp.*":
- ping
"Files":
"files.*":
- ping
"Mail":
"imap.*":
- ping
"smtp.*":
- ping
"pop.*":
- ping
"Tunnel":
"*":
- ping
"Social":
"social.*":
- ping
"Sync":
"sync.*":
- ping
HOST_LABEL: Librem One
HOST_DOMAIN: librem.one
import pkg_resources
import strictyaml
default_yaml = pkg_resources.resource_string(__name__, "../data/default.yaml").decode('utf-8')
deckplan_yaml = pkg_resources.resource_string(__name__, "../data/deckplan.yaml").decode('utf-8')
DEFAULT = strictyaml.load(default_yaml)
DECKPLAN = strictyaml.load(deckplan_yaml)
#!/usr/bin/env python3
# Copyright 2017-2020 Purism SPC
# SPDX-License-Identifier: AGPL-3.0-or-later
# These default strings appear in user-facing prompts.
# The user can enter any address/host they want.
import ldh_operator
def debug():
import pkg_resources
import sys
import platform
import distro
import os
default_data = "Defaults " + ldh_operator.DEFAULT.as_yaml().replace("\n", " ").replace(" ", " ")
package_version = pkg_resources.require("ldh_operator")[0]
python_version = "Python " + sys.version.replace("\n", " ").replace(" ", " ")
platform_version = "Platform " + platform.platform()
distro_version = "Distribution " + distro.name(pretty=True)
path = "$PATH " + os.environ["PATH"].replace(os.environ["HOME"], "~")
print(default_data)
print(package_version)
print(python_version)
print(platform_version)
print(distro_version)
print(path)
def naive_ping(fqdn):
"""Use system ping on server."""
import sh
try:
result = "👍"
sh.ping("-c 4 -w 4", fqdn)
except:
result = "❌"
finally:
print(fqdn, "PING", result)
def ping():
"""Ping all known servers."""
for service_name in ldh_operator.DECKPLAN.data:
print(service_name)
domain_list = ldh_operator.DECKPLAN.data[service_name]
for domain in domain_list:
fqdn = domain.replace("*", str(ldh_operator.DEFAULT["HOST_DOMAIN"]))
test_list = domain_list[domain]
for test in test_list:
if test == "ping":
naive_ping(fqdn)
else:
pass # silently skip unknown tests
[metadata]
name = ldh_operator
version = 0.0.2
description = Whipstaff is a command-line tool for operating one or more Liberty Deckplan Hosts (LDHs) from your local session. The reference implementation for an LDH operator toolkit.
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
license = AGPL-3.0-or-later
author = Purism SPC
author_email = doublerainbows@librem.one
url = https://source.puri.sm/liberty/tool/operator
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
[options]
packages = find:
include_package_data = True
install_requires =
click<=7.0
distro<=1.3.0
strictyaml<=1.0.6
scripts = whipstaff.py
[options.entry_points]
console_scripts =
whipstaff = whipstaff:cli
[options.data_files]
. =
data/deckplan.yaml
data/default.yaml
from setuptools import setup
setup(
name='whipstaff',
version='0.0.1',
py_modules=['whipstaff'],
install_requires=[
'Click',
],
entry_points='''
[console_scripts]
whipstaff=whipstaff:cli
''',
)
setup()
import click
import ldh_operator.basic
@click.command()
def cli():
"""Example script."""
click.echo('Hello World!')
@click.group()
@click.pass_context
def cli(ctx):
"""Whipstaff is a command-line tool for operating one or more
Liberty Deckplan Hosts (LDHs) from your local session."""
pass
@cli.command()
def debug():
"""Show debug information suitable for bug reports."""
ldh_operator.basic.debug()
@cli.command()
def ping():
"""Ping all members of a Liberty Domain Host."""
ldh_operator.basic.ping()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment