Convert pvc-client-cli into a proper Python module

Also fixes up the Debian packaging such that this works how I would
want, with proper module installation while leaving everything else
untouched. Finally implements automatic installation and removal of the
BASH completion for the PVC command.
This commit is contained in:
Joshua Boniface 2021-06-23 04:08:02 -04:00
parent f0db631947
commit f248d579df
21 changed files with 68 additions and 36 deletions

6
.gitignore vendored
View File

@ -1,4 +1,8 @@
*.pyc *.pyc
*.tmp *.tmp
*.swp *.swp
venv/ # Ignore build artifacts
debian/pvc-*/
debian/*.log
debian/*.substvars
debian/files

1
.version Normal file
View File

@ -0,0 +1 @@
0.9.20

View File

@ -7,7 +7,7 @@ if [[ -z ${new_version} ]]; then
exit 1 exit 1
fi fi
current_version="$( grep '^version = ' node-daemon/pvcnoded/Daemon.py | awk -F "'" '{ print $2 }' )" current_version="$( cat .version )"
echo "${current_version} -> ${new_version}" echo "${current_version} -> ${new_version}"
changelog_file=$( mktemp ) changelog_file=$( mktemp )
@ -18,6 +18,8 @@ changelog="$( cat ${changelog_file} | grep -v '^#' | sed 's/^*/ */' )"
sed -i "s,version = '${current_version}',version = '${new_version}'," node-daemon/pvcnoded/Daemon.py sed -i "s,version = '${current_version}',version = '${new_version}'," node-daemon/pvcnoded/Daemon.py
sed -i "s,version = '${current_version}',version = '${new_version}'," api-daemon/pvcapid/Daemon.py sed -i "s,version = '${current_version}',version = '${new_version}'," api-daemon/pvcapid/Daemon.py
sed -i "s,version='${current_version}',version='${new_version}'," client-cli/setup.py
echo ${new_version} > .version
readme_tmpdir=$( mktemp -d ) readme_tmpdir=$( mktemp -d )
cp README.md ${readme_tmpdir}/ cp README.md ${readme_tmpdir}/

View File

View File

View File

@ -24,8 +24,8 @@ import math
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import UploadProgressBar, call_api from pvc.cli_lib.common import UploadProgressBar, call_api
# #
# Supplemental functions # Supplemental functions

View File

@ -21,8 +21,8 @@
import json import json
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import call_api from pvc.cli_lib.common import call_api
def initialize(config, overwrite=False): def initialize(config, overwrite=False):

View File

@ -20,8 +20,8 @@
############################################################################### ###############################################################################
import re import re
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import call_api from pvc.cli_lib.common import call_api
def isValidMAC(macaddr): def isValidMAC(macaddr):

View File

@ -19,8 +19,8 @@
# #
############################################################################### ###############################################################################
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import call_api from pvc.cli_lib.common import call_api
# #

View File

@ -21,8 +21,8 @@
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import UploadProgressBar, call_api from pvc.cli_lib.common import UploadProgressBar, call_api
# #

View File

