From 6ade378cc9a8f0c4e5cca201c3542d0c21e19b0d Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 17 Jun 2018 14:55:13 -0400 Subject: [PATCH] Debianize the packaging --- debian/changelog | 5 +++ debian/compat | 1 + debian/control | 28 ++++++++++++ debian/copyright | 38 +++++++++++++++++ debian/pvc-client.install | 2 + debian/pvc-client.postinst | 4 ++ debian/pvc-client.prerm | 4 ++ debian/pvc-daemon.install | 4 ++ debian/pvc-daemon.postinst | 6 +++ debian/pvc-daemon.prerm | 5 +++ debian/rules | 16 +++++++ debian/source/format | 1 + debian/source/options | 1 + install.sh | 6 --- pvcd.conf => pvcd.conf.sample | 15 ++++--- pvcd.py | 6 +-- pvcd.service | 7 ++- {pvc => pvcd}/NodeInstance.py | 2 +- {pvc => pvcd}/VMInstance.py | 2 +- pvcd/__init__.py | 0 pvcd/ansiiprint.py | 80 +++++++++++++++++++++++++++++++++++ 21 files changed, 211 insertions(+), 22 deletions(-) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/pvc-client.install create mode 100644 debian/pvc-client.postinst create mode 100644 debian/pvc-client.prerm create mode 100644 debian/pvc-daemon.install create mode 100644 debian/pvc-daemon.postinst create mode 100644 debian/pvc-daemon.prerm create mode 100755 debian/rules create mode 100644 debian/source/format create mode 100644 debian/source/options delete mode 100644 install.sh rename pvcd.conf => pvcd.conf.sample (81%) rename {pvc => pvcd}/NodeInstance.py (99%) rename {pvc => pvcd}/VMInstance.py (99%) create mode 100644 pvcd/__init__.py create mode 100644 pvcd/ansiiprint.py diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..fe2a3d3d --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +pvc (0.1-1) unstable; urgency=medium + + * Initial packaging release + + -- Joshua Boniface Sun, 17 Jun 2018 02:40:39 -0400 diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..7503ee77 --- /dev/null +++ b/debian/control @@ -0,0 +1,28 @@ +Source: pvc +Section: main +Priority: optional +Maintainer: Joshua Boniface +Standards-Version: 3.9.8 +Homepage: https://www.boniface.me +X-Python3-Version: >= 3.2 + +Package: pvc-daemon +Architecture: all +Depends: python3-kazoo, python3-libvirt, python3-psutil, python3-apscheduler +Suggests: pvc-client +Description: Parallel Virtual Cluster daemon (Python 3) + The Parallel Virtual Cluster provides a management solution for QEMU/KVM virtual clusters, + including full control of running VMs, definitions, and hypervisors (including fencing via + IPMI). This package provides the daemon component for a hypervisor node. + . + This package installs the PVC daemon utility + +Package: pvc-client +Architecture: all +Depends: python3-kazoo, python3-libvirt, python3-psutil, python3-click, python3-lxml +Description: Parallel Virtual Cluster client (Python 3) + The Parallel Virtual Cluster provides a management solution for QEMU/KVM virtual clusters, + including full control of running VMs, definitions, and hypervisors (including fencing via + IPMI). This package provides the client command-line interface. + . + This package installs the PVC command-line client diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000..d935aa99 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,38 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: pvc +Source: + +Files: * +Copyright: + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2018 unknown +License: GPL-2+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid picking licenses with terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. diff --git a/debian/pvc-client.install b/debian/pvc-client.install new file mode 100644 index 00000000..de9470d1 --- /dev/null +++ b/debian/pvc-client.install @@ -0,0 +1,2 @@ +pvc.py usr/share/pvc +pvc usr/share/pvc diff --git a/debian/pvc-client.postinst b/debian/pvc-client.postinst new file mode 100644 index 00000000..cda92dfc --- /dev/null +++ b/debian/pvc-client.postinst @@ -0,0 +1,4 @@ +#!/bin/sh + +# Install client binary to /usr/bin via symlink +ln -s /usr/share/pvc/pvc.py /usr/bin/pvc diff --git a/debian/pvc-client.prerm b/debian/pvc-client.prerm new file mode 100644 index 00000000..7d7fcd37 --- /dev/null +++ b/debian/pvc-client.prerm @@ -0,0 +1,4 @@ +#!/bin/sh + +# Remove client binary symlink +rm -f /usr/bin/pvc diff --git a/debian/pvc-daemon.install b/debian/pvc-daemon.install new file mode 100644 index 00000000..25d67a6e --- /dev/null +++ b/debian/pvc-daemon.install @@ -0,0 +1,4 @@ +pvcd.py usr/share/pvc +pvcd.service lib/systemd/system +pvcd.conf.sample etc/pvc +pvcd usr/share/pvc diff --git a/debian/pvc-daemon.postinst b/debian/pvc-daemon.postinst new file mode 100644 index 00000000..dfcb4131 --- /dev/null +++ b/debian/pvc-daemon.postinst @@ -0,0 +1,6 @@ +#!/bin/sh + +# Enable the servive +systemctl enable /lib/systemd/system/pvcd.service + +echo "The PVC daemon has not been started. Create a config file at /etc/pvc/pvcd.conf then start it." diff --git a/debian/pvc-daemon.prerm b/debian/pvc-daemon.prerm new file mode 100644 index 00000000..63691d01 --- /dev/null +++ b/debian/pvc-daemon.prerm @@ -0,0 +1,5 @@ +#!/bin/sh + +# Disable the servive +systemctl disable pvcd.service + diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000..da4dcf81 --- /dev/null +++ b/debian/rules @@ -0,0 +1,16 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + +%: + dh $@ + + +# If you need to rebuild the Sphinx documentation +# Add spinxdoc to the dh --with line +#override_dh_auto_build: +# dh_auto_build +# PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bhtml docs/ build/html # HTML generator +# PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bman docs/ build/man # Manpage generator + diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 00000000..163aaf8d --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/source/options b/debian/source/options new file mode 100644 index 00000000..cb61fa52 --- /dev/null +++ b/debian/source/options @@ -0,0 +1 @@ +extend-diff-ignore = "^[^/]*[.]egg-info/" diff --git a/install.sh b/install.sh deleted file mode 100644 index fffdc44b..00000000 --- a/install.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -DEPS=( python3-kazoo python3-libvirt python3-psutil python3-apscheduler ) - -# Install required packages -sudo apt install ${DEPS[@]} diff --git a/pvcd.conf b/pvcd.conf.sample similarity index 81% rename from pvcd.conf rename to pvcd.conf.sample index 39621205..565c1246 100644 --- a/pvcd.conf +++ b/pvcd.conf.sample @@ -1,4 +1,4 @@ -# pvcd cluster configuration file +# pvcd cluster configuration file example # # This configuration file lists all nodes that should be running in the cluster and provides # basic configuration information for them. @@ -17,15 +17,16 @@ # ipmi_hostname: the IPMI hostname for fencing (defaults to -lom.) # ipmi_username: username to connect to IPMI # ipmi_password: password to connect to IPMI +# +# Copy this example to /etc/pvc/pvcd.conf and edit to your needs [default] zookeeper = 127.0.0.1:2181 keepalive_interval = 5 +#ipmi_username = admin +#ipmi_password = admin + +[myhost] ipmi_username = admin ipmi_password = admin - -[test1.i.bonilan.net] -ipmi_hostname = test1-lom.m.bonilan.net - -[test2.i.bonilan.net] -ipmi_hostname = test2-lom.m.bonilan.net +ipmi_hostname = myhost-lom diff --git a/pvcd.py b/pvcd.py index cd91da5b..f1eef547 100755 --- a/pvcd.py +++ b/pvcd.py @@ -33,9 +33,9 @@ import time import configparser import apscheduler.schedulers.background -import pvc.ansiiprint as ansiiprint -import pvc.VMInstance as VMInstance -import pvc.NodeInstance as NodeInstance +import pvcd.ansiiprint as ansiiprint +import pvcd.VMInstance as VMInstance +import pvcd.NodeInstance as NodeInstance print(ansiiprint.bold() + "pvcd - Parallel Virtual Cluster management daemon" + ansiiprint.end()) diff --git a/pvcd.service b/pvcd.service index 1ba0a262..ffe834f3 100644 --- a/pvcd.service +++ b/pvcd.service @@ -5,11 +5,10 @@ After = network-online.target libvirtd.service zookeeper.service [Service] Type = simple -WorkingDirectory = /var/home/joshua/pvc +WorkingDirectory = /usr/share/pvc Environment = PYTHONUNBUFFERED=true -Environment = PVCD_CONFIG_FILE=/etc/pvcd.conf -#ExecStartPre = /bin/bash -c "GIT_SSH_COMMAND='/usr/bin/ssh -i /srv/git-deploy.key' /usr/bin/git pull" -ExecStart = /var/home/joshua/pvc/pvcd.py +Environment = PVCD_CONFIG_FILE=/etc/pvc/pvcd.conf +ExecStart = /usr/share/pvc/pvcd.py Restart = on-failure [Install] diff --git a/pvc/NodeInstance.py b/pvcd/NodeInstance.py similarity index 99% rename from pvc/NodeInstance.py rename to pvcd/NodeInstance.py index 4aac371c..0bf1b9c6 100644 --- a/pvc/NodeInstance.py +++ b/pvcd/NodeInstance.py @@ -21,7 +21,7 @@ ############################################################################### import os, sys, psutil, socket, time, libvirt, kazoo.client, threading, subprocess -import pvc.ansiiprint as ansiiprint +import pvcd.ansiiprint as ansiiprint class NodeInstance(): # Initialization function diff --git a/pvc/VMInstance.py b/pvcd/VMInstance.py similarity index 99% rename from pvc/VMInstance.py rename to pvcd/VMInstance.py index 2c085b1b..206c5259 100644 --- a/pvc/VMInstance.py +++ b/pvcd/VMInstance.py @@ -21,7 +21,7 @@ ############################################################################### import os, sys, uuid, socket, time, threading, libvirt, kazoo.client -import pvc.ansiiprint as ansiiprint +import pvcd.ansiiprint as ansiiprint class VMInstance: # Initialization function diff --git a/pvcd/__init__.py b/pvcd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pvcd/ansiiprint.py b/pvcd/ansiiprint.py new file mode 100644 index 00000000..69cc1b0e --- /dev/null +++ b/pvcd/ansiiprint.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +# ansiprint.py - Printing function for formatted messages +# Part of the Parallel Virtual Cluster (PVC) system +# +# Copyright (C) 2018 Joshua M. Boniface +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################### + +import datetime + +# ANSII colours for output +def red(): + return '\033[91m' +def blue(): + return '\033[94m' +def green(): + return '\033[92m' +def yellow(): + return '\033[93m' +def purple(): + return '\033[95m' +def bold(): + return '\033[1m' +def end(): + return '\033[0m' + +# Print function +def echo(message, prefix, state): + # Get the date + date = '{} - '.format(datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S.%f')) + endc = end() + + # Continuation + if state == 'c': + date = '' + colour = '' + prompt = ' ' + # OK + elif state == 'o': + colour = green() + prompt = '>>> ' + # Error + elif state == 'e': + colour = red() + prompt = '>>> ' + # Warning + elif state == 'w': + colour = yellow() + prompt = '>>> ' + # Tick + elif state == 't': + colour = purple() + prompt = '>>> ' + # Information + elif state == 'i': + colour = blue() + prompt = '>>> ' + else: + colour = bold() + prompt = '>>> ' + + # Append space to prefix + if prefix != '': + prefix = prefix + ' ' + + print(colour + prompt + endc + date + prefix + message)