Repository URL to install this package:
Version:
5.0.6.dev10 ▾
|
from setuptools import setup, find_packages
from setuptools.command.install import install
import os
import sys
import shutil
import pwd
import grp
import configparser
import subprocess
from configobj import ConfigObj
from distutils.sysconfig import EXEC_PREFIX, get_python_lib
class InstallWrapper(install):
"""Provides a install wrapper for WSGI applications
to copy additional files for Web servers to use e.g
static files. These were packaed using definitions
in MANIFEST.in and don't really belong in the
Python package."""
_TARGET_SERVICE_PATH = "/etc/systemd/system/"
_COPY_FOLDERS = ['wsgi', 'static']
_SERVICE_FILE_NAME = "tvault-config.service"
_BANNER_YAML_FILE_NAME = "banner.yaml"
_SERVICE_FILE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'tvault_configurator', 'services', _SERVICE_FILE_NAME))
_GRAPHANA_CHANGE_PASS_SCRIPT = os.path.abspath(os.path.join(os.path.dirname(__file__), 'tvault_configurator', 'etc', 'change_grafana_password.sh'))
_BANNER_YAML_FILE_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'tvault_configurator', 'etc', _BANNER_YAML_FILE_NAME))
_TARGET_BANNER_PATH = "/etc/tvault-config/"
def run(self):
# Run this first so the install stops in case
# these fail otherwise the Python package is
# successfully installed
self._copy_banner_files()
self._copy_service_files()
# Run the standard PyPi copy
install.run(self)
def _copy_banner_files(self):
yaml_target_path = os.path.join(self._TARGET_BANNER_PATH, self._BANNER_YAML_FILE_NAME)
os.makedirs("/etc/tvault-config", exist_ok=True)
# If this exists at the target then
# remove it to ensure the target is clean
if os.path.isfile(yaml_target_path):
os.remove(yaml_target_path)
shutil.copy(self._BANNER_YAML_FILE_PATH, yaml_target_path)
def _copy_service_files(self):
# Check to see we are running as a non-prvilleged user
#if os.geteuid() == 0:
# raise Exception(
# "Install should be as a non-privileged user")
# Check to see that the required folders exists
# Do this first so we don't fail half way
#for folder in self._COPY_FOLDERS:
if not os.access(self._SERVICE_FILE_PATH, os.R_OK):
raise IOError("%s not readable from achive" % self._SERVICE_FILE_PATH)
# Check to see we can write to the target
if not os.access(self._TARGET_SERVICE_PATH, os.W_OK):
raise IOError("%s not writeable by user" % self._TARGET_SERVICE_PATH)
# Clean target and copy files
#for folder in self._COPY_FOLDERS:
target_path = os.path.join(self._TARGET_SERVICE_PATH, self._SERVICE_FILE_NAME)
# If this exists at the target then
# remove it to ensure the target is clean
if os.path.isfile(target_path):
os.remove(target_path)
# Copy the files from the archive
shutil.copy(self._SERVICE_FILE_PATH, self._TARGET_SERVICE_PATH)
uid = pwd.getpwnam('root').pw_uid
gid = grp.getgrnam('root').gr_gid
os.chown(target_path, uid, gid)
os.chmod(target_path, 0o644)
shutil.copy(self._GRAPHANA_CHANGE_PASS_SCRIPT, '/etc/tvault/')
ansible_config = ConfigObj('/etc/ansible/ansible.cfg')
# finding python's library path
python_lib_path = get_python_lib()
ansible_config['defaults']['library'] = os.path.join(python_lib_path, 'tvault_configurator', 'openstack-ansible-modules')
ansible_config.write()
del ansible_config
tvault_config_bin_path = os.path.join(EXEC_PREFIX, 'bin', 'tvault_config_bottle')
python_bin_path = os.path.join(EXEC_PREFIX, 'bin', 'python3')
# adding binary execution path in tvault-config.service file
tvault_service_config = ConfigObj(target_path)
tvault_service_config['Service']['ExecStart'] = '{} {}'.format(python_bin_path, tvault_config_bin_path)
tvault_service_config.write()
del tvault_service_config
subprocess.call([shutil.which('systemctl'), 'daemon-reload'])
subprocess.call([shutil.which('systemctl'), 'enable', 'tvault-config.service'])
subprocess.call([shutil.which('systemctl'), 'stop' 'tvault-config.service'])
subprocess.call([shutil.which('systemctl'), 'start', 'tvault-config.service'])
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name="tvault_configurator",
version=os.getenv('TVAULT_VERSION', '4.0.19'),
author='TrilioData',
author_email='support@trilio.io',
description="Configurator service",
long_description=long_description,
url='https://www.trilio.io',
packages=find_packages(),
include_package_data=True,
scripts=['bin/tvault_config_bottle'],
cmdclass={'install': InstallWrapper},
install_requires=[
'setuptools >= 40.0.4',
'docutils>=0.3',
'configobj>=5.0.6',
'requests>=2.18.4',
'ansible>=2.9.2',
'Beaker>=1.11.0',
'bottle==0.12.16',
'jinja2>=2.10.3',
#'cork>=0.2',
'bottle-cork>=0.12.0',
'keystoneauth1>=3.4.0',
'mock>=1.3.0',
'nose>=1.3.7',
'pyOpenSSL>=17.5.0',
'python_keystoneclient>=3.15.0',
'python_swiftclient>=3.8.1',
'pytz>=2019.2',
'SQLAlchemy>=1.3.8',
'tzlocal>=2.0.0',
'openstacksdk',
'contegoclient>=4.0.19',
'workloadmgrclient>=4.0.19',
'workloadmgr>=4.0.19'
],
classifiers=[
'Environment :: OpenStack',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
],
python_requires='>=3.6',
)