@ -22,8 +22,8 @@
import time import time
import re import re
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
from cli_lib.common import call_api, format_bytes, format_metric from pvc.cli_lib.common import call_api, format_bytes, format_metric
# #
@ -512,7 +512,7 @@ def vm_networks_add(config, vm, network, macaddr, model, sriov, sriov_mode, rest
from lxml.objectify import fromstring from lxml.objectify import fromstring
from lxml.etree import tostring from lxml.etree import tostring
from random import randint from random import randint
import cli_lib.network as pvc_network import pvc.cli_lib.network as pvc_network
# Verify that the provided network is valid (not in SR-IOV mode) # Verify that the provided network is valid (not in SR-IOV mode)
if not sriov: if not sriov:
@ -800,7 +800,7 @@ def vm_volumes_add(config, vm, volume, disk_id, bus, disk_type, restart):
from lxml.objectify import fromstring from lxml.objectify import fromstring
from lxml.etree import tostring from lxml.etree import tostring
from copy import deepcopy from copy import deepcopy
import cli_lib.ceph as pvc_ceph import pvc.cli_lib.ceph as pvc_ceph
if disk_type == 'rbd': if disk_type == 'rbd':
# Verify that the provided volume is valid # Verify that the provided volume is valid

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python3
# pvc.py - PVC client command-line interface # pvc.py - PVC client command-line interface
# Part of the Parallel Virtual Cluster (PVC) system # Part of the Parallel Virtual Cluster (PVC) system
# #
@ -34,13 +32,13 @@ from distutils.util import strtobool
from functools import wraps from functools import wraps
import cli_lib.ansiprint as ansiprint import pvc.cli_lib.ansiprint as ansiprint
import cli_lib.cluster as pvc_cluster import pvc.cli_lib.cluster as pvc_cluster
import cli_lib.node as pvc_node import pvc.cli_lib.node as pvc_node
import cli_lib.vm as pvc_vm import pvc.cli_lib.vm as pvc_vm
import cli_lib.network as pvc_network import pvc.cli_lib.network as pvc_network
import cli_lib.ceph as pvc_ceph import pvc.cli_lib.ceph as pvc_ceph
import cli_lib.provisioner as pvc_provisioner import pvc.cli_lib.provisioner as pvc_provisioner
myhostname = socket.gethostname().split('.')[0] myhostname = socket.gethostname().split('.')[0]
zk_host = '' zk_host = ''

20
client-cli/setup.py Normal file
View File

@ -0,0 +1,20 @@
from setuptools import setup
setup(
name='pvc',
version='0.9.20',
packages=['pvc', 'pvc.cli_lib'],
install_requires=[
'Click',
'PyYAML',
'lxml',
'colorama',
'requests',
'requests-toolbelt'
],
entry_points={
'console_scripts': [
'pvc = pvc.pvc:cli',
],
},
)

View File

@ -1,3 +0,0 @@
client-cli/pvc.py usr/share/pvc
client-cli/cli_lib usr/share/pvc
client-cli/scripts usr/share/pvc

View File

@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
# Install client binary to /usr/bin via symlink # Generate the bash completion configuration
ln -s /usr/share/pvc/pvc.py /usr/bin/pvc if [ -d /etc/bash_completion.d ]; then
_PVC_COMPLETE=source_bash pvc > /etc/bash_completion.d/pvc
fi

View File

@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
# Remove client binary symlink # Remove the bash completion
rm -f /usr/bin/pvc if [ -f /etc/bash_completion.d/pvc ]; then
rm -f /etc/bash_completion.d/pvc
fi

12
debian/rules vendored
View File

@ -1,13 +1,19 @@
#!/usr/bin/make -f #!/usr/bin/make -f
# See debhelper(7) (uncomment to enable) # See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system. # output every command that modifies files on the build system.
#export DH_VERBOSE = 1 export DH_VERBOSE = 1
%: %:
dh $@ dh $@ --with python3
override_dh_python3:
cd $(CURDIR)/client-cli; pybuild --system=distutils --dest-dir=../debian/pvc-client-cli/
mkdir -p debian/pvc-client-cli/usr/lib/python3
mv debian/pvc-client-cli/usr/lib/python3*/* debian/pvc-client-cli/usr/lib/python3/
rm -r $(CURDIR)/client-cli/.pybuild $(CURDIR)/client-cli/pvc.egg-info
override_dh_auto_clean: override_dh_auto_clean:
find . -name "__pycache__" -exec rm -r {} \; || true find . -name "__pycache__" -o -name ".pybuild" -exec rm -r {} \; || true
# If you need to rebuild the Sphinx documentation # If you need to rebuild the Sphinx documentation
# Add spinxdoc to the dh --with line # Add spinxdoc to the dh --with line

2
lint
View File

@ -7,7 +7,7 @@ fi
flake8 \ flake8 \
--ignore=E501 \ --ignore=E501 \
--exclude=venv,api-daemon/migrations/versions,api-daemon/provisioner/examples --exclude=debian,api-daemon/migrations/versions,api-daemon/provisioner/examples
ret=$? ret=$?
if [[ $ret -eq 0 ]]; then if [[ $ret -eq 0 ]]; then
echo "No linting issues found!" echo "No linting issues found!"