Skip to content

Commit

Permalink
VERSION file is the only source of truth for ZTPS version number
Browse files Browse the repository at this point in the history
  • Loading branch information
advornic committed Jan 8, 2015
1 parent 7ca8b49 commit 91f2458
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 48 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.3.0
62 changes: 35 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,65 @@
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from glob import glob
import os
import shutil

from glob import glob
from ztpserver import config

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

from ztpserver import __version__, __author__
packages = ['ztpserver']

PACKAGES = ['ztpserver']
conf_path = config.CONF_PATH
install_path = config.INSTALL_PATH

INSTALL_ROOT = ''
if os.environ.get('READTHEDOCS'):
print "Customizing install for ReadTheDocs.org build servers..."
INSTALL_ROOT = "."
print 'Customizing install for ReadTheDocs.org build servers...'
conf_path = '.' + conf_path
install_path = '.' + install_path
from subprocess import call
call(['docs/setup_rtd_files.sh'])
PACKAGES.append('client')
PACKAGES.append('actions')
packages.append('client')
packages.append('actions')

CONF_PATH = INSTALL_ROOT + '/etc/ztpserver'
INSTALL_PATH = INSTALL_ROOT + '/usr/share/ztpserver'
INSTALL_REQUIREMENTS = open('requirements.txt').read().split('\n')
install_requirements = open('requirements.txt').read().split('\n')
version = open('VERSION').read().split()[0].strip()

setup(
name='ztpserver',
version=__version__,
version=version,
description = 'ZTP Server for EOS',
author=__author__,
author='Arista Networks',
author_email='eosplus-dev@arista.com',
url='https://github.com/arista-eosplus/ztpserver',
download_url='https://github.com/arista-eosplus/ztpserver/tarball/v%s' % \
__version__,
version,
license='BSD-3',
install_requires=INSTALL_REQUIREMENTS,
packages=PACKAGES,
install_requires=install_requirements,
packages=packages,
scripts=glob('bin/*'),
data_files=[
('%s/nodes' % INSTALL_PATH, []),
('%s/definitions' % INSTALL_PATH, []),
('%s/files' % INSTALL_PATH, []),
('%s/resources' % INSTALL_PATH, []),
(CONF_PATH, glob('conf/ztpserver.conf')),
(CONF_PATH, glob('conf/ztpserver.wsgi')),
('%s/bootstrap' % INSTALL_PATH, glob('client/bootstrap')),
('%s/bootstrap' % INSTALL_PATH, glob('conf/bootstrap.conf')),
('%s/actions' % INSTALL_PATH, glob('actions/*')),
('%s' % INSTALL_PATH, glob('conf/neighbordb')),
('%s/nodes' % install_path, []),
('%s/definitions' % install_path, []),
('%s/files' % install_path, []),
('%s/resources' % install_path, []),
(conf_path, glob('conf/ztpserver.conf')),
(conf_path, glob('conf/ztpserver.wsgi')),
(conf_path, ['VERSION']),
('%s/bootstrap' % install_path, glob('client/bootstrap')),
('%s/bootstrap' % install_path, glob('conf/bootstrap.conf')),
('%s/actions' % install_path, glob('actions/*')),
('%s' % install_path, glob('conf/neighbordb')),

# 4.12.x support
('%s/files/lib' % INSTALL_PATH, glob('client/lib/requests-2.3.0.tar.gz')),
('%s/files/lib' % install_path, glob('client/lib/requests-2.3.0.tar.gz')),
]
)

# Hide VERSION file
shutil.rmtree(config.VERSION_FILE_PATH, ignore_errors=True)
shutil.move('%s/VERSION' % conf_path, config.VERSION_FILE_PATH)
3 changes: 1 addition & 2 deletions ztpserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
__version__ = '1.2.0'
__author__ = 'Arista Networks'
pass
38 changes: 20 additions & 18 deletions ztpserver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@

from wsgiref.simple_server import make_server

import ztpserver.config
import ztpserver.controller
import ztpserver.topology
from ztpserver import config, controller

from ztpserver.serializers import load
from ztpserver.validators import NeighbordbValidator
from ztpserver.constants import CONTENT_TYPE_YAML
from ztpserver.topology import default_filename

from ztpserver import __version__ as VERSION

DEFAULT_CONF = '/etc/ztpserver/ztpserver.conf'
DEFAULT_CONF = config.GLOBAL_CONF_FILE_PATH

log = logging.getLogger("ztpserver")
log.setLevel(logging.DEBUG)
Expand All @@ -60,7 +56,7 @@
def enable_handler_console(level=None):
""" Enables logging to stdout """

logging_fmt = ztpserver.config.runtime.default.console_logging_format
logging_fmt = config.runtime.default.console_logging_format
formatter = logging.Formatter(logging_fmt)

ch = logging.StreamHandler()
Expand All @@ -87,16 +83,16 @@ def python_supported():
def start_logging(debug):
""" reads the runtime config and starts logging if enabled """

if ztpserver.config.runtime.default.logging:
if ztpserver.config.runtime.default.console_logging:
if config.runtime.default.logging:
if config.runtime.default.console_logging:
enable_handler_console('DEBUG' if debug else 'INFO')

def load_config(conf=None):
conf = conf or DEFAULT_CONF
conf = os.environ.get('ZTPS_CONFIG', conf)

if os.path.exists(conf):
ztpserver.config.runtime.read(conf)
config.runtime.read(conf)

def start_wsgiapp(conf=None, debug=False):
""" Provides the entry point into the application for wsgi compliant
Expand All @@ -113,14 +109,14 @@ def start_wsgiapp(conf=None, debug=False):
start_logging(debug)

log.info('Logging started for ztpserver')
log.info('Using repository %s', ztpserver.config.runtime.default.data_root)
log.info('Using repository %s', config.runtime.default.data_root)

if not python_supported():
raise SystemExit('ERROR: ZTPServer requires Python 2.7')

return ztpserver.controller.Router()
return controller.Router()

def run_server(conf, debug):
def run_server(conf, debug, version):
""" The :py:func:`run_server` is called by the main command line routine to
run the server as standalone. This function accepts a single argument
that points towards the configuration file describing this server
Expand All @@ -132,12 +128,12 @@ def run_server(conf, debug):

app = start_wsgiapp(conf, debug)

host = ztpserver.config.runtime.server.interface
port = ztpserver.config.runtime.server.port
host = config.runtime.server.interface
port = config.runtime.server.port

httpd = make_server(host, port, app)

print "Starting ZTPServer v%s on http://%s:%s" % (VERSION, host, port)
print "Starting ZTPServer v%s on http://%s:%s" % (version, host, port)

try:
httpd.serve_forever()
Expand Down Expand Up @@ -200,13 +196,19 @@ def main():

args = parser.parse_args()

version = 'N/A'
try:
version = open(config.VERSION_FILE_PATH).read().split()[0].strip()
except IOError:
pass

if args.version:
print 'ztps version %s' % VERSION
print 'ztps version %s' % version
sys.exit()

if args.validate is not None:
load_config(args.conf)
start_logging(args.debug)
sys.exit(run_validator(args.validate))

return run_server(args.conf, args.debug)
return run_server(args.conf, args.debug, version)
10 changes: 10 additions & 0 deletions ztpserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@

import ztpserver.types

CONF_PATH = '/etc/ztpserver'

VERSION_FILE = '.VERSION'
VERSION_FILE_PATH = '%s/%s' % (CONF_PATH, VERSION_FILE)

GLOBAL_CONF_FILE = 'ztpserver.conf'
GLOBAL_CONF_FILE_PATH = '%s/%s' % (CONF_PATH, GLOBAL_CONF_FILE)

INSTALL_PATH = '/usr/share/ztpserver'

log = logging.getLogger(__name__)

class Attr(object):
Expand Down

0 comments on commit 91f2458

Please sign in to comment